3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
29 * Test CRM_Contribute_Form_Contribution_ThankYou
31 * @package CiviCRM_APIv3
32 * @subpackage API_Contribution
35 class CRM_Contribute_Form_Contribution_ThankYouTest
extends CiviUnitTestCase
{
40 public function tearDown() {
41 $this->quickCleanUpFinancialEntities();
45 * Test that correct contribution status is fetched for both live and test contributions.
47 public function testLiveAndTestContributionStatus() {
48 $paymentProcessorID = $this->paymentProcessorCreate(['payment_processor_type_id' => 'Dummy']);
50 $form = $this->getThankYouFormWithContribution($paymentProcessorID, FALSE, FALSE);
51 $form->buildQuickForm();
52 $isPendingOutcome = $form->get_template_vars('isPendingOutcome');
54 $this->assertEquals(FALSE, $isPendingOutcome, 'Outcome should not be pending.');
56 $form = $this->getThankYouFormWithContribution($paymentProcessorID, TRUE, FALSE);
57 $form->buildQuickForm();
58 $isPendingOutcome = $form->get_template_vars('isPendingOutcome');
60 $this->assertEquals(TRUE, $isPendingOutcome, 'Outcome should be pending.');
62 $form = $this->getThankYouFormWithContribution($paymentProcessorID, FALSE, TRUE);
63 $form->buildQuickForm();
64 $isPendingOutcome = $form->get_template_vars('isPendingOutcome');
66 $this->assertEquals(FALSE, $isPendingOutcome, 'Outcome should not be pending.');
68 $form = $this->getThankYouFormWithContribution($paymentProcessorID, TRUE, TRUE);
69 $form->buildQuickForm();
70 $isPendingOutcome = $form->get_template_vars('isPendingOutcome');
72 $this->assertEquals(TRUE, $isPendingOutcome, 'Outcome should be pending.');
76 * Get CRM_Contribute_Form_Contribution_ThankYou form with attached contribution.
78 * @param $paymentProcessorID
79 * @param bool $withPendingContribution
80 * @param bool $isTestContribution
81 * @return CRM_Contribute_Form_Contribution_ThankYou
83 private function getThankYouFormWithContribution($paymentProcessorID, $withPendingContribution = FALSE, $isTestContribution = FALSE) {
84 $pageContribution = $this->getPageContribution((($withPendingContribution) ?
2 : 1), $isTestContribution);
85 $form = $this->getThankYouForm();
86 $form->_lineItem
= [];
89 $form->_params
['contributionID'] = $pageContribution['contribution_id'];
90 $form->_params
['invoiceID'] = $pageContribution['invoice_id'];
91 $form->_params
['email-5'] = 'demo@example.com';
92 $form->_params
['payment_processor_id'] = $paymentProcessorID;
93 if ($isTestContribution) {
94 $form->_mode
= 'test';
101 * Get Contribution and Invoice ID.
103 * @param $contributionStatus
104 * @param bool $isTest
107 private function getPageContribution($contributionStatus, $isTest = FALSE) {
108 $individualId = $this->individualCreate();
109 $invoiceId = rand(100000, 999999);
111 $contributionId = $this->contributionCreate([
112 'contact_id' => $individualId,
113 'invoice_id' => $invoiceId,
114 'contribution_status_id' => $contributionStatus,
115 'is_test' => ($isTest) ?
1 : 0,
119 'contribution_id' => $contributionId,
120 'invoice_id' => $invoiceId,
125 * Get CRM_Contribute_Form_Contribution_ThankYou Form
127 * @return CRM_Contribute_Form_Contribution_ThankYou
129 private function getThankYouForm() {
130 $form = new CRM_Contribute_Form_Contribution_ThankYou();
131 $_SERVER['REQUEST_METHOD'] = 'GET';
132 $form->controller
= new CRM_Contribute_Controller_Contribution();