Skip to content

Commit

Permalink
Merge pull request civicrm#11269 from varshith/CRM-21041_respect_defa…
Browse files Browse the repository at this point in the history
…ult_communication_style_on_api_contact_create

CRM-21041: Respect default 'Communication Style' when creating a …
  • Loading branch information
colemanw authored and sluc23 committed Jan 10, 2018
2 parents f967d9e + 84542bf commit 9dc673d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CRM/Contact/BAO/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,12 @@ public static function &create(&$params, $fixAddress = TRUE, $invokeHooks = TRUE
}
}
}

// CRM-21041: set default 'Communication Style' if unset when creating a contact.
if (empty($params['communication_style_id'])) {
$defaultCommunicationStyleId = CRM_Core_OptionGroup::values('communication_style', TRUE, NULL, NULL, 'AND is_default = 1');
$params['communication_style_id'] = array_pop($defaultCommunicationStyleId);
}
}

$transaction = new CRM_Core_Transaction();
Expand Down
34 changes: 34 additions & 0 deletions tests/phpunit/api/v3/ContactTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3548,4 +3548,38 @@ protected function putGroupContactCacheInClearableState($groupID, $contact) {
Civi::$statics['CRM_Contact_BAO_GroupContactCache']['is_refresh_init'] = FALSE;
}

/**
* CRM-21041 Test if 'communication style' is set to site default if not passed.
*/
public function testCreateCommunicationStyleUnset() {
$this->callAPISuccess('Contact', 'create', array(
'first_name' => 'John',
'last_name' => 'Doe',
'contact_type' => 'Individual')
);
$result = $this->callAPISuccessGetSingle('Contact', array('last_name' => 'Doe'));
$this->assertEquals(1, $result['communication_style_id']);
}

/**
* CRM-21041 Test if 'communication style' is set if value is passed.
*/
public function testCreateCommunicationStylePassed() {
$this->callAPISuccess('Contact', 'create', array(
'first_name' => 'John',
'last_name' => 'Doe',
'contact_type' => 'Individual',
'communication_style_id' => 'Familiar',
));
$result = $this->callAPISuccessGetSingle('Contact', array('last_name' => 'Doe'));
$params = array(
'option_group_id' => 'communication_style',
'label' => 'Familiar',
'return' => 'value',
);
$optionResult = civicrm_api3('OptionValue', 'get', $params);
$communicationStyle = reset($optionResult['values']);
$this->assertEquals($communicationStyle['value'], $result['communication_style_id']);
}

}

0 comments on commit 9dc673d

Please sign in to comment.