* @group headless
*/
class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase {
- protected $_tablesToTruncate = ['civicrm_address', 'civicrm_phone', 'civicrm_email'];
+ use CRMTraits_Custom_CustomDataTrait;
+
+ /**
+ * Main entity for the class.
+ *
+ * @var string
+ */
+ protected $entity = 'Contact';
/**
* Setup function.
parent::setUp();
}
+ /**
+ * Tear down after test.
+ *
+ * @throws \CRM_Core_Exception
+ */
+ public function tearDown() {
+ $this->quickCleanup(['civicrm_address', 'civicrm_phone', 'civicrm_email'], TRUE);
+ parent::tearDown();
+ }
+
/**
* Test that import parser will add contact with employee of relationship.
*
$this->callAPISuccessGetSingle('Contact', $contactValues);
}
+ /**
+ * Test that labels work for importing custom data.
+ *
+ * @throws \CRM_Core_Exception
+ */
+ public function testCustomDataLabel() {
+ $this->createCustomGroupWithFieldOfType([], 'select');
+ $contactValues = [
+ 'first_name' => 'Bill',
+ 'last_name' => 'Gates',
+ 'email' => 'bill.gates@microsoft.com',
+ 'nick_name' => 'Billy-boy',
+ $this->getCustomFieldName('select') => 'Yellow',
+ ];
+ $this->runImport($contactValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID, [NULL, NULL, 'Primary', NULL, NULL]);
+ $contact = $this->callAPISuccessGetSingle('Contact', array_merge($contactValues, ['return' => $this->getCustomFieldName('select')]));
+ $this->assertEquals('Y', $contact[$this->getCustomFieldName('select')]);
+ }
+
+ /**
+ * Test that names work for importing custom data.
+ *
+ * @throws \CRM_Core_Exception
+ */
+ public function testCustomDataName() {
+ $this->createCustomGroupWithFieldOfType([], 'select');
+ $contactValues = [
+ 'first_name' => 'Bill',
+ 'last_name' => 'Gates',
+ 'email' => 'bill.gates@microsoft.com',
+ 'nick_name' => 'Billy-boy',
+ $this->getCustomFieldName('select') => 'Y',
+ ];
+ $this->runImport($contactValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID, [NULL, NULL, 'Primary', NULL, NULL]);
+ $contact = $this->callAPISuccessGetSingle('Contact', array_merge($contactValues, ['return' => $this->getCustomFieldName('select')]));
+ $this->assertEquals('Y', $contact[$this->getCustomFieldName('select')]);
+ }
+
/**
* Test that the import parser adds the address to the primary location.
*
*/
public function testImportFill() {
// Create a custom field group for testing.
- $custom_group_name = 'importFillGroup';
- $results = $this->callAPISuccess('customGroup', 'get', ['title' => $custom_group_name]);
- if ($results['count'] == 0) {
- $api_params = [
- 'title' => $custom_group_name,
- 'extends' => 'Individual',
- 'is_active' => TRUE,
- ];
- $customGroup = $this->callAPISuccess('customGroup', 'create', $api_params);
- }
+ $this->createCustomGroup([
+ 'title' => 'importFillGroup',
+ 'extends' => 'Individual',
+ 'is_active' => TRUE,
+ ]);
+ $customGroupID = $this->ids['CustomGroup']['importFillGroup'];
// Add two custom fields.
$api_params = [
- 'custom_group_id' => $customGroup['id'],
+ 'custom_group_id' => $customGroupID,
'label' => 'importFillField1',
'html_type' => 'Select',
'data_type' => 'String',
$customField1 = $result['id'];
$api_params = [
- 'custom_group_id' => $customGroup['id'],
+ 'custom_group_id' => $customGroupID,
'label' => 'importFillField2',
'html_type' => 'Select',
'data_type' => 'String',
// Now set up values.
$original_gender = 'Male';
$original_custom1 = 'foo';
- $original_job_title = '';
- $original_custom2 = '';
$original_email = 'test-import-fill@example.org';
$import_gender = 'Female';