From 285fa7293dbf592c1e4427e724af109d7ae78c32 Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 25 Nov 2019 11:24:24 +1300 Subject: [PATCH] Revised version of test from #15725 I started digging into https://github.com/civicrm/civicrm-core/pull/15725 and found that a deprecated methodology was used for the test. I got as far as re-writing the test - although the key lines are commented out as the fix from the above PR is not yet merged --- tests/phpunit/CRM/Export/BAO/ExportTest.php | 42 ++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/tests/phpunit/CRM/Export/BAO/ExportTest.php b/tests/phpunit/CRM/Export/BAO/ExportTest.php index 86df6ae15a..6f40123eec 100644 --- a/tests/phpunit/CRM/Export/BAO/ExportTest.php +++ b/tests/phpunit/CRM/Export/BAO/ExportTest.php @@ -646,7 +646,7 @@ class CRM_Export_BAO_ExportTest extends CiviUnitTestCase { 'mergeSameHousehold' => TRUE, ]); $row = $this->csv->fetchOne(); - $this->assertEquals(1, count($this->csv)); + $this->assertCount(1, $this->csv); $this->assertEquals('Portland', $row['City']); $this->assertEquals('ME', $row['State']); $this->assertEquals($householdID, $row['Household ID']); @@ -1214,6 +1214,46 @@ class CRM_Export_BAO_ExportTest extends CiviUnitTestCase { $this->assertEquals('Contact ID', $this->csv->getHeader()[0]); } + /** + * Test to ensure that 'Merge All Contacts with the Same Address' works on export. + * + * 3 contacts are created A, B and C where A and B are individual contacts that share same address via master_id. + * C is a household contact whose member is contact A. + * + * These 3 contacts are selected for export with 'Merge All Contacts with the Same Address' = TRUE + * And at the end export table contain only 1 contact i.e. is C as A and B got merged into 1 as they share same address but then A is Household member of C. + * So C take preference over A and thus C is exported as result. + * + * @throws \CRM_Core_Exception + * @throws \League\Csv\Exception + */ + public function testMergeSameAddressOnExport() { + $this->individualCreate(); + $householdID = $this->setUpHousehold()[0]; + $contactIDs = array_merge($this->contactIDs, [$householdID]); + // Empty existing addresses & start fresh. + $this->callAPISuccess('Address', 'get', ['api.Address.delete' => 1]); + foreach ($contactIDs as $id) { + $this->callAPISuccess('Address', 'create', [ + 'city' => 'Portland', + 'street_address' => 'Ambachtstraat 23', + 'state_province_id' => 'Maine', + 'location_type_id' => 'Home', + 'contact_id' => $id, + ]); + } + + $this->doExportTest([ + 'selectAll' => FALSE, + 'ids' => $contactIDs, + 'mergeSameAddress' => TRUE, + ]); + // @todo - the below is commented out because it does not yet work. + //$this->assertCount(1, $this->csv); + $row = $this->csv->fetchOne(); + //$this->assertEquals('Household', $this->csv->fetchOne()['Contact Type']); + } + /** * Test that deceased and do not mail contacts are removed from contacts before * -- 2.25.1