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(): void
{
25 $this->quickCleanUpFinancialEntities();
30 * Test that correct contribution status is fetched for both live and test contributions.
32 public function testLiveAndTestContributionStatus(): void
{
33 $paymentProcessorID = $this->paymentProcessorCreate(['payment_processor_type_id' => 'Dummy']);
35 $form = $this->getThankYouFormWithContribution($paymentProcessorID, FALSE, FALSE);
36 $form->buildQuickForm();
37 $isPendingOutcome = $form->get_template_vars('isPendingOutcome');
39 $this->assertEquals(FALSE, $isPendingOutcome, 'Outcome should not be pending.');
41 $form = $this->getThankYouFormWithContribution($paymentProcessorID, TRUE, FALSE);
42 $form->buildQuickForm();
43 $isPendingOutcome = $form->get_template_vars('isPendingOutcome');
45 $this->assertEquals(TRUE, $isPendingOutcome, 'Outcome should be pending.');
47 $form = $this->getThankYouFormWithContribution($paymentProcessorID, FALSE, TRUE);
48 $form->buildQuickForm();
49 $isPendingOutcome = $form->get_template_vars('isPendingOutcome');
51 $this->assertEquals(FALSE, $isPendingOutcome, 'Outcome should not be pending.');
53 $form = $this->getThankYouFormWithContribution($paymentProcessorID, TRUE, TRUE);
54 $form->buildQuickForm();
55 $isPendingOutcome = $form->get_template_vars('isPendingOutcome');
57 $this->assertEquals(TRUE, $isPendingOutcome, 'Outcome should be pending.');
61 * Get CRM_Contribute_Form_Contribution_ThankYou form with attached contribution.
63 * @param $paymentProcessorID
64 * @param bool $withPendingContribution
65 * @param bool $isTestContribution
66 * @return CRM_Contribute_Form_Contribution_ThankYou
68 private function getThankYouFormWithContribution($paymentProcessorID, $withPendingContribution = FALSE, $isTestContribution = FALSE) {
69 $pageContribution = $this->getPageContribution((($withPendingContribution) ?
2 : 1), $isTestContribution);
70 $form = $this->getThankYouForm();
71 $form->_lineItem
= [];
74 $form->_params
['contributionID'] = $pageContribution['contribution_id'];
75 $form->_params
['invoiceID'] = $pageContribution['invoice_id'];
76 $form->_params
['email-5'] = 'demo@example.com';
77 $form->_params
['payment_processor_id'] = $paymentProcessorID;
78 if ($isTestContribution) {
79 $form->_mode
= 'test';
82 'custom_pre_id' => NULL,
83 'custom_post_id' => NULL,
90 * Get Contribution and Invoice ID.
92 * @param $contributionStatus
96 private function getPageContribution($contributionStatus, $isTest = FALSE) {
97 $individualId = $this->individualCreate();
98 $invoiceId = rand(100000, 999999);
100 $contributionId = $this->contributionCreate([
101 'contact_id' => $individualId,
102 'invoice_id' => $invoiceId,
103 'contribution_status_id' => $contributionStatus,
104 'is_test' => ($isTest) ?
1 : 0,
108 'contribution_id' => $contributionId,
109 'invoice_id' => $invoiceId,
114 * Get CRM_Contribute_Form_Contribution_ThankYou Form
116 * @return CRM_Contribute_Form_Contribution_ThankYou
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();