Skip to content

Commit

Permalink
[REF] Add in Unit test to demonstrate error when trying to import a c…
Browse files Browse the repository at this point in the history
…ampaign id int rather than name or label of the campaign
  • Loading branch information
seamuslee001 committed Oct 25, 2022
1 parent 68a22a1 commit 7ee3819
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,8 @@ public function validateData(): array {
*/
public function testImportFieldsNotRequiredWithTrxnID(): void {
$this->individualCreate(['email' => 'mum@example.com']);
$this->campaignCreate();
$this->callAPISuccess('System', 'flush', []);
$fieldMappings = [
['name' => 'first_name'],
['name' => ''],
Expand All @@ -539,6 +541,7 @@ public function testImportFieldsNotRequiredWithTrxnID(): void {
['name' => ''],
['name' => ''],
['name' => 'trxn_id'],
['name' => 'contribution_campaign_id'],
];
// First we try to create without total_amount mapped.
// It will fail in create mode as total_amount is required for create.
Expand All @@ -558,7 +561,7 @@ public function testImportFieldsNotRequiredWithTrxnID(): void {
$this->importCSV('contributions.csv', $fieldMappings, ['onDuplicate' => CRM_Import_Parser::DUPLICATE_SKIP]);

$row = $this->getDataSource()->getRows()[0];
$this->assertEquals('IMPORTED', $row[9]);
$this->assertEquals('IMPORTED', $row[10]);
$contribution = Contribution::get()->addSelect('source', 'id')->execute()->first();
$this->assertEmpty($contribution['source']);

Expand All @@ -572,11 +575,13 @@ public function testImportFieldsNotRequiredWithTrxnID(): void {
['name' => ''],
['name' => 'contribution_source'],
['name' => 'trxn_id'],
['name' => 'contribution_campaign_id'],
];
$this->importCSV('contributions.csv', $fieldMappings, ['onDuplicate' => CRM_Import_Parser::DUPLICATE_UPDATE]);

$row = $this->getDataSource()->getRows()[0];
$this->assertEquals('IMPORTED', $row[9]);
var_dump($row);
$this->assertEquals('IMPORTED', $row[10]);
$contribution = Contribution::get()->addSelect('source', 'id')->execute()->first();
$this->assertEquals('Call him back', $contribution['source']);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
External Identifier,Total Amount,Receive Date,Financial Type,Soft Credit to,Source,Note,Transaction ID
bob,65,2008-09-20,Donation,mum@example.com,Word of mouth,Call him back,999
External Identifier,Total Amount,Receive Date,Financial Type,Soft Credit to,Source,Note,Transaction ID,Campaign ID
bob,65,2008-09-20,Donation,mum@example.com,Word of mouth,Call him back,999,1

0 comments on commit 7ee3819

Please sign in to comment.