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

Fix test to be more valid #15743

Merged
merged 1 commit into from
Nov 6, 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
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