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 * @throws \CRM_Core_Exception|\API_Exception
26 public function tearDown(): void
{
27 $this->quickCleanUpFinancialEntities();
32 * Test that correct contribution status is fetched for both live and test contributions.
34 public function testLiveAndTestContributionStatus() {
35 $paymentProcessorID = $this->paymentProcessorCreate(['payment_processor_type_id' => 'Dummy']);
37 $form = $this->getThankYouFormWithContribution($paymentProcessorID, FALSE, FALSE);
38 $form->buildQuickForm();
39 $isPendingOutcome = $form->get_template_vars('isPendingOutcome');
41 $this->assertEquals(FALSE, $isPendingOutcome, 'Outcome should not be pending.');
43 $form = $this->getThankYouFormWithContribution($paymentProcessorID, TRUE, FALSE);
44 $form->buildQuickForm();
45 $isPendingOutcome = $form->get_template_vars('isPendingOutcome');
47 $this->assertEquals(TRUE, $isPendingOutcome, 'Outcome should be pending.');
49 $form = $this->getThankYouFormWithContribution($paymentProcessorID, FALSE, TRUE);
50 $form->buildQuickForm();
51 $isPendingOutcome = $form->get_template_vars('isPendingOutcome');
53 $this->assertEquals(FALSE, $isPendingOutcome, 'Outcome should not be pending.');
55 $form = $this->getThankYouFormWithContribution($paymentProcessorID, TRUE, TRUE);
56 $form->buildQuickForm();
57 $isPendingOutcome = $form->get_template_vars('isPendingOutcome');
59 $this->assertEquals(TRUE, $isPendingOutcome, 'Outcome should be pending.');
63 * Get CRM_Contribute_Form_Contribution_ThankYou form with attached contribution.
65 * @param $paymentProcessorID
66 * @param bool $withPendingContribution
67 * @param bool $isTestContribution
68 * @return CRM_Contribute_Form_Contribution_ThankYou
70 private function getThankYouFormWithContribution($paymentProcessorID, $withPendingContribution = FALSE, $isTestContribution = FALSE) {
71 $pageContribution = $this->getPageContribution((($withPendingContribution) ?
2 : 1), $isTestContribution);
72 $form = $this->getThankYouForm();
73 $form->_lineItem
= [];
76 $form->_params
['contributionID'] = $pageContribution['contribution_id'];
77 $form->_params
['invoiceID'] = $pageContribution['invoice_id'];
78 $form->_params
['email-5'] = 'demo@example.com';
79 $form->_params
['payment_processor_id'] = $paymentProcessorID;
80 if ($isTestContribution) {
81 $form->_mode
= 'test';
84 'custom_pre_id' => NULL,
85 'custom_post_id' => NULL,
92 * Get Contribution and Invoice ID.
94 * @param $contributionStatus
98 private function getPageContribution($contributionStatus, $isTest = FALSE) {
99 $individualId = $this->individualCreate();
100 $invoiceId = rand(100000, 999999);
102 $contributionId = $this->contributionCreate([
103 'contact_id' => $individualId,
104 'invoice_id' => $invoiceId,
105 'contribution_status_id' => $contributionStatus,
106 'is_test' => ($isTest) ?
1 : 0,
110 'contribution_id' => $contributionId,
111 'invoice_id' => $invoiceId,
116 * Get CRM_Contribute_Form_Contribution_ThankYou Form
118 * @return CRM_Contribute_Form_Contribution_ThankYou
120 private function getThankYouForm() {
121 $form = new CRM_Contribute_Form_Contribution_ThankYou();
122 $_SERVER['REQUEST_METHOD'] = 'GET';
123 $form->controller
= new CRM_Contribute_Controller_Contribution();