From 43b4ba4388145531557d48de87c1dedb134a7970 Mon Sep 17 00:00:00 2001 From: Jitendra Purohit Date: Tue, 28 Nov 2017 08:17:45 +0530 Subject: [PATCH] Unit test for CRM-21436 --- .../CRM/Contribute/Form/ContributionTest.php | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/tests/phpunit/CRM/Contribute/Form/ContributionTest.php b/tests/phpunit/CRM/Contribute/Form/ContributionTest.php index 77547e14f5..ed9892f403 100644 --- a/tests/phpunit/CRM/Contribute/Form/ContributionTest.php +++ b/tests/phpunit/CRM/Contribute/Form/ContributionTest.php @@ -1324,6 +1324,55 @@ Price Field - Price Field 1 1 $ 100.00 $ 100.00 $this->assertEquals(CRM_Utils_Array::value('pan_truncation', $financialTrxn), 4567); } + /** + * Check payment processor is correctly assigned for a contribution page. + */ + public function testContributionBasePreProcess() { + //Create contribution page with only pay later enabled. + $params = array( + 'title' => "Test Contribution Page", + 'financial_type_id' => 1, + 'currency' => 'NZD', + 'goal_amount' => 100, + 'is_pay_later' => 1, + 'is_monetary' => TRUE, + 'is_active' => TRUE, + 'is_email_receipt' => TRUE, + 'receipt_from_email' => 'yourconscience@donate.com', + 'receipt_from_name' => 'Ego Freud', + ); + + $page1 = $this->callAPISuccess("contribution_page", 'create', $params); + + //Execute CRM_Contribute_Form_ContributionBase preProcess + //and check the assignment of payment processors + $form = new CRM_Contribute_Form_ContributionBase(); + $form->controller = new CRM_Core_Controller(); + $form->set('id', $page1['id']); + $_REQUEST['id'] = $page1['id']; + + $form->preProcess(); + $this->assertEquals($form->_paymentProcessor['name'], 'pay_later'); + + //Disable all the payment processor for the contribution page. + $params['is_pay_later'] = 0; + $page2 = $this->callAPISuccess("contribution_page", 'create', $params); + + //Assert an exception is thrown on loading the contribution page. + $form = new CRM_Contribute_Form_ContributionBase(); + $form->controller = new CRM_Core_Controller(); + $_REQUEST['id'] = $page2['id']; + $form->set('id', $page2['id']); + try { + $form->preProcess(); + } + catch (CRM_Core_Exception $e) { + $this->assertContains("A payment processor configured for this page might be disabled (contact the site administrator for assistance).", $e->getMessage()); + return; + } + $this->fail('Exception was expected'); + } + /** * function to test card_type and pan truncation. */ -- 2.25.1