[REF][TEST][EXPORT] minor test cleanup & minor cleanup of code it tests
authoreileen <emcnaughton@wikimedia.org>
Sat, 20 Jul 2019 03:05:44 +0000 (15:05 +1200)
committereileen <emcnaughton@wikimedia.org>
Sat, 20 Jul 2019 03:05:44 +0000 (15:05 +1200)
CRM/Export/BAO/ExportProcessor.php
tests/phpunit/CRM/Export/BAO/ExportTest.php

index 04f62644d7bfbff3c447cc9f20e789118bb02bd6..871f3f9127799e478898ce9653009ba5831cd3be 100644 (file)
@@ -970,10 +970,8 @@ class CRM_Export_BAO_ExportProcessor {
           $fieldValue = CRM_Utils_Array::value($fieldValue, $imProviders);
         }
         elseif (strstr($field, 'master_id')) {
-          $masterAddressId = NULL;
-          if (isset($iterationDAO->$field)) {
-            $masterAddressId = $iterationDAO->$field;
-          }
+          // @todo - why not just $field === 'master_id'  - what else would it be?
+          $masterAddressId = $iterationDAO->$field ?? NULL;
           // get display name of contact that address is shared.
           $fieldValue = CRM_Contact_BAO_Contact::getMasterDisplayName($masterAddressId);
         }
index 68b911d740be3431af58303d856b54f43f6d4840..e385cd15e847495a866915b38fc46b78e30d4fcf 100644 (file)
@@ -1045,7 +1045,10 @@ class CRM_Export_BAO_ExportTest extends CiviUnitTestCase {
   }
 
   /**
-   * Test master_address_id field.
+   * Test master_address_id field when no merge is in play.
+   *
+   * @throws \CRM_Core_Exception
+   * @throws \League\Csv\Exception
    */
   public function testExportMasterAddress() {
     $this->setUpContactExportData();
@@ -1054,32 +1057,12 @@ class CRM_Export_BAO_ExportTest extends CiviUnitTestCase {
     $selectedFields = [
       ['contact_type' => 'Individual', 'name' => 'master_id', 'location_type_id' => 1],
     ];
-    list($tableName, $sqlColumns) = CRM_Export_BAO_Export::exportComponents(
-      TRUE,
-      [$this->contactIDs[1]],
-      [],
-      NULL,
-      $selectedFields,
-      NULL,
-      CRM_Export_Form_Select::CONTACT_EXPORT,
-      "contact_a.id IN ({$this->contactIDs[1]})",
-      NULL,
-      FALSE,
-      FALSE,
-      [
-        'suppress_csv_for_testing' => TRUE,
-      ]
-    );
-    $field = key($sqlColumns);
-
-    //assert the exported result
-    $masterName = CRM_Core_DAO::singleValueQuery("SELECT {$field} FROM {$tableName}");
-    $displayName = CRM_Contact_BAO_Contact::getMasterDisplayName($this->masterAddressID);
-    $this->assertEquals($displayName, $masterName);
-
-    // delete the export temp table and component table
-    $sql = "DROP TABLE IF EXISTS {$tableName}";
-    CRM_Core_DAO::executeQuery($sql);
+    $this->doExportTest([
+      'fields' => $selectedFields,
+      'ids' => [$this->contactIDs[1]],
+    ]);
+    $row = $this->csv->fetchOne();
+    $this->assertEquals(CRM_Contact_BAO_Contact::getMasterDisplayName($this->masterAddressID), $row['Home-Master Address Belongs To']);
   }
 
   /**