Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ref] [export] [test] Improve csv test to test final output rather than the csv #14779

Merged
merged 1 commit into from
Jul 10, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 24 additions & 23 deletions tests/phpunit/CRM/Export/BAO/ExportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ class CRM_Export_BAO_ExportTest extends CiviUnitTestCase {
*/
protected $processor;

/**
* Csv output from export.
*
* @var \League\Csv\Reader
*/
protected $csv;

/**
* Cleanup data.
*
Expand Down Expand Up @@ -418,35 +425,28 @@ public function setUpContactExportData() {
*
* @dataProvider getBooleanDataProvider
* @throws \CRM_Core_Exception
* @throws \League\Csv\Exception
*/
public function testExportPrimaryAddress($isPrimaryOnly) {
\Civi::settings()->set('searchPrimaryDetailsOnly', $isPrimaryOnly);
$this->setUpContactExportData();

$selectedFields = [['Individual', 'email', ' '], ['Individual', 'email', '1'], ['Individual', 'email', '2']];
list($tableName) = CRM_Export_BAO_Export::exportComponents(
TRUE,
[],
[['email', 'LIKE', 'c', 0, 1]],
NULL,
$selectedFields,
NULL,
CRM_Export_Form_Select::CONTACT_EXPORT,
"contact_a.id IN ({$this->contactIDs[0]}, {$this->contactIDs[1]})",
NULL,
FALSE,
FALSE,
[
'suppress_csv_for_testing' => TRUE,
]
);
$this->doExportTest([
'ids' => [],
'params' => [['email', 'LIKE', 'c', 0, 1]],
'fields' => $selectedFields,
'componentClause' => "contact_a.id IN ({$this->contactIDs[0]}, {$this->contactIDs[1]})",
'selectAll' => TRUE,
]);

$dao = CRM_Core_DAO::executeQuery('SELECT * from ' . $tableName);
$dao->fetch();
$this->assertEquals('home@example.com', $dao->email);
$this->assertEquals('work@example.com', $dao->work_email);
$this->assertEquals('home@example.com', $dao->home_email);
$this->assertEquals(2, $dao->N);
$row = $this->csv->fetchOne();
$this->assertEquals([
'Email' => 'home@example.com',
'Home-Email' => 'home@example.com',
'Work-Email' => 'work@example.com',
], $row);
$this->assertEquals(2, count($this->csv));
\Civi::settings()->set('searchPrimaryDetailsOnly', FALSE);
}

Expand Down Expand Up @@ -2777,6 +2777,7 @@ protected function diversifyLocationTypes() {
* @param $params
*
* @throws \CRM_Core_Exception
* @throws \League\Csv\Exception
*/
protected function doExportTest($params) {
$this->startCapturingOutput();
Expand All @@ -2797,7 +2798,7 @@ protected function doExportTest($params) {
}
catch (CRM_Core_Exception_PrematureExitException $e) {
$this->processor = $e->errorData['processor'];
ob_end_clean();
$this->csv = $this->captureOutputToCSV();
return;
}
$this->fail('We expected a premature exit exception');
Expand Down