WIP Failing test on importing Preferred Language field using Option value label
[civicrm-core.git] / tests / phpunit / CRM / Contact / Import / Parser / ContactTest.php
index 1a154a2671a3ded5d762255bda0b57b66ada3172..e3025cacbbf2b032218d7620aa2363f60027040b 100644 (file)
@@ -49,13 +49,11 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase {
 
   /**
    * Test that import parser will add contact with employee of relationship.
-   *
-   * @throws \Exception
    */
-  public function testImportParserWtihEmployeeOfRelationship() {
+  public function testImportParserWithEmployeeOfRelationship(): void {
     $this->organizationCreate([
-      "organization_name" => "Agileware",
-      "legal_name"        => "Agileware",
+      'organization_name' => 'Agileware',
+      'legal_name'        => 'Agileware',
     ]);
     $contactImportValues = [
       "first_name"  => "Alok",
@@ -97,16 +95,18 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase {
   }
 
   /**
-   * Test that import parser will not fail when same external_identifier found of deleted contact.
+   * Test that import parser will not fail when same external_identifier found
+   * of deleted contact.
    *
    * @throws \CRM_Core_Exception
+   * @throws \CiviCRM_API3_Exception
    */
-  public function testImportParserWtihDeletedContactExternalIdentifier() {
+  public function testImportParserWithDeletedContactExternalIdentifier(): void {
     $contactId = $this->individualCreate([
       'external_identifier' => 'ext-1',
     ]);
     $this->callAPISuccess('Contact', 'delete', ['id' => $contactId]);
-    list($originalValues, $result) = $this->setUpBaseContact([
+    [$originalValues, $result] = $this->setUpBaseContact([
       'external_identifier' => 'ext-1',
     ]);
     $originalValues['nick_name'] = 'Old Bill';
@@ -140,7 +140,7 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase {
    * @throws \Exception
    */
   public function testImportParserWithUpdateWithExternalIdentifier() {
-    list($originalValues, $result) = $this->setUpBaseContact(['external_identifier' => 'windows']);
+    [$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']);
@@ -163,7 +163,7 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase {
    * @throws \Exception
    */
   public function testImportParserWithUpdateWithExternalIdentifierButNoPrimaryMatch() {
-    list($originalValues, $result) = $this->setUpBaseContact([
+    [$originalValues, $result] = $this->setUpBaseContact([
       'external_identifier' => 'windows',
       'email' => NULL,
     ]);
@@ -188,7 +188,7 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase {
    * @throws \Exception
    */
   public function testImportParserWithUpdateWithContactID() {
-    list($originalValues, $result) = $this->setUpBaseContact([
+    [$originalValues, $result] = $this->setUpBaseContact([
       'external_identifier' => '',
       'email' => NULL,
     ]);
@@ -208,7 +208,7 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase {
    * @throws \Exception
    */
   public function testImportParserWithUpdateWithNoExternalIdentifier() {
-    list($originalValues, $result) = $this->setUpBaseContact();
+    [$originalValues, $result] = $this->setUpBaseContact();
     $originalValues['nick_name'] = 'Old Bill';
     $originalValues['external_identifier'] = 'windows';
     $this->runImport($originalValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID);
@@ -223,7 +223,7 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase {
    * @throws \Exception
    */
   public function testImportParserWithUpdateWithChangedExternalIdentifier() {
-    list($contactValues, $result) = $this->setUpBaseContact(['external_identifier' => 'windows']);
+    [$contactValues, $result] = $this->setUpBaseContact(['external_identifier' => 'windows']);
     $contact_id = $result['id'];
     $contactValues['nick_name'] = 'Old Bill';
     $contactValues['external_identifier'] = 'android';
@@ -239,7 +239,7 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase {
    * @throws \Exception
    */
   public function testImportBillingAddress() {
-    list($contactValues) = $this->setUpBaseContact();
+    [$contactValues] = $this->setUpBaseContact();
     $contactValues['nick_name'] = 'Old Bill';
     $contactValues['external_identifier'] = 'android';
     $contactValues['street_address'] = 'Big Mansion';
@@ -349,7 +349,7 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase {
    * @throws \Exception
    */
   public function testImportPrimaryAddress() {
-    list($contactValues) = $this->setUpBaseContact();
+    [$contactValues] = $this->setUpBaseContact();
     $contactValues['nick_name'] = 'Old Bill';
     $contactValues['external_identifier'] = 'android';
     $contactValues['street_address'] = 'Big Mansion';
@@ -424,7 +424,7 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase {
    */
   public function testAddressWithCustomData() {
     $ids = $this->entityCustomGroupWithSingleFieldCreate('Address', 'AddressTest.php');
-    list($contactValues) = $this->setUpBaseContact();
+    [$contactValues] = $this->setUpBaseContact();
     $contactValues['nick_name'] = 'Old Bill';
     $contactValues['external_identifier'] = 'android';
     $contactValues['street_address'] = 'Big Mansion';
@@ -526,13 +526,29 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase {
     $this->assertEquals('Y', $contact[$this->getCustomFieldName('select')]);
   }
 
+  /**
+   * Test importing in the Preferred Language Field
+   *
+   * @throws \CRM_Core_Exception
+   */
+  public function testPreferredLanguageImport() {
+    $contactValues = [
+      'first_name' => 'Bill',
+      'last_name' => 'Gates',
+      'email' => 'bill.gates@microsoft.com',
+      'nick_name' => 'Billy-boy',
+      'preferred_language' => 'English (Australia)',
+    ];
+    $this->runImport($contactValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID, [NULL, NULL, 'Primary', NULL, NULL]);
+  }
+
   /**
    * Test that the import parser adds the address to the primary location.
    *
    * @throws \Exception
    */
   public function testImportDeceased() {
-    list($contactValues) = $this->setUpBaseContact();
+    [$contactValues] = $this->setUpBaseContact();
     CRM_Core_Session::singleton()->set("dateTypes", 1);
     $contactValues['birth_date'] = '1910-12-17';
     $contactValues['deceased_date'] = '2010-12-17';
@@ -550,7 +566,7 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase {
    * @throws \Exception
    */
   public function testImportTwoAddressFirstPrimary() {
-    list($contactValues) = $this->setUpBaseContact();
+    [$contactValues] = $this->setUpBaseContact();
     $contactValues['nick_name'] = 'Old Bill';
     $contactValues['external_identifier'] = 'android';
     $contactValues['street_address'] = 'Big Mansion';
@@ -615,7 +631,7 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase {
    * @throws \Exception
    */
   public function testImportTwoAddressSecondPrimary() {
-    list($contactValues) = $this->setUpBaseContact();
+    [$contactValues] = $this->setUpBaseContact();
     $contactValues['nick_name'] = 'Old Bill';
     $contactValues['external_identifier'] = 'android';
     $contactValues['street_address'] = 'Big Mansion';
@@ -654,7 +670,7 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase {
    * @throws \Exception
    */
   public function testImportPrimaryAddressUpdate() {
-    list($contactValues) = $this->setUpBaseContact(['external_identifier' => 'android']);
+    [$contactValues] = $this->setUpBaseContact(['external_identifier' => 'android']);
     $contactValues['email'] = 'melinda.gates@microsoft.com';
     $contactValues['phone'] = '98765';
     $contactValues['external_identifier'] = 'android';
@@ -853,8 +869,11 @@ class CRM_Contact_Import_Parser_ContactTest extends CiviUnitTestCase {
    *   that method does not cope with duplicates.
    * @param int|null $ruleGroupId
    *   To test against a specific dedupe rule group, pass its ID as this argument.
+   *
+   * @throws \CRM_Core_Exception
+   * @throws \CiviCRM_API3_Exception
    */
-  protected function runImport($originalValues, $onDuplicateAction, $expectedResult, $mapperLocType = [], $fields = NULL, int $ruleGroupId = NULL) {
+  protected function runImport(array $originalValues, $onDuplicateAction, $expectedResult, $mapperLocType = [], $fields = NULL, int $ruleGroupId = NULL): void {
     if (!$fields) {
       $fields = array_keys($originalValues);
     }