From eb98c900bd772a4d1a148fee15d01182d6791ca5 Mon Sep 17 00:00:00 2001 From: Alok Patel Date: Wed, 27 Feb 2019 19:16:31 +0530 Subject: [PATCH] CIVIEWAY-42: Unit test to verify the correct outcome message on ThankYou Page. --- .../Form/Contribution/ThankYouTest.php | 134 ++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 tests/phpunit/CRM/Contribute/Form/Contribution/ThankYouTest.php diff --git a/tests/phpunit/CRM/Contribute/Form/Contribution/ThankYouTest.php b/tests/phpunit/CRM/Contribute/Form/Contribution/ThankYouTest.php new file mode 100644 index 000000000000..efe98b0f3297 --- /dev/null +++ b/tests/phpunit/CRM/Contribute/Form/Contribution/ThankYouTest.php @@ -0,0 +1,134 @@ +quickCleanUpFinancialEntities(); + } + + /** + * Test that correct contribution status is fetched for both live and test contributions. + */ + public function testLiveAndTestContributionStatus() { + $paymentProcessorID = $this->paymentProcessorCreate(array('payment_processor_type_id' => 'Dummy')); + + $form = $this->getThankYouFormWithContribution($paymentProcessorID, FALSE, FALSE); + $form->buildQuickForm(); + $isPendingOutcome = $form->get_template_vars('isPendingOutcome'); + + $this->assertEquals(FALSE, $isPendingOutcome, 'Outcome should not be pending.'); + + $form = $this->getThankYouFormWithContribution($paymentProcessorID, TRUE, FALSE); + $form->buildQuickForm(); + $isPendingOutcome = $form->get_template_vars('isPendingOutcome'); + + $this->assertEquals(TRUE, $isPendingOutcome, 'Outcome should be pending.'); + + $form = $this->getThankYouFormWithContribution($paymentProcessorID, FALSE, TRUE); + $form->buildQuickForm(); + $isPendingOutcome = $form->get_template_vars('isPendingOutcome'); + + $this->assertEquals(FALSE, $isPendingOutcome, 'Outcome should not be pending.'); + + $form = $this->getThankYouFormWithContribution($paymentProcessorID, TRUE, TRUE); + $form->buildQuickForm(); + $isPendingOutcome = $form->get_template_vars('isPendingOutcome'); + + $this->assertEquals(TRUE, $isPendingOutcome, 'Outcome should be pending.'); + } + + /** + * Get CRM_Contribute_Form_Contribution_ThankYou form with attached contribution. + * + * @param $paymentProcessorID + * @param bool $withPendingContribution + * @param bool $isTestContribution + * @return CRM_Contribute_Form_Contribution_ThankYou + */ + private function getThankYouFormWithContribution($paymentProcessorID, $withPendingContribution = FALSE, $isTestContribution = FALSE) { + $pageContribution = $this->getPageContribution((($withPendingContribution) ? 2 : 1), $isTestContribution); + $form = $this->getThankYouForm(); + $form->_lineItem = array(); + + $form->_params['contributionID'] = $pageContribution['contribution_id']; + $form->_params['invoiceID'] = $pageContribution['invoice_id']; + $form->_params['payment_processor_id'] = $paymentProcessorID; + if ($isTestContribution) { + $form->_mode = 'test'; + } + + return $form; + } + + /** + * Get Contribution and Invoice ID. + * + * @param $contributionStatus + * @param bool $isTest + * @return array + */ + private function getPageContribution($contributionStatus, $isTest = FALSE) { + $individualId = $this->individualCreate(); + $invoiceId = rand(100000, 999999); + + $contributionId = $this->contributionCreate(array( + 'contact_id' => $individualId, + 'invoice_id' => $invoiceId, + 'contribution_status_id' => $contributionStatus, + 'is_test' => ($isTest) ? 1 : 0, + )); + + return array( + 'contribution_id' => $contributionId, + 'invoice_id' => $invoiceId, + ); + } + + /** + * Get CRM_Contribute_Form_Contribution_ThankYou Form + * + * @return CRM_Contribute_Form_Contribution_ThankYou + */ + private function getThankYouForm() { + $form = new CRM_Contribute_Form_Contribution_ThankYou(); + $_SERVER['REQUEST_METHOD'] = 'GET'; + $form->controller = new CRM_Contribute_Controller_Contribution(); + return $form; + } + +}