Commit | Line | Data |
---|---|---|
eb98c900 AP |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
7d61e75f | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
eb98c900 | 5 | | | |
7d61e75f TO |
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 | | |
eb98c900 AP |
9 | +--------------------------------------------------------------------+ |
10 | */ | |
11 | ||
12 | /** | |
13 | * Test CRM_Contribute_Form_Contribution_ThankYou | |
14 | * | |
15 | * @package CiviCRM_APIv3 | |
16 | * @subpackage API_Contribution | |
17 | * @group headless | |
18 | */ | |
19 | class CRM_Contribute_Form_Contribution_ThankYouTest extends CiviUnitTestCase { | |
20 | ||
21 | /** | |
22 | * Clean up DB. | |
23 | */ | |
594a9328 | 24 | public function tearDown(): void { |
eb98c900 | 25 | $this->quickCleanUpFinancialEntities(); |
d706c149 | 26 | parent::tearDown(); |
eb98c900 AP |
27 | } |
28 | ||
29 | /** | |
30 | * Test that correct contribution status is fetched for both live and test contributions. | |
31 | */ | |
e50378d4 | 32 | public function testLiveAndTestContributionStatus(): void { |
9099cab3 | 33 | $paymentProcessorID = $this->paymentProcessorCreate(['payment_processor_type_id' => 'Dummy']); |
eb98c900 AP |
34 | |
35 | $form = $this->getThankYouFormWithContribution($paymentProcessorID, FALSE, FALSE); | |
36 | $form->buildQuickForm(); | |
37 | $isPendingOutcome = $form->get_template_vars('isPendingOutcome'); | |
38 | ||
39 | $this->assertEquals(FALSE, $isPendingOutcome, 'Outcome should not be pending.'); | |
40 | ||
41 | $form = $this->getThankYouFormWithContribution($paymentProcessorID, TRUE, FALSE); | |
42 | $form->buildQuickForm(); | |
43 | $isPendingOutcome = $form->get_template_vars('isPendingOutcome'); | |
44 | ||
45 | $this->assertEquals(TRUE, $isPendingOutcome, 'Outcome should be pending.'); | |
46 | ||
47 | $form = $this->getThankYouFormWithContribution($paymentProcessorID, FALSE, TRUE); | |
48 | $form->buildQuickForm(); | |
49 | $isPendingOutcome = $form->get_template_vars('isPendingOutcome'); | |
50 | ||
51 | $this->assertEquals(FALSE, $isPendingOutcome, 'Outcome should not be pending.'); | |
52 | ||
53 | $form = $this->getThankYouFormWithContribution($paymentProcessorID, TRUE, TRUE); | |
54 | $form->buildQuickForm(); | |
55 | $isPendingOutcome = $form->get_template_vars('isPendingOutcome'); | |
56 | ||
57 | $this->assertEquals(TRUE, $isPendingOutcome, 'Outcome should be pending.'); | |
58 | } | |
59 | ||
60 | /** | |
61 | * Get CRM_Contribute_Form_Contribution_ThankYou form with attached contribution. | |
62 | * | |
63 | * @param $paymentProcessorID | |
64 | * @param bool $withPendingContribution | |
65 | * @param bool $isTestContribution | |
66 | * @return CRM_Contribute_Form_Contribution_ThankYou | |
67 | */ | |
68 | private function getThankYouFormWithContribution($paymentProcessorID, $withPendingContribution = FALSE, $isTestContribution = FALSE) { | |
69 | $pageContribution = $this->getPageContribution((($withPendingContribution) ? 2 : 1), $isTestContribution); | |
70 | $form = $this->getThankYouForm(); | |
9099cab3 | 71 | $form->_lineItem = []; |
238ea0e4 | 72 | $form->_bltID = 5; |
eb98c900 AP |
73 | |
74 | $form->_params['contributionID'] = $pageContribution['contribution_id']; | |
75 | $form->_params['invoiceID'] = $pageContribution['invoice_id']; | |
238ea0e4 | 76 | $form->_params['email-5'] = 'demo@example.com'; |
eb98c900 AP |
77 | $form->_params['payment_processor_id'] = $paymentProcessorID; |
78 | if ($isTestContribution) { | |
79 | $form->_mode = 'test'; | |
80 | } | |
9f190348 SL |
81 | $form->_values = [ |
82 | 'custom_pre_id' => NULL, | |
83 | 'custom_post_id' => NULL, | |
84 | ]; | |
eb98c900 AP |
85 | |
86 | return $form; | |
87 | } | |
88 | ||
89 | /** | |
90 | * Get Contribution and Invoice ID. | |
91 | * | |
92 | * @param $contributionStatus | |
93 | * @param bool $isTest | |
94 | * @return array | |
95 | */ | |
96 | private function getPageContribution($contributionStatus, $isTest = FALSE) { | |
97 | $individualId = $this->individualCreate(); | |
98 | $invoiceId = rand(100000, 999999); | |
99 | ||
9099cab3 | 100 | $contributionId = $this->contributionCreate([ |
eb98c900 AP |
101 | 'contact_id' => $individualId, |
102 | 'invoice_id' => $invoiceId, | |
103 | 'contribution_status_id' => $contributionStatus, | |
104 | 'is_test' => ($isTest) ? 1 : 0, | |
9099cab3 | 105 | ]); |
eb98c900 | 106 | |
9099cab3 | 107 | return [ |
eb98c900 AP |
108 | 'contribution_id' => $contributionId, |
109 | 'invoice_id' => $invoiceId, | |
9099cab3 | 110 | ]; |
eb98c900 AP |
111 | } |
112 | ||
113 | /** | |
114 | * Get CRM_Contribute_Form_Contribution_ThankYou Form | |
115 | * | |
116 | * @return CRM_Contribute_Form_Contribution_ThankYou | |
117 | */ | |
118 | private function getThankYouForm() { | |
119 | $form = new CRM_Contribute_Form_Contribution_ThankYou(); | |
120 | $_SERVER['REQUEST_METHOD'] = 'GET'; | |
121 | $form->controller = new CRM_Contribute_Controller_Contribution(); | |
122 | return $form; | |
123 | } | |
124 | ||
125 | } |