From: eileen Date: Thu, 26 May 2016 10:43:23 +0000 (+1200) Subject: CRM-18685, CRM-18674 tests X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=6c0c7017370d1ce0f7b7861b1a05cff17dc72b99;p=civicrm-core.git CRM-18685, CRM-18674 tests Change-Id: I672399d3c82a885d04eb663e3f3287bb3b4cdfa6 --- diff --git a/tests/phpunit/api/v3/JobTestCustomData.php b/tests/phpunit/api/v3/JobTestCustomData.php new file mode 100644 index 0000000000..714abbb41c --- /dev/null +++ b/tests/phpunit/api/v3/JobTestCustomData.php @@ -0,0 +1,359 @@ +_params = array( + 'sequential' => 1, + 'name' => 'API_Test_Job', + 'description' => 'A long description written by hand in cursive', + 'run_frequency' => 'Daily', + 'api_entity' => 'ApiTestEntity', + 'api_action' => 'apitestaction', + 'parameters' => 'Semi-formal explanation of runtime job parameters', + 'is_active' => 1, + ); + } + + /** + * Cleanup after tests. + */ + public function tearDown() { + $this->quickCleanup(array('civicrm_contact'), TRUE); + parent::tearDown(); + } + + /** + * Test the batch merge does not bork on custom date fields. + * + * Test CRM-18674 date custom field handling. + */ + public function testBatchMergeDateCustomFieldHandling() { + $customGroup = $this->customGroupCreate(); + $this->customGroupID = $customGroup['id']; + $customField = $this->customFieldCreate(array( + 'custom_group_id' => $this->customGroupID, + 'data_type' => 'Date', + 'html_type' => 'Select Date', + 'default_value' => '', + )); + $this->customFieldID = $customField['id']; + $customFieldLabel = 'custom_' . $this->customFieldID; + $contactID = $this->individualCreate(); + $this->individualCreate(array($customFieldLabel => '2012-12-03')); + $result = $this->callAPISuccess('Job', 'process_batch_merge', array()); + $this->assertEquals(1, count($result['values']['merged'])); + $contact = $this->callAPISuccess('Contact', 'getsingle', array('id' => $contactID, 'return' => $customFieldLabel)); + $this->assertEquals('2012-12-03 00:00:00', $contact[$customFieldLabel]); + } + + /** + * Test the batch merge does not bork on custom date fields. + * + * Test CRM-18674 date custom field handling. + */ + public function testBatchMergeDateCustomFieldHandlingIsView() { + $customGroup = $this->customGroupCreate(); + $this->customGroupID = $customGroup['id']; + $customField = $this->customFieldCreate(array( + 'custom_group_id' => $this->customGroupID, + 'data_type' => 'Date', + 'html_type' => 'Select Date', + 'default_value' => '', + 'is_view' => 1, + )); + $this->customFieldID = $customField['id']; + $customFieldLabel = 'custom_' . $this->customFieldID; + $contactID = $this->individualCreate(); + $this->individualCreate(array($customFieldLabel => '2012-11-03')); + $result = $this->callAPISuccess('Job', 'process_batch_merge', array()); + $this->assertEquals(1, count($result['values']['merged'])); + $contact = $this->callAPISuccess('Contact', 'getsingle', array('id' => $contactID, 'return' => $customFieldLabel)); + $this->assertEquals('2012-11-03 00:00:00', $contact[$customFieldLabel]); + } + + /** + * Check we get a conflict on the custom field. + */ + public function testBatchMergeDateCustomFieldConflict() { + $customGroup = $this->customGroupCreate(); + $this->customGroupID = $customGroup['id']; + $customField = $this->customFieldCreate(array( + 'custom_group_id' => $this->customGroupID, + 'data_type' => 'Date', + 'html_type' => 'Select Date', + 'default_value' => '', + )); + $this->customFieldID = $customField['id']; + $customFieldLabel = 'custom_' . $this->customFieldID; + $contactID = $this->individualCreate(array($customFieldLabel => '2012-11-03')); + $this->individualCreate(array($customFieldLabel => '2013-11-03')); + $result = $this->callAPISuccess('Job', 'process_batch_merge', array()); + $this->assertEquals(0, count($result['values']['merged'])); + $this->assertEquals(1, count($result['values']['skipped'])); + $contact = $this->callAPISuccess('Contact', 'getsingle', array('id' => $contactID, 'return' => $customFieldLabel)); + $this->assertEquals('2012-11-03 00:00:00', $contact[$customFieldLabel]); + } + + /** + * Check we get a conflict on the custom field. + */ + public function testBatchMergeDateCustomFieldNoConflict() { + $customGroup = $this->customGroupCreate(); + $this->customGroupID = $customGroup['id']; + $customField = $this->customFieldCreate(array( + 'custom_group_id' => $this->customGroupID, + 'data_type' => 'Date', + 'html_type' => 'Select Date', + 'default_value' => '', + )); + $this->customFieldID = $customField['id']; + $customFieldLabel = 'custom_' . $this->customFieldID; + $contactID = $this->individualCreate(array($customFieldLabel => '2012-11-03')); + $this->individualCreate(array($customFieldLabel => '2012-11-03')); + $result = $this->callAPISuccess('Job', 'process_batch_merge', array()); + $this->assertEquals(1, count($result['values']['merged'])); + $this->assertEquals(0, count($result['values']['skipped'])); + $contact = $this->callAPISuccess('Contact', 'getsingle', array('id' => $contactID, 'return' => $customFieldLabel)); + $this->assertEquals('2012-11-03 00:00:00', $contact[$customFieldLabel]); + } + + /** + * Using the api with check perms set to off, make sure custom data is merged.git + * + * Test CRM-18674 date custom field handling. + */ + public function testBatchMergeDateCustomFieldConflictAndNoCheckPerms() { + CRM_Core_Config::singleton()->userPermissionClass->permissions = array('access CiviCRM', 'edit my contact'); + $customGroup = $this->customGroupCreate(); + $this->customGroupID = $customGroup['id']; + $customField = $this->customFieldCreate(array( + 'custom_group_id' => $this->customGroupID, + 'data_type' => 'Date', + 'html_type' => 'Select Date', + 'default_value' => '', + )); + $this->customFieldID = $customField['id']; + $customFieldLabel = 'custom_' . $this->customFieldID; + $contactID = $this->individualCreate(array($customFieldLabel => '2012-11-03')); + $this->individualCreate(array($customFieldLabel => '2013-11-03')); + $result = $this->callAPISuccess('Job', 'process_batch_merge', array('check_permissions' => 0)); + $this->assertEquals(0, count($result['values']['merged'])); + $this->assertEquals(1, count($result['values']['skipped'])); + $contact = $this->callAPISuccess('Contact', 'getsingle', array('id' => $contactID, 'return' => $customFieldLabel)); + $this->assertEquals('2012-11-03 00:00:00', $contact[$customFieldLabel]); + } + + /** + * Get data for batch merge. + */ + public function getMergeSets() { + $data = array( + array( + array( + 'mode' => 'safe', + 'contacts' => array( + array( + 'first_name' => 'Michael', + 'last_name' => 'Jackson', + 'email' => 'michael@neverland.com', + 'contact_type' => 'Individual', + 'contact_sub_type' => 'Student', + 'api.Address.create' => array( + 'street_address' => 'big house', + 'location_type_id' => 'Home', + ), + ), + array( + 'first_name' => 'Michael', + 'last_name' => 'Jackson', + 'email' => 'michael@neverland.com', + 'contact_type' => 'Individual', + 'contact_sub_type' => 'Student', + ), + ), + 'skipped' => 0, + 'merged' => 1, + 'expected' => array( + array( + 'first_name' => 'Michael', + 'last_name' => 'Jackson', + 'email' => 'michael@neverland.com', + 'contact_type' => 'Individual', + ), + ), + ), + ), + array( + array( + 'mode' => 'safe', + 'contacts' => array( + array( + 'first_name' => 'Michael', + 'last_name' => 'Jackson', + 'email' => 'michael@neverland.com', + 'contact_type' => 'Individual', + 'contact_sub_type' => 'Student', + 'api.Address.create' => array( + 'street_address' => 'big house', + 'location_type_id' => 'Home', + ), + ), + array( + 'first_name' => 'Michael', + 'last_name' => 'Jackson', + 'email' => 'michael@neverland.com', + 'contact_type' => 'Individual', + 'contact_sub_type' => 'Student', + 'api.Address.create' => array( + 'street_address' => 'bigger house', + 'location_type_id' => 'Home', + ), + ), + ), + 'skipped' => 1, + 'merged' => 0, + 'expected' => array( + array( + 'first_name' => 'Michael', + 'last_name' => 'Jackson', + 'email' => 'michael@neverland.com', + 'contact_type' => 'Individual', + 'street_address' => 'big house', + ), + array( + 'first_name' => 'Michael', + 'last_name' => 'Jackson', + 'email' => 'michael@neverland.com', + 'contact_type' => 'Individual', + 'street_address' => 'bigger house', + ), + ), + ), + ), + array( + array( + 'mode' => 'aggressive', + 'contacts' => array( + array( + 'first_name' => 'Michael', + 'last_name' => 'Jackson', + 'email' => 'michael@neverland.com', + 'contact_type' => 'Individual', + 'contact_sub_type' => 'Student', + 'api.Address.create' => array( + 'street_address' => 'big house', + 'location_type_id' => 'Home', + ), + ), + array( + 'first_name' => 'Michael', + 'last_name' => 'Jackson', + 'email' => 'michael@neverland.com', + 'contact_type' => 'Individual', + 'contact_sub_type' => 'Student', + 'api.Address.create' => array( + 'street_address' => 'bigger house', + 'location_type_id' => 'Home', + ), + ), + ), + 'skipped' => 0, + 'merged' => 1, + 'expected' => array( + array( + 'first_name' => 'Michael', + 'last_name' => 'Jackson', + 'email' => 'michael@neverland.com', + 'contact_type' => 'Individual', + 'street_address' => 'big house', + ), + ), + ), + ), + ); + return $data; + } + + /** + * @param $op + * @param string $objectName + * @param int $id + * @param array $params + */ + public function hookPreRelationship($op, $objectName, $id, &$params) { + if ($op == 'delete') { + return; + } + if ($params['is_active']) { + $params['description'] = 'Hooked'; + } + else { + $params['description'] = 'Go Go you good thing'; + } + } + +}