Skip to content

Commit

Permalink
dev/core#3063 APIv3 - Add unit test for numeric option matching
Browse files Browse the repository at this point in the history
  • Loading branch information
colemanw committed Feb 9, 2022
1 parent c27d601 commit 88b8a48
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions tests/phpunit/api/v3/FinancialTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,48 @@ public function testAssociatedFinancialAccountGetsCreated($apiVersion) {
$this->assertEquals('INC', $result['account_type_code'], 'Financial account created is not an income account.');
}

public function testMatchFinancialTypeOptions() {
// Just a string name, should be simple to match on
$nonNumericOption = $this->callAPISuccess('FinancialType', 'create', [
'name' => 'StringName',
])['id'];
// A numeric name, but a number that won't match any existing id
$numericOptionUnique = $this->callAPISuccess('FinancialType', 'create', [
'name' => '999',
])['id'];
// Here's the kicker, a numeric name that matches an existing id!
$numericOptionMatchingExistingId = $this->callAPISuccess('FinancialType', 'create', [
'name' => $nonNumericOption,
])['id'];
$cid = $this->individualCreate();

// Create a contribution matching non-numeric name
$contributionWithNonNumericType = $this->callAPISuccess('Contribution', 'create', [
'financial_type_id' => 'StringName',
'total_amount' => 100,
'contact_id' => $cid,
'sequential' => TRUE,
]);
$this->assertEquals($nonNumericOption, $contributionWithNonNumericType['values'][0]['financial_type_id']);

// Create a contribution matching unique numeric name
$contributionWithUniqueNumericType = $this->callAPISuccess('Contribution', 'create', [
'financial_type_id' => '999',
'total_amount' => 100,
'contact_id' => $cid,
'sequential' => TRUE,
]);
$this->assertEquals($numericOptionUnique, $contributionWithUniqueNumericType['values'][0]['financial_type_id']);

// Create a contribution matching the id of the non-numeric option, which is ambiguously the name of another option
$contributionWithAmbiguousNumericType = $this->callAPISuccess('Contribution', 'create', [
'financial_type_id' => "$nonNumericOption",
'total_amount' => 100,
'contact_id' => $cid,
'sequential' => TRUE,
]);
// The id should have taken priority over matching by name
$this->assertEquals($nonNumericOption, $contributionWithAmbiguousNumericType['values'][0]['financial_type_id']);
}

}

0 comments on commit 88b8a48

Please sign in to comment.