Skip to content

Commit

Permalink
Still output csv file, even if no rows are in it
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Oct 8, 2019
1 parent 41c0e58 commit 18fe79a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
4 changes: 2 additions & 2 deletions CRM/Export/BAO/ExportProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -2376,6 +2376,7 @@ public function writeCSVFromTable() {

$query = "SELECT * FROM $exportTempTable";

CRM_Core_Report_Excel::makeCSVTable($headerRows, [], NULL, TRUE, TRUE);
while (1) {
$limitQuery = $query . "
LIMIT $offset, $limit
Expand All @@ -2399,10 +2400,9 @@ public function writeCSVFromTable() {
$headerRows,
$componentDetails,
NULL,
$writeHeader
FALSE
);

$writeHeader = FALSE;
$offset += $limit;
}
}
Expand Down
25 changes: 25 additions & 0 deletions tests/phpunit/CRM/Export/BAO/ExportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1178,6 +1178,31 @@ public function testMergeSameAddressGreetingOptions() {
$this->assertCount(2, $this->csv);
}

/**
* Test exporting when no rows are retrieved.
*
* @throws \CRM_Core_Exception
* @throws \League\Csv\Exception
*/
public function testExportNoRows() {
$contactA = $this->callAPISuccess('contact', 'create', [
'first_name' => 'John',
'last_name' => 'Doe',
'contact_type' => 'Individual',
]);
$this->doExportTest([
'selectAll' => TRUE,
'ids' => [$contactA['id']],
'exportParams' => [
'postal_mailing_export' => [
'postal_mailing_export' => TRUE,
],
'mergeSameAddress' => TRUE,
],
]);
$this->assertEquals('Contact ID', $this->csv->getHeader()[0]);
}

/**
* Test that deceased and do not mail contacts are removed from contacts before
*
Expand Down

0 comments on commit 18fe79a

Please sign in to comment.