'civicrm_phone',
'civicrm_address',
'civicrm_acl_contact_cache',
+ 'civicrm_activity_contact',
+ 'civicrm_activity',
);
$this->quickCleanup($tablesToTruncate, TRUE);
);
}
+ /**
+ * Test for international string acceptance (CRM-10210).
+ *
+ * @dataProvider getInternationalStrings
+ *
+ * @param string $string
+ * String to be tested.
+ *
+ * @throws \Exception
+ */
+ public function testInternationalStrings($string) {
+ $this->callAPISuccess('Contact', 'create', array_merge(
+ $this->_params,
+ array('first_name' => $string)
+ ));
+ $result = $this->callAPISuccessGetSingle('Contact', array('first_name' => $string));
+ $this->assertEquals($string, $result['first_name']);
+
+ $organizationParams = array(
+ 'organization_name' => $string,
+ 'contact_type' => 'Organization',
+ );
+
+ $this->callAPISuccess('Contact', 'create', $organizationParams);
+ $result = $this->callAPISuccessGetSingle('Contact', $organizationParams);
+ $this->assertEquals($string, $result['organization_name']);
+ }
+
+ /**
+ * Get international string data for testing against api calls.
+ */
+ public function getInternationalStrings() {
+ $invocations = array();
+ $invocations[] = array('Scarabée');
+ $invocations[] = array('Iñtërnâtiônàlizætiøn');
+ $invocations[] = array('これは日本語のテキストです。読めますか');
+ $invocations[] = array('देखें हिन्दी कैसी नजर आती है। अरे वाह ये तो नजर आती है।');
+ return $invocations;
+ }
+
/**
* Test civicrm_contact_create.
*
}
/**
- * Check that address name is returned if required.
+ * Check that address name, ID is returned if required.
*/
- public function testGetReturnAddressName() {
+ public function testGetReturnAddress() {
$contactID = $this->individualCreate();
- $this->callAPISuccess('address', 'create', array(
+ $result = $this->callAPISuccess('address', 'create', array(
'contact_id' => $contactID,
'address_name' => 'My house',
'location_type_id' => 'Home',
'street_address' => '1 my road',
));
+ $addressID = $result['id'];
+
$result = $this->callAPISuccessGetSingle('contact', array(
- 'return' => 'address_name, street_address',
+ 'return' => 'address_name, street_address, address_id',
'id' => $contactID,
));
+ $this->assertEquals($addressID, $result['address_id']);
$this->assertEquals('1 my road', $result['street_address']);
$this->assertEquals('My house', $result['address_name']);
/**
* Test merging 2 contacts.
+ *
+ * Someone kindly bequethed us the legacy of mixed up use of main_id & other_id
+ * in the params for contact.merge api.
+ *
+ * This test protects that legacy.
*/
- public function testMerge() {
+ public function testMergeBizzareOldParams() {
+ $this->createLoggedInUser();
$otherContact = $this->callAPISuccess('contact', 'create', $this->_params);
$mainContact = $this->callAPISuccess('contact', 'create', $this->_params);
- $this->callAPISuccess('contact', 'merge', array('main_id' => $mainContact['id'], 'other_id' => $otherContact['id']));
+ $this->callAPISuccess('contact', 'merge', array(
+ 'main_id' => $mainContact['id'],
+ 'other_id' => $otherContact['id'],
+ ));
$contacts = $this->callAPISuccess('contact', 'get', $this->_params);
$this->assertEquals($otherContact['id'], $contacts['id']);
+ }
+
+ /**
+ * Test merging 2 contacts.
+ */
+ public function testMerge() {
+ $this->createLoggedInUser();
+ $otherContact = $this->callAPISuccess('contact', 'create', $this->_params);
+ $retainedContact = $this->callAPISuccess('contact', 'create', $this->_params);
+ $this->callAPISuccess('contact', 'merge', array(
+ 'to_keep_id' => $retainedContact['id'],
+ 'to_remove_id' => $otherContact['id'],
+ 'auto_flip' => FALSE,
+ ));
+
+ $contacts = $this->callAPISuccess('contact', 'get', $this->_params);
+ $this->assertEquals($retainedContact['id'], $contacts['id']);
+ $activity = $this->callAPISuccess('Activity', 'getsingle', array(
+ 'target_contact_id' => $retainedContact['id'],
+ 'activity_type_id' => 'Contact Merged',
+ ));
+ $this->assertEquals(date('Y-m-d'), date('Y-m-d', strtotime($activity['activity_date_time'])));
+ $activity2 = $this->callAPISuccess('Activity', 'getsingle', array(
+ 'target_contact_id' => $otherContact['id'],
+ 'activity_type_id' => 'Contact Deleted by Merge',
+ ));
+ $this->assertEquals($activity['id'], $activity2['parent_id']);
+ $this->assertEquals('Normal', civicrm_api3('option_value', 'getvalue', array(
+ 'value' => $activity['priority_id'],
+ 'return' => 'label',
+ 'option_group_id' => 'priority',
+ )));
}
+ /**
+ * Test merging 2 contacts with delete to trash off.
+ *
+ * We are checking that there is no error due to attempting to add an activity for the
+ * deleted contact.
+ *
+ * CRM-18307
+ */
+ public function testMergeNoTrash() {
+ $this->createLoggedInUser();
+ $this->callAPISuccess('Setting', 'create', array('contact_undelete' => FALSE));
+ $otherContact = $this->callAPISuccess('contact', 'create', $this->_params);
+ $retainedContact = $this->callAPISuccess('contact', 'create', $this->_params);
+ $this->callAPISuccess('contact', 'merge', array(
+ 'to_keep_id' => $retainedContact['id'],
+ 'to_remove_id' => $otherContact['id'],
+ 'auto_flip' => FALSE,
+ ));
+ $this->callAPISuccess('Setting', 'create', array('contact_undelete' => TRUE));
+ }
+
}