Merge pull request #14934 from civicrm/5.16
[civicrm-core.git] / tests / phpunit / CRM / Contact / Import / Parser / ContactTest.php
index 783015fd973a9b3a27948f19f43c01cbc1566af2..ff4e11c6c9ef64bfc2624ea51031de8124525174 100644 (file)
  * @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.
@@ -46,21 +53,31 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase {
     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.
    *
    * @throws \Exception
    */
   public function testImportParserWtihEmployeeOfRelationship() {
-    $this->organizationCreate(array(
+    $this->organizationCreate([
       "organization_name" => "Agileware",
       "legal_name"        => "Agileware",
-    ));
-    $contactImportValues = array(
+    ]);
+    $contactImportValues = [
       "first_name"  => "Alok",
       "last_name"   => "Patel",
       "Employee of" => "Agileware",
-    );
+    ];
 
     $fields = array_keys($contactImportValues);
     $values = array_values($contactImportValues);
@@ -69,30 +86,30 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase {
     $parser->init();
     $this->mapRelationshipFields($fields, $parser->getAllFields());
 
-    $parser = new CRM_Contact_Import_Parser_Contact($fields, [], [], [], array(
+    $parser = new CRM_Contact_Import_Parser_Contact($fields, [], [], [], [
       NULL,
       NULL,
       $fields[2],
-    ), array(
+    ], [
       NULL,
       NULL,
       "Organization",
-    ), array(
+    ], [
       NULL,
       NULL,
       "organization_name",
-    ), [], [], [], [], []);
+    ], [], [], [], [], []);
 
     $parser->_contactType = 'Individual';
     $parser->_onDuplicate = CRM_Import_Parser::DUPLICATE_UPDATE;
     $parser->init();
 
     $this->assertEquals(CRM_Import_Parser::VALID, $parser->import(CRM_Import_Parser::DUPLICATE_UPDATE, $values), 'Return code from parser import was not as expected');
-    $this->callAPISuccess("Contact", "get", array(
+    $this->callAPISuccess("Contact", "get", [
       "first_name"        => "Alok",
       "last_name"         => "Patel",
       "organization_name" => "Agileware",
-    ));
+    ]);
   }
 
   /**
@@ -101,17 +118,17 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase {
    * @throws \Exception
    */
   public function testImportParserWtihDeletedContactExternalIdentifier() {
-    $contactId = $this->individualCreate(array(
+    $contactId = $this->individualCreate([
       "external_identifier" => "ext-1",
-    ));
+    ]);
     CRM_Contact_BAO_Contact::deleteContact($contactId);
-    list($originalValues, $result) = $this->setUpBaseContact(array(
+    list($originalValues, $result) = $this->setUpBaseContact([
       'external_identifier' => 'ext-1',
-    ));
+    ]);
     $originalValues['nick_name'] = 'Old Bill';
     $this->runImport($originalValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID);
     $originalValues['id'] = $result['id'];
-    $this->assertEquals('ext-1', $this->callAPISuccessGetValue('Contact', array('id' => $result['id'], 'return' => 'external_identifier')));
+    $this->assertEquals('ext-1', $this->callAPISuccessGetValue('Contact', ['id' => $result['id'], 'return' => 'external_identifier']));
     $this->callAPISuccessGetSingle('Contact', $originalValues);
   }
 
@@ -127,7 +144,7 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase {
     $originalValues['nick_name'] = 'Old Bill';
     $this->runImport($originalValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID);
     $originalValues['id'] = $result['id'];
-    $this->assertEquals('Old Bill', $this->callAPISuccessGetValue('Contact', array('id' => $result['id'], 'return' => 'nick_name')));
+    $this->assertEquals('Old Bill', $this->callAPISuccessGetValue('Contact', ['id' => $result['id'], 'return' => 'nick_name']));
     $this->callAPISuccessGetSingle('Contact', $originalValues);
   }
 
@@ -139,7 +156,7 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase {
    * @throws \Exception
    */
   public function testImportParserWithUpdateWithExternalIdentifier() {
-    list($originalValues, $result) = $this->setUpBaseContact(array('external_identifier' => 'windows'));
+    list($originalValues, $result) = $this->setUpBaseContact(['external_identifier' => 'windows']);
 
     $this->assertEquals($result['id'], CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', 'windows', 'id', 'external_identifier', TRUE));
     $this->assertEquals('windows', $result['external_identifier']);
@@ -148,7 +165,7 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase {
     $this->runImport($originalValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID);
     $originalValues['id'] = $result['id'];
 
-    $this->assertEquals('Old Bill', $this->callAPISuccessGetValue('Contact', array('id' => $result['id'], 'return' => 'nick_name')));
+    $this->assertEquals('Old Bill', $this->callAPISuccessGetValue('Contact', ['id' => $result['id'], 'return' => 'nick_name']));
     $this->callAPISuccessGetSingle('Contact', $originalValues);
   }
 
@@ -173,7 +190,7 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase {
     $this->runImport($originalValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID);
     $originalValues['id'] = $result['id'];
 
-    $this->assertEquals('Old Bill', $this->callAPISuccessGetValue('Contact', array('id' => $result['id'], 'return' => 'nick_name')));
+    $this->assertEquals('Old Bill', $this->callAPISuccessGetValue('Contact', ['id' => $result['id'], 'return' => 'nick_name']));
     $this->callAPISuccessGetSingle('Contact', $originalValues);
   }
 
@@ -187,10 +204,10 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase {
    * @throws \Exception
    */
   public function testImportParserWithUpdateWithContactID() {
-    list($originalValues, $result) = $this->setUpBaseContact(array(
+    list($originalValues, $result) = $this->setUpBaseContact([
       'external_identifier' => '',
       'email' => NULL,
-    ));
+    ]);
     $updateValues = ['id' => $result['id'], 'email' => 'bill@example.com'];
     // This is some deep weirdness - this sets a flag for updatingBlankLocinfo - allowing input to be blanked
     // (which IS a good thing but it's pretty weird & all to do with legacy profile stuff).
@@ -212,7 +229,7 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase {
     $originalValues['external_identifier'] = 'windows';
     $this->runImport($originalValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID);
     $originalValues['id'] = $result['id'];
-    $this->assertEquals('Old Bill', $this->callAPISuccessGetValue('Contact', array('id' => $result['id'], 'return' => 'nick_name')));
+    $this->assertEquals('Old Bill', $this->callAPISuccessGetValue('Contact', ['id' => $result['id'], 'return' => 'nick_name']));
     $this->callAPISuccessGetSingle('Contact', $originalValues);
   }
 
@@ -222,13 +239,13 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase {
    * @throws \Exception
    */
   public function testImportParserWithUpdateWithChangedExternalIdentifier() {
-    list($contactValues, $result) = $this->setUpBaseContact(array('external_identifier' => 'windows'));
+    list($contactValues, $result) = $this->setUpBaseContact(['external_identifier' => 'windows']);
     $contact_id = $result['id'];
     $contactValues['nick_name'] = 'Old Bill';
     $contactValues['external_identifier'] = 'android';
     $this->runImport($contactValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID);
     $contactValues['id'] = $contact_id;
-    $this->assertEquals('Old Bill', $this->callAPISuccessGetValue('Contact', array('id' => $contact_id, 'return' => 'nick_name')));
+    $this->assertEquals('Old Bill', $this->callAPISuccessGetValue('Contact', ['id' => $contact_id, 'return' => 'nick_name']));
     $this->callAPISuccessGetSingle('Contact', $contactValues);
   }
 
@@ -243,15 +260,15 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase {
     $contactValues['external_identifier'] = 'android';
     $contactValues['street_address'] = 'Big Mansion';
     $contactValues['phone'] = '911';
-    $this->runImport($contactValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID, array(0 => NULL, 1 => NULL, 2 => NULL, 3 => NULL, 4 => NULL, 5 => 2, 6 => 2));
-    $address = $this->callAPISuccessGetSingle('Address', array('street_address' => 'Big Mansion'));
+    $this->runImport($contactValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID, [0 => NULL, 1 => NULL, 2 => NULL, 3 => NULL, 4 => NULL, 5 => 2, 6 => 2]);
+    $address = $this->callAPISuccessGetSingle('Address', ['street_address' => 'Big Mansion']);
     $this->assertEquals(2, $address['location_type_id']);
 
-    $phone = $this->callAPISuccessGetSingle('Phone', array('phone' => '911'));
+    $phone = $this->callAPISuccessGetSingle('Phone', ['phone' => '911']);
     $this->assertEquals(2, $phone['location_type_id']);
 
     $contact = $this->callAPISuccessGetSingle('Contact', $contactValues);
-    $this->callAPISuccess('Contact', 'delete', array('id' => $contact['id']));
+    $this->callAPISuccess('Contact', 'delete', ['id' => $contact['id']]);
   }
 
   /**
@@ -265,23 +282,25 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase {
     $contactValues['external_identifier'] = 'android';
     $contactValues['street_address'] = 'Big Mansion';
     $contactValues['phone'] = 12334;
-    $this->runImport($contactValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID, array(0 => NULL, 1 => NULL, 2 => 'Primary', 3 => NULL, 4 => NULL, 5 => 'Primary', 6 => 'Primary'));
-    $address = $this->callAPISuccessGetSingle('Address', array('street_address' => 'Big Mansion'));
+    $this->runImport($contactValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID, [0 => NULL, 1 => NULL, 2 => 'Primary', 3 => NULL, 4 => NULL, 5 => 'Primary', 6 => 'Primary']);
+    $address = $this->callAPISuccessGetSingle('Address', ['street_address' => 'Big Mansion']);
     $this->assertEquals(1, $address['location_type_id']);
     $this->assertEquals(1, $address['is_primary']);
 
-    $phone = $this->callAPISuccessGetSingle('Phone', array('phone' => '12334'));
+    $phone = $this->callAPISuccessGetSingle('Phone', ['phone' => '12334']);
     $this->assertEquals(1, $phone['location_type_id']);
 
-    $this->callAPISuccessGetSingle('Email', array('email' => 'bill.gates@microsoft.com'));
+    $this->callAPISuccessGetSingle('Email', ['email' => 'bill.gates@microsoft.com']);
 
     $contact = $this->callAPISuccessGetSingle('Contact', $contactValues);
-    $this->callAPISuccess('Contact', 'delete', array('id' => $contact['id']));
+    $this->callAPISuccess('Contact', 'delete', ['id' => $contact['id']]);
   }
 
   /**
    * Test that address custom fields can be imported
    * FIXME: Api4
+   *
+   * @throws \CRM_Core_Exception
    */
   public function testAddressWithCustomData() {
     $ids = $this->entityCustomGroupWithSingleFieldCreate('Address', 'AddressTest.php');
@@ -290,11 +309,68 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase {
     $contactValues['external_identifier'] = 'android';
     $contactValues['street_address'] = 'Big Mansion';
     $contactValues['custom_' . $ids['custom_field_id']] = 'Update';
-    $this->runImport($contactValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID, array(0 => NULL, 1 => NULL, 2 => NULL, 3 => NULL, 4 => NULL, 5 => 'Primary', 6 => 'Primary'));
+    $this->runImport($contactValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID, [0 => NULL, 1 => NULL, 2 => NULL, 3 => NULL, 4 => NULL, 5 => 'Primary', 6 => 'Primary']);
     $address = $this->callAPISuccessGetSingle('Address', ['street_address' => 'Big Mansion', 'return' => 'custom_' . $ids['custom_field_id']]);
     $this->assertEquals('Update', $address['custom_' . $ids['custom_field_id']]);
   }
 
+  /**
+   * Test gender works when you specify the label.
+   *
+   * There is an expectation that you can import by label here.
+   *
+   * @throws \CRM_Core_Exception
+   */
+  public function testGenderLabel() {
+    $contactValues = [
+      'first_name' => 'Bill',
+      'last_name' => 'Gates',
+      'email' => 'bill.gates@microsoft.com',
+      'nick_name' => 'Billy-boy',
+      'gender_id' => 'Female',
+    ];
+    $this->runImport($contactValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID, [NULL, NULL, 'Primary', NULL, NULL]);
+    $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.
    *
@@ -310,7 +386,7 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase {
     $this->assertEquals('1910-12-17', $contact['birth_date']);
     $this->assertEquals('2010-12-17', $contact['deceased_date']);
     $this->assertEquals(1, $contact['is_deceased']);
-    $this->callAPISuccess('Contact', 'delete', array('id' => $contact['id']));
+    $this->callAPISuccess('Contact', 'delete', ['id' => $contact['id']]);
   }
 
   /**
@@ -329,9 +405,9 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase {
     $contactValues['phone_2'] = 4444;
     $fields[] = 'street_address';
     $fields[] = 'phone';
-    $this->runImport($contactValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID, array(0 => NULL, 1 => NULL, 2 => NULL, 3 => NULL, 4 => NULL, 5 => 'Primary', 6 => 'Primary', 7 => 3, 8 => 3), $fields);
-    $contact = $this->callAPISuccessGetSingle('Contact', array('external_identifier' => 'android'));
-    $address = $this->callAPISuccess('Address', 'get', array('contact_id' => $contact['id'], 'sequential' => 1));
+    $this->runImport($contactValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID, [0 => NULL, 1 => NULL, 2 => NULL, 3 => NULL, 4 => NULL, 5 => 'Primary', 6 => 'Primary', 7 => 3, 8 => 3], $fields);
+    $contact = $this->callAPISuccessGetSingle('Contact', ['external_identifier' => 'android']);
+    $address = $this->callAPISuccess('Address', 'get', ['contact_id' => $contact['id'], 'sequential' => 1]);
 
     $this->assertEquals(3, $address['values'][0]['location_type_id']);
     $this->assertEquals(0, $address['values'][0]['is_primary']);
@@ -341,7 +417,7 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase {
     $this->assertEquals(1, $address['values'][1]['is_primary']);
     $this->assertEquals('Big Mansion', $address['values'][1]['street_address']);
 
-    $phone = $this->callAPISuccess('Phone', 'get', array('contact_id' => $contact['id'], 'sequential' => 1));
+    $phone = $this->callAPISuccess('Phone', 'get', ['contact_id' => $contact['id'], 'sequential' => 1]);
     $this->assertEquals(1, $phone['values'][0]['location_type_id']);
     $this->assertEquals(1, $phone['values'][0]['is_primary']);
     $this->assertEquals(12334, $phone['values'][0]['phone']);
@@ -349,7 +425,7 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase {
     $this->assertEquals(0, $phone['values'][1]['is_primary']);
     $this->assertEquals(4444, $phone['values'][1]['phone']);
 
-    $this->callAPISuccess('Contact', 'delete', array('id' => $contact['id']));
+    $this->callAPISuccess('Contact', 'delete', ['id' => $contact['id']]);
   }
 
   /**
@@ -368,9 +444,9 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase {
     $contactValues['phone_2'] = 4444;
     $fields[] = 'street_address';
     $fields[] = 'phone';
-    $this->runImport($contactValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID, array(0 => NULL, 1 => NULL, 2 => NULL, 3 => NULL, 4 => NULL, 5 => 3, 6 => 3, 7 => 'Primary', 8 => 'Primary'), $fields);
-    $contact = $this->callAPISuccessGetSingle('Contact', array('external_identifier' => 'android'));
-    $address = $this->callAPISuccess('Address', 'get', array('contact_id' => $contact['id'], 'sequential' => 1))['values'];
+    $this->runImport($contactValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID, [0 => NULL, 1 => NULL, 2 => NULL, 3 => NULL, 4 => NULL, 5 => 3, 6 => 3, 7 => 'Primary', 8 => 'Primary'], $fields);
+    $contact = $this->callAPISuccessGetSingle('Contact', ['external_identifier' => 'android']);
+    $address = $this->callAPISuccess('Address', 'get', ['contact_id' => $contact['id'], 'sequential' => 1])['values'];
 
     $this->assertEquals(1, $address[1]['location_type_id']);
     $this->assertEquals(1, $address[1]['is_primary']);
@@ -388,7 +464,7 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase {
     $this->assertEquals(1, $phone[0]['is_primary']);
     $this->assertEquals(4444, $phone[0]['phone']);
 
-    $this->callAPISuccess('Contact', 'delete', array('id' => $contact['id']));
+    $this->callAPISuccess('Contact', 'delete', ['id' => $contact['id']]);
   }
 
   /**
@@ -397,21 +473,21 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase {
    * @throws \Exception
    */
   public function testImportPrimaryAddressUpdate() {
-    list($contactValues) = $this->setUpBaseContact(array('external_identifier' => 'android'));
+    list($contactValues) = $this->setUpBaseContact(['external_identifier' => 'android']);
     $contactValues['email'] = 'melinda.gates@microsoft.com';
     $contactValues['phone'] = '98765';
     $contactValues['external_identifier'] = 'android';
     $contactValues['street_address'] = 'Big Mansion';
     $contactValues['city'] = 'Big City';
-    $contactID = $this->callAPISuccessGetValue('Contact', array('external_identifier' => 'android', 'return' => 'id'));
-    $originalAddress = $this->callAPISuccess('Address', 'create', array('location_type_id' => 2, 'street_address' => 'small house', 'contact_id' => $contactID));
-    $originalPhone = $this->callAPISuccess('phone', 'create', array('location_type_id' => 2, 'phone' => '1234', 'contact_id' => $contactID));
-    $this->runImport($contactValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID, array(0 => NULL, 1 => NULL, 2 => 'Primary', 3 => NULL, 4 => NULL, 5 => 'Primary', 6 => 'Primary', 7 => 'Primary'));
+    $contactID = $this->callAPISuccessGetValue('Contact', ['external_identifier' => 'android', 'return' => 'id']);
+    $originalAddress = $this->callAPISuccess('Address', 'create', ['location_type_id' => 2, 'street_address' => 'small house', 'contact_id' => $contactID]);
+    $originalPhone = $this->callAPISuccess('phone', 'create', ['location_type_id' => 2, 'phone' => '1234', 'contact_id' => $contactID]);
+    $this->runImport($contactValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID, [0 => NULL, 1 => NULL, 2 => 'Primary', 3 => NULL, 4 => NULL, 5 => 'Primary', 6 => 'Primary', 7 => 'Primary']);
     $phone = $this->callAPISuccessGetSingle('Phone', ['phone' => '98765']);
     $this->assertEquals(2, $phone['location_type_id']);
     $this->assertEquals($originalPhone['id'], $phone['id']);
     $email = $this->callAPISuccess('Email', 'getsingle', ['contact_id' => $contactID]);
-    $address = $this->callAPISuccessGetSingle('Address', array('street_address' => 'Big Mansion'));
+    $address = $this->callAPISuccessGetSingle('Address', ['street_address' => 'Big Mansion']);
     $this->assertEquals(2, $address['location_type_id']);
     $this->assertEquals($originalAddress['id'], $address['id']);
     $this->assertEquals('Big City', $address['city']);
@@ -422,17 +498,17 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase {
    * Test the determination of whether a custom field is valid.
    */
   public function testCustomFieldValidation() {
-    $errorMessage = array();
-    $customGroup = $this->customGroupCreate(array(
+    $errorMessage = [];
+    $customGroup = $this->customGroupCreate([
       'extends' => 'Contact',
       'title' => 'ABC',
-    ));
-    $customField = $this->customFieldOptionValueCreate($customGroup, 'fieldABC', array('html_type' => 'Multi-Select'));
-    $params = array(
+    ]);
+    $customField = $this->customFieldOptionValueCreate($customGroup, 'fieldABC', ['html_type' => 'Multi-Select']);
+    $params = [
       'custom_' . $customField['id'] => 'Label1|Label2',
-    );
+    ];
     CRM_Contact_Import_Parser_Contact::isErrorInCustomData($params, $errorMessage);
-    $this->assertEquals(array(), $errorMessage);
+    $this->assertEquals([], $errorMessage);
   }
 
   /**
@@ -443,49 +519,43 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase {
    */
   public function testImportFill() {
     // Create a custom field group for testing.
-    $custom_group_name = 'importFillGroup';
-    $results = $this->callAPISuccess('customGroup', 'get', array('title' => $custom_group_name));
-    if ($results['count'] == 0) {
-      $api_params = array(
-        '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 = array(
-      'custom_group_id' => $customGroup['id'],
+    $api_params = [
+      'custom_group_id' => $customGroupID,
       'label' => 'importFillField1',
       'html_type' => 'Select',
       'data_type' => 'String',
-      'option_values' => array(
+      'option_values' => [
         'foo' => 'Foo',
         'bar' => 'Bar',
-      ),
-    );
+      ],
+    ];
     $result = $this->callAPISuccess('custom_field', 'create', $api_params);
     $customField1 = $result['id'];
 
-    $api_params = array(
-      'custom_group_id' => $customGroup['id'],
+    $api_params = [
+      'custom_group_id' => $customGroupID,
       'label' => 'importFillField2',
       'html_type' => 'Select',
       'data_type' => 'String',
-      'option_values' => array(
+      'option_values' => [
         'baz' => 'Baz',
         'boo' => 'Boo',
-      ),
-    );
+      ],
+    ];
     $result = $this->callAPISuccess('custom_field', 'create', $api_params);
     $customField2 = $result['id'];
 
     // 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';
@@ -495,42 +565,42 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase {
 
     // Create contact with both one known core field and one custom
     // field filled in.
-    $api_params = array(
+    $api_params = [
       'contact_type' => 'Individual',
       'email' => $original_email,
       'gender' => $original_gender,
       'custom_' . $customField1 => $original_custom1,
-    );
+    ];
     $result = $this->callAPISuccess('contact', 'create', $api_params);
     $contact_id = $result['id'];
 
     // Run an import.
-    $import = array(
+    $import = [
       'email' => $original_email,
       'gender_id' => $import_gender,
       'custom_' . $customField1 => $import_custom1,
       'job_title' => $import_job_title,
       'custom_' . $customField2 => $import_custom2,
-    );
+    ];
 
     $this->runImport($import, CRM_Import_Parser::DUPLICATE_FILL, CRM_Import_Parser::VALID);
 
-    $expected = array(
+    $expected = [
       'gender' => $original_gender,
       'custom_' . $customField1 => $original_custom1,
       'job_title' => $import_job_title,
       'custom_' . $customField2 => $import_custom2,
-    );
+    ];
 
-    $params = array(
+    $params = [
       'id' => $contact_id,
-      'return' => array(
+      'return' => [
         'gender',
         'custom_' . $customField1,
         'job_title',
         'custom_' . $customField2,
-      ),
-    );
+      ],
+    ];
     $result = civicrm_api3('Contact', 'get', $params);
     $values = array_pop($result['values']);
     foreach ($expected as $field => $expected_value) {
@@ -555,19 +625,19 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase {
   public function testImportAmbiguousStateCountry() {
     $this->callAPISuccess('Setting', 'create', ['defaultContactCountry' => 1228]);
     $countries = CRM_Core_PseudoConstant::country(FALSE, FALSE);
-    $this->callAPISuccess('Setting', 'create', array('countryLimit' => array(array_search('United States', $countries), array_search('Guyana', $countries), array_search('Netherlands', $countries))));
-    $this->callAPISuccess('Setting', 'create', array('provinceLimit' => array(array_search('United States', $countries), array_search('Guyana', $countries), array_search('Netherlands', $countries))));
-    $mapper = array(0 => NULL, 1 => NULL, 2 => 'Primary', 3 => NULL);
+    $this->callAPISuccess('Setting', 'create', ['countryLimit' => [array_search('United States', $countries), array_search('Guyana', $countries), array_search('Netherlands', $countries)]]);
+    $this->callAPISuccess('Setting', 'create', ['provinceLimit' => [array_search('United States', $countries), array_search('Guyana', $countries), array_search('Netherlands', $countries)]]);
+    $mapper = [0 => NULL, 1 => NULL, 2 => 'Primary', 3 => NULL];
     list($contactValues) = $this->setUpBaseContact();
     $fields = array_keys($contactValues);
-    $addressValues = array(
+    $addressValues = [
       'street_address' => 'PO Box 2716',
       'city' => 'Midway',
       'state_province' => 'UT',
       'postal_code' => 84049,
       'country' => 'United States',
-    );
-    $locationTypes = $this->callAPISuccess('Address', 'getoptions', array('field' => 'location_type_id'));
+    ];
+    $locationTypes = $this->callAPISuccess('Address', 'getoptions', ['field' => 'location_type_id']);
     $locationTypes = $locationTypes['values'];
     foreach ($addressValues as $field => $value) {
       $contactValues['home_' . $field] = $value;
@@ -580,7 +650,7 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase {
     $contactValues['work_country'] = '';
 
     $this->runImport($contactValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID, $mapper, $fields);
-    $addresses = $this->callAPISuccess('Address', 'get', array('contact_id' => array('>' => 2), 'sequential' => 1));
+    $addresses = $this->callAPISuccess('Address', 'get', ['contact_id' => ['>' => 2], 'sequential' => 1]);
     $this->assertEquals(2, $addresses['count']);
     $this->assertEquals(array_search('United States', $countries), $addresses['values'][0]['country_id']);
     $this->assertEquals(array_search('United States', $countries), $addresses['values'][1]['country_id']);
@@ -631,18 +701,18 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase {
    *   Optional extra parameters to set.
    *
    * @return array
-   * @throws \Exception
+   * @throws \CRM_Core_Exception
    */
-  protected function setUpBaseContact($params = array()) {
-    $originalValues = array_merge(array(
+  protected function setUpBaseContact($params = []) {
+    $originalValues = array_merge([
       'first_name' => 'Bill',
       'last_name' => 'Gates',
       'email' => 'bill.gates@microsoft.com',
       'nick_name' => 'Billy-boy',
-    ), $params);
+    ], $params);
     $this->runImport($originalValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID);
     $result = $this->callAPISuccessGetSingle('Contact', $originalValues);
-    return array($originalValues, $result);
+    return [$originalValues, $result];
   }
 
 }