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] [Test] [Export] Convert some more tests to use the newer function #14933

Merged
merged 1 commit into from
Aug 2, 2019
Merged
Show file tree
Hide file tree
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
5 changes: 0 additions & 5 deletions CRM/Export/BAO/ExportProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -1397,11 +1397,6 @@ public function getSqlColumnDefinition($fieldName, $columnName) {
return "$fieldName varchar(128)";
}

if (substr($fieldName, -11) == 'campaign_id') {
// CRM-14398
return "$fieldName varchar(128)";
}

$queryFields = $this->getQueryFields();
// @todo remove the enotice avoidance here, ensure all columns are declared.
// tests will fail on the enotices until they all are & then all the 'else'
Expand Down
98 changes: 34 additions & 64 deletions tests/phpunit/CRM/Export/BAO/ExportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public function tearDown() {
'civicrm_case',
'civicrm_case_contact',
'civicrm_case_activity',
'civicrm_campaign',
]);

if (!empty($this->locationTypes)) {
Expand Down Expand Up @@ -538,32 +539,28 @@ public function testExportPseudoField() {
* Test that when exporting a pseudoField it is reset for NULL entries.
*
* This is specific to the example in CRM-14398
*
* @throws \CRM_Core_Exception
* @throws \League\Csv\Exception
*/
public function testExportPseudoFieldCampaign() {
$this->setUpContributionExportData();
$campaign = $this->callAPISuccess('Campaign', 'create', ['title' => 'Big campaign']);
$this->callAPISuccess('Contribution', 'create', ['campaign_id' => 'Big_campaign', 'id' => $this->contributionIDs[0]]);
$campaign = $this->callAPISuccess('Campaign', 'create', ['title' => 'Big campaign and kinda long too']);
$this->callAPISuccess('Contribution', 'create', ['campaign_id' => 'Big_campaign_and_kinda_long_too', 'id' => $this->contributionIDs[0]]);
$selectedFields = [
['contact_type' => 'Individual', 'name' => 'gender_id'],
['contact_type' => 'Contribution', 'name' => 'contribution_campaign_title'],
['contact_type' => 'Contribution', 'name' => 'contribution_campaign_id'],
];
list($tableName, $sqlColumns) = CRM_Export_BAO_Export::exportComponents(
TRUE,
$this->contactIDs[1],
[],
NULL,
$selectedFields,
NULL,
CRM_Export_Form_Select::CONTRIBUTE_EXPORT,
"contact_a.id IN (" . implode(",", $this->contactIDs) . ")",
NULL,
FALSE,
FALSE,
[
'suppress_csv_for_testing' => TRUE,
]
);
$this->assertEquals('Big campaign,', CRM_Core_DAO::singleValueQuery("SELECT GROUP_CONCAT(contribution_campaign_title) FROM {$tableName}"));
$this->doExportTest([
'ids' => [$this->contactIDs[1]],
'exportMode' => CRM_Export_Form_Select::CONTRIBUTE_EXPORT,
'fields' => $selectedFields,
'componentClause' => "contact_a.id IN (" . implode(",", $this->contactIDs) . ")",
]);
$row = $this->csv->fetchOne();
$this->assertEquals('Big campaign and kinda long too', $row['Campaign Title']);
$this->assertEquals($campaign['id'], $row['Campaign ID']);
}

/**
Expand Down Expand Up @@ -611,6 +608,7 @@ public function testExportRelationships() {
* @param bool $includeHouseHold
*
* @throws CRM_Core_Exception
* @throws \League\Csv\Exception
*/
public function testExportRelationshipsMergeToHousehold($includeHouseHold) {
list($householdID, $houseHoldTypeID) = $this->setUpHousehold();
Expand All @@ -625,45 +623,17 @@ public function testExportRelationshipsMergeToHousehold($includeHouseHold) {
['contact_type' => 'Individual', 'name' => 'state_province', 'location_type_id' => ''],
['contact_type' => 'Individual', 'name' => 'contact_source', 'location_type_id' => ''],
];
list($tableName, $sqlColumns, $headerRows) = CRM_Export_BAO_Export::exportComponents(
FALSE,
$this->contactIDs,
[],
NULL,
$selectedFields,
NULL,
CRM_Export_Form_Select::CONTACT_EXPORT,
"contact_a.id IN (" . implode(",", $this->contactIDs) . ")",
NULL,
FALSE,
TRUE,
[
'suppress_csv_for_testing' => TRUE,
]
);
$dao = CRM_Core_DAO::executeQuery("SELECT * FROM {$tableName}");
while ($dao->fetch()) {
$this->assertEquals(1, $dao->N);
$this->assertEquals('Portland', $dao->city);
$this->assertEquals('ME', $dao->state_province);
$this->assertEquals($householdID, $dao->civicrm_primary_id);
$this->assertEquals($householdID, $dao->civicrm_primary_id);
$this->assertEquals('household sauce', $dao->contact_source);
}

$this->assertEquals([
0 => 'City',
1 => 'State',
2 => 'Contact Source',
3 => 'Household ID',
], $headerRows);
$this->assertEquals(
[
'city' => 'city varchar(64)',
'state_province' => 'state_province varchar(64)',
'civicrm_primary_id' => 'civicrm_primary_id varchar(16)',
'contact_source' => 'contact_source varchar(255)',
], $sqlColumns);
$this->doExportTest([
'ids' => $this->contactIDs,
'fields' => $selectedFields,
'mergeSameHousehold' => TRUE,
]);
$row = $this->csv->fetchOne();
$this->assertEquals(1, count($this->csv));
$this->assertEquals('Portland', $row['City']);
$this->assertEquals('ME', $row['State']);
$this->assertEquals($householdID, $row['Household ID']);
$this->assertEquals('household sauce', $row['Contact Source']);
}

/**
Expand Down Expand Up @@ -1902,7 +1872,7 @@ public function getAllSpecifiableReturnFields() {
*/
public function getAllSpecifiableParticipantReturnColumns() {
return [
'participant_campaign_id' => 'participant_campaign_id varchar(128)',
'participant_campaign_id' => 'participant_campaign_id varchar(16)',
'participant_contact_id' => 'participant_contact_id varchar(16)',
'componentpaymentfield_contribution_status' => 'componentpaymentfield_contribution_status text',
'currency' => 'currency varchar(3)',
Expand Down Expand Up @@ -2608,7 +2578,7 @@ protected function getActivitySqlColumns() {
'source_contact' => 'source_contact varchar(255)',
'source_record_id' => 'source_record_id varchar(255)',
'activity_is_test' => 'activity_is_test varchar(16)',
'activity_campaign_id' => 'activity_campaign_id varchar(128)',
'activity_campaign_id' => 'activity_campaign_id varchar(16)',
'result' => 'result text',
'activity_engagement_level' => 'activity_engagement_level varchar(16)',
'parent_id' => 'parent_id varchar(255)',
Expand Down Expand Up @@ -2642,7 +2612,7 @@ protected function getParticipantSqlColumns() {
'participant_discount_name' => 'participant_discount_name varchar(16)',
'participant_fee_currency' => 'participant_fee_currency varchar(3)',
'participant_registered_by_id' => 'participant_registered_by_id varchar(16)',
'participant_campaign_id' => 'participant_campaign_id varchar(128)',
'participant_campaign_id' => 'participant_campaign_id varchar(16)',
];
}

Expand Down Expand Up @@ -2760,7 +2730,7 @@ public function getContributionSqlColumns() {
'contribution_note' => 'contribution_note text',
'contribution_batch' => 'contribution_batch text',
'contribution_campaign_title' => 'contribution_campaign_title varchar(255)',
'contribution_campaign_id' => 'contribution_campaign_id varchar(128)',
'contribution_campaign_id' => 'contribution_campaign_id varchar(16)',
'contribution_soft_credit_name' => 'contribution_soft_credit_name varchar(255)',
'contribution_soft_credit_amount' => 'contribution_soft_credit_amount varchar(255)',
'contribution_soft_credit_type' => 'contribution_soft_credit_type varchar(255)',
Expand Down Expand Up @@ -2790,7 +2760,7 @@ public function getPledgeSqlColumns() {
'pledge_frequency_interval' => 'pledge_frequency_interval varchar(255)',
'pledge_frequency_unit' => 'pledge_frequency_unit varchar(255)',
'pledge_currency' => 'pledge_currency text',
'pledge_campaign_id' => 'pledge_campaign_id varchar(128)',
'pledge_campaign_id' => 'pledge_campaign_id varchar(16)',
'pledge_balance_amount' => 'pledge_balance_amount text',
'pledge_payment_id' => 'pledge_payment_id varchar(16)',
'pledge_payment_scheduled_amount' => 'pledge_payment_scheduled_amount varchar(32)',
Expand Down Expand Up @@ -2822,7 +2792,7 @@ public function getMembershipSqlColumns() {
'owner_membership_id' => 'owner_membership_id varchar(16)',
'max_related' => 'max_related text',
'membership_recur_id' => 'membership_recur_id varchar(255)',
'member_campaign_id' => 'member_campaign_id varchar(128)',
'member_campaign_id' => 'member_campaign_id varchar(16)',
'member_is_override' => 'member_is_override text',
'member_auto_renew' => 'member_auto_renew text',
];
Expand Down