Add unit test towards CRM-20759
authoreileen <emcnaughton@wikimedia.org>
Tue, 27 Jun 2017 01:31:46 +0000 (13:31 +1200)
committereileen <emcnaughton@wikimedia.org>
Sun, 2 Jul 2017 23:35:18 +0000 (11:35 +1200)
tests/phpunit/CRM/Contact/Import/Parser/ContactTest.php

index eb23b93dc7d9f8fa65ab84cf52ae0aed91c26625..712efbaddf7855b52ddc448915ca15a95a92a5ab 100644 (file)
@@ -139,6 +139,23 @@ class CRM_Contact_Imports_Parser_ContactTest extends CiviUnitTestCase {
     $this->callAPISuccessGetSingle('Contact', $contactValues);
   }
 
+  /**
+   * Test that the import parser changes the external identifier when there is a dedupe match.
+   *
+   * @throws \Exception
+   */
+  public function testImportBillingAddress() {
+    list($contactValues) = $this->setUpBaseContact();
+    $contactValues['nick_name'] = 'Old Bill';
+    $contactValues['external_identifier'] = 'android';
+    $contactValues['street_address'] = 'Big Mansion';
+    $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));
+    $address = $this->callAPISuccessGetSingle('Address', array('street_address' => 'Big Mansion'));
+    $this->assertEquals(2, $address['location_type_id']);
+
+    $this->callAPISuccessGetSingle('Contact', $contactValues);
+  }
+
   /**
    * Run the import parser.
    *
@@ -146,11 +163,12 @@ class CRM_Contact_Imports_Parser_ContactTest extends CiviUnitTestCase {
    *
    * @param int $onDuplicateAction
    * @param int $expectedResult
+   * @param array|null $mapperLocType
    */
-  protected function runImport($originalValues, $onDuplicateAction, $expectedResult) {
+  protected function runImport($originalValues, $onDuplicateAction, $expectedResult, $mapperLocType = NULL) {
     $fields = array_keys($originalValues);
     $values = array_values($originalValues);
-    $parser = new CRM_Contact_Import_Parser_Contact($fields);
+    $parser = new CRM_Contact_Import_Parser_Contact($fields, $mapperLocType);
     $parser->_contactType = 'Individual';
     $parser->_onDuplicate = $onDuplicateAction;
     $parser->init();