3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
13 * Test CRM_Contribute_Form_Contribution_ThankYou
15 * @package CiviCRM_APIv3
16 * @subpackage API_Contribution
19 class CRM_Contribute_Form_Contribution_ThankYouTest
extends CiviUnitTestCase
{
24 public function tearDown() {
25 $this->quickCleanUpFinancialEntities();
29 * Test that correct contribution status is fetched for both live and test contributions.
31 public function testLiveAndTestContributionStatus() {
32 $paymentProcessorID = $this->paymentProcessorCreate(['payment_processor_type_id' => 'Dummy']);
34 $form = $this->getThankYouFormWithContribution($paymentProcessorID, FALSE, FALSE);
35 $form->buildQuickForm();
36 $isPendingOutcome = $form->get_template_vars('isPendingOutcome');
38 $this->assertEquals(FALSE, $isPendingOutcome, 'Outcome should not be pending.');
40 $form = $this->getThankYouFormWithContribution($paymentProcessorID, TRUE, FALSE);
41 $form->buildQuickForm();
42 $isPendingOutcome = $form->get_template_vars('isPendingOutcome');
44 $this->assertEquals(TRUE, $isPendingOutcome, 'Outcome should be pending.');
46 $form = $this->getThankYouFormWithContribution($paymentProcessorID, FALSE, TRUE);
47 $form->buildQuickForm();
48 $isPendingOutcome = $form->get_template_vars('isPendingOutcome');
50 $this->assertEquals(FALSE, $isPendingOutcome, 'Outcome should not be pending.');
52 $form = $this->getThankYouFormWithContribution($paymentProcessorID, TRUE, TRUE);
53 $form->buildQuickForm();
54 $isPendingOutcome = $form->get_template_vars('isPendingOutcome');
56 $this->assertEquals(TRUE, $isPendingOutcome, 'Outcome should be pending.');
60 * Get CRM_Contribute_Form_Contribution_ThankYou form with attached contribution.
62 * @param $paymentProcessorID
63 * @param bool $withPendingContribution
64 * @param bool $isTestContribution
65 * @return CRM_Contribute_Form_Contribution_ThankYou
67 private function getThankYouFormWithContribution($paymentProcessorID, $withPendingContribution = FALSE, $isTestContribution = FALSE) {
68 $pageContribution = $this->getPageContribution((($withPendingContribution) ?
2 : 1), $isTestContribution);
69 $form = $this->getThankYouForm();
70 $form->_lineItem
= [];
73 $form->_params
['contributionID'] = $pageContribution['contribution_id'];
74 $form->_params
['invoiceID'] = $pageContribution['invoice_id'];
75 $form->_params
['email-5'] = 'demo@example.com';
76 $form->_params
['payment_processor_id'] = $paymentProcessorID;
77 if ($isTestContribution) {
78 $form->_mode
= 'test';
81 'custom_pre_id' => NULL,
82 'custom_post_id' => NULL,
89 * Get Contribution and Invoice ID.
91 * @param $contributionStatus
95 private function getPageContribution($contributionStatus, $isTest = FALSE) {
96 $individualId = $this->individualCreate();
97 $invoiceId = rand(100000, 999999);
99 $contributionId = $this->contributionCreate([
100 'contact_id' => $individualId,
101 'invoice_id' => $invoiceId,
102 'contribution_status_id' => $contributionStatus,
103 'is_test' => ($isTest) ?
1 : 0,
107 'contribution_id' => $contributionId,
108 'invoice_id' => $invoiceId,
113 * Get CRM_Contribute_Form_Contribution_ThankYou Form
115 * @return CRM_Contribute_Form_Contribution_ThankYou
117 private function getThankYouForm() {
118 $form = new CRM_Contribute_Form_Contribution_ThankYou();
119 $_SERVER['REQUEST_METHOD'] = 'GET';
120 $form->controller
= new CRM_Contribute_Controller_Contribution();