From a1a013006f54b12cdafaeb10b82ad133edcc456e Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 11 Mar 2019 13:21:01 +1300 Subject: [PATCH] Add unit test on validate --- api/v3/ContributionPage.php | 2 ++ tests/phpunit/api/v3/ContributionPageTest.php | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/api/v3/ContributionPage.php b/api/v3/ContributionPage.php index 1a1e822b6e..9ffbd59edb 100644 --- a/api/v3/ContributionPage.php +++ b/api/v3/ContributionPage.php @@ -117,6 +117,7 @@ function civicrm_api3_contribution_page_validate($params) { // If we are calling this as a result of a POST action (e.g validating a form submission before first getting payment // authorization from a payment processor like Paypal checkout) the lack of a qfKey will not result in a valid // one being generated so we generate one first. + $originalRequest = $_REQUEST; $qfKey = CRM_Utils_Array::value('qfKey', $_REQUEST); if (!$qfKey) { $_REQUEST['qfKey'] = CRM_Core_Key::get('CRM_Core_Controller', TRUE); @@ -129,6 +130,7 @@ function civicrm_api3_contribution_page_validate($params) { if ($errors === TRUE) { $errors = []; } + $_REQUEST = $originalRequest; return civicrm_api3_create_success($errors, $params, 'ContributionPage', 'validate'); } diff --git a/tests/phpunit/api/v3/ContributionPageTest.php b/tests/phpunit/api/v3/ContributionPageTest.php index 6b96a7f5e6..e773ba39f0 100644 --- a/tests/phpunit/api/v3/ContributionPageTest.php +++ b/tests/phpunit/api/v3/ContributionPageTest.php @@ -1936,6 +1936,21 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase { $this->setUpContributionPage(); $errors = $this->callAPISuccess('ContributionPage', 'validate', array_merge($this->getBasicSubmitParams(), ['action' => 'submit']))['values']; $this->assertEmpty($errors); + unset($_SERVER['REQUEST_METHOD']); + } + + /** + * Test that an error is generated if required fields are not submitted. + */ + public function testValidateOutputOnMissingRecurFields() { + $this->params['is_recur_interval'] = 1; + $this->setUpContributionPage(TRUE); + $submitParams = array_merge($this->getBasicSubmitParams(), ['action' => 'submit']); + $submitParams['is_recur'] = 1; + $submitParams['frequency_interval'] = ''; + $submitParams['frequency_unit'] = ''; + $errors = $this->callAPISuccess('ContributionPage', 'validate', $submitParams)['values']; + $this->assertEquals('Please enter a number for how often you want to make this recurring contribution (EXAMPLE: Every 3 months).', $errors['frequency_interval']); } /** -- 2.25.1