Skip to content

Commit

Permalink
Merge pull request #15948 from eileenmcnaughton/export_test
Browse files Browse the repository at this point in the history
Revised version of test from #15725
  • Loading branch information
seamuslee001 authored Jan 7, 2020
2 parents 050abb2 + 285fa72 commit 306a860
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion tests/phpunit/CRM/Export/BAO/ExportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ public function testExportRelationshipsMergeToHousehold($includeHouseHold) {
'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']);
Expand Down Expand Up @@ -1214,6 +1214,46 @@ public function testExportNoRows() {
$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
*
Expand Down

0 comments on commit 306a860

Please sign in to comment.