Skip to content

Commit

Permalink
Add unit test on validate
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Mar 14, 2019
1 parent dbc654e commit a1a0130
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions api/v3/ContributionPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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');
}

Expand Down
15 changes: 15 additions & 0 deletions tests/phpunit/api/v3/ContributionPageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1936,6 +1936,21 @@ public function testValidatePost() {
$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']);
}

/**
Expand Down

0 comments on commit a1a0130

Please sign in to comment.