Skip to content

Commit

Permalink
Fix test to be more valid
Browse files Browse the repository at this point in the history
I've added a check to run after tests & before tearDown to ensure that all payments have the
right entity_financial_trxn records.

This required fixing one ttest to be valid. It's not possible to create a contribution using the
back office for with status set to Partially Paid (it's not an option in the drop down, so
the test should create as Pending & then add a payment to get to partially paid
  • Loading branch information
eileenmcnaughton committed Nov 6, 2019
1 parent fe5aa2e commit 8ea34be
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
26 changes: 21 additions & 5 deletions tests/phpunit/CRM/Contribute/Form/ContributionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class CRM_Contribute_Form_ContributionTest extends CiviUnitTestCase {
protected $_individualId;
protected $_contribution;
protected $_financialTypeId = 1;
protected $_apiversion;
protected $_entity = 'Contribution';
protected $_params;
protected $_ids = [];
Expand Down Expand Up @@ -88,6 +87,9 @@ class CRM_Contribute_Form_ContributionTest extends CiviUnitTestCase {

/**
* Setup function.
*
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
public function setUp() {
$this->_apiversion = 3;
Expand Down Expand Up @@ -133,12 +135,23 @@ public function setUp() {

/**
* Clean up after each test.
*
* @throws \CRM_Core_Exception
*/
public function tearDown() {
$this->quickCleanUpFinancialEntities();
$this->quickCleanup(['civicrm_note', 'civicrm_uf_match', 'civicrm_address']);
}

/**
* CHeck that all tests that have created payments have created them with the right financial entities.
*
* @throws \CRM_Core_Exception
*/
protected function assertPostConditions() {
$this->validateAllPayments();
}

/**
* Test the submit function on the contribution page.
*
Expand Down Expand Up @@ -982,6 +995,9 @@ protected function getCreditCardParams() {

/**
* Test the submit function that completes the partially paid payment using Credit Card
*
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
public function testPartialPaymentWithCreditCard() {
// create a partially paid contribution by using back-office form
Expand All @@ -994,22 +1010,22 @@ public function testPartialPaymentWithCreditCard() {
'payment_instrument_id' => array_search('Check', $this->paymentInstruments),
'check_number' => substr(sha1(rand()), 0, 7),
'billing_city-5' => 'Vancouver',
'contribution_status_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Partially paid'),
'contribution_status_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Pending'),
], CRM_Core_Action::ADD
);

$contribution = $this->callAPISuccessGetSingle('Contribution', []);
$this->assertNotEmpty($contribution);
$this->callAPISuccess('Payment', 'create', ['contribution_id' => $contribution['id'], 'total_amount' => 10, 'payment_instrument_id' => 'Cash']);
$contribution = $this->callAPISuccessGetSingle('Contribution', ['id' => $contribution['id']]);
$this->assertEquals('Partially paid', $contribution['contribution_status']);
// pay additional amount by using Credit Card
$form = new CRM_Contribute_Form_AdditionalPayment();
$form->testSubmit([
'contribution_id' => $contribution['id'],
'contact_id' => $this->_individualId,
'total_amount' => 50,
'total_amount' => 40,
'currency' => 'USD',
'financial_type_id' => 1,
'contact_id' => $this->_individualId,
'payment_instrument_id' => array_search('Credit card', $this->paymentInstruments),
'payment_processor_id' => $this->paymentProcessorID,
'credit_card_exp_date' => ['M' => 5, 'Y' => 2025],
Expand Down
3 changes: 3 additions & 0 deletions tests/phpunit/api/v3/ContributionPageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,9 @@ public function testSubmitMembershipBlockTwoTypesIsSeparatePayment() {
* Test submit with a membership block in place.
*
* We are expecting a separate payment for the membership vs the contribution.
*
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
public function testSubmitMembershipBlockIsSeparatePaymentPaymentProcessorNow() {
$mut = new CiviMailUtils($this, TRUE);
Expand Down

0 comments on commit 8ea34be

Please sign in to comment.