From ffd511ee8abe7efbfb997dcae8291825b4fda2ad Mon Sep 17 00:00:00 2001 From: eileen Date: Sat, 20 Jul 2019 15:05:44 +1200 Subject: [PATCH] [REF][TEST][EXPORT] minor test cleanup & minor cleanup of code it tests --- CRM/Export/BAO/ExportProcessor.php | 6 ++-- tests/phpunit/CRM/Export/BAO/ExportTest.php | 37 ++++++--------------- 2 files changed, 12 insertions(+), 31 deletions(-) diff --git a/CRM/Export/BAO/ExportProcessor.php b/CRM/Export/BAO/ExportProcessor.php index 04f62644d7..871f3f9127 100644 --- a/CRM/Export/BAO/ExportProcessor.php +++ b/CRM/Export/BAO/ExportProcessor.php @@ -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); } diff --git a/tests/phpunit/CRM/Export/BAO/ExportTest.php b/tests/phpunit/CRM/Export/BAO/ExportTest.php index 68b911d740..e385cd15e8 100644 --- a/tests/phpunit/CRM/Export/BAO/ExportTest.php +++ b/tests/phpunit/CRM/Export/BAO/ExportTest.php @@ -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']); } /** -- 2.25.1