Skip to content

Commit

Permalink
Merge pull request #11334 from jitendrapurohit/CRM-21436-unittest
Browse files Browse the repository at this point in the history
Unit test for CRM-21436
  • Loading branch information
eileenmcnaughton authored Dec 1, 2017
2 parents 802fe9f + 43b4ba4 commit e872ab2
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions tests/phpunit/CRM/Contribute/Form/ContributionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1328,6 +1328,55 @@ public function testCardTypeAndPanTruncation() {
$this->assertEquals(CRM_Utils_Array::value('pan_truncation', $financialTrxn), 4567);
}

/**
* Check payment processor is correctly assigned for a contribution page.
*/
public function testContributionBasePreProcess() {
//Create contribution page with only pay later enabled.
$params = array(
'title' => "Test Contribution Page",
'financial_type_id' => 1,
'currency' => 'NZD',
'goal_amount' => 100,
'is_pay_later' => 1,
'is_monetary' => TRUE,
'is_active' => TRUE,
'is_email_receipt' => TRUE,
'receipt_from_email' => 'yourconscience@donate.com',
'receipt_from_name' => 'Ego Freud',
);

$page1 = $this->callAPISuccess("contribution_page", 'create', $params);

//Execute CRM_Contribute_Form_ContributionBase preProcess
//and check the assignment of payment processors
$form = new CRM_Contribute_Form_ContributionBase();
$form->controller = new CRM_Core_Controller();
$form->set('id', $page1['id']);
$_REQUEST['id'] = $page1['id'];

$form->preProcess();
$this->assertEquals($form->_paymentProcessor['name'], 'pay_later');

//Disable all the payment processor for the contribution page.
$params['is_pay_later'] = 0;
$page2 = $this->callAPISuccess("contribution_page", 'create', $params);

//Assert an exception is thrown on loading the contribution page.
$form = new CRM_Contribute_Form_ContributionBase();
$form->controller = new CRM_Core_Controller();
$_REQUEST['id'] = $page2['id'];
$form->set('id', $page2['id']);
try {
$form->preProcess();
}
catch (CRM_Core_Exception $e) {
$this->assertContains("A payment processor configured for this page might be disabled (contact the site administrator for assistance).", $e->getMessage());
return;
}
$this->fail('Exception was expected');
}

/**
* function to test card_type and pan truncation.
*/
Expand Down

0 comments on commit e872ab2

Please sign in to comment.