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';
85 * Get Contribution and Invoice ID.
87 * @param $contributionStatus
91 private function getPageContribution($contributionStatus, $isTest = FALSE) {
92 $individualId = $this->individualCreate();
93 $invoiceId = rand(100000, 999999);
95 $contributionId = $this->contributionCreate([
96 'contact_id' => $individualId,
97 'invoice_id' => $invoiceId,
98 'contribution_status_id' => $contributionStatus,
99 'is_test' => ($isTest) ?
1 : 0,
103 'contribution_id' => $contributionId,
104 'invoice_id' => $invoiceId,
109 * Get CRM_Contribute_Form_Contribution_ThankYou Form
111 * @return CRM_Contribute_Form_Contribution_ThankYou
113 private function getThankYouForm() {
114 $form = new CRM_Contribute_Form_Contribution_ThankYou();
115 $_SERVER['REQUEST_METHOD'] = 'GET';
116 $form->controller
= new CRM_Contribute_Controller_Contribution();