Skip to content

Commit

Permalink
CRM-19543 - Fix integer 0 matching for api pseudoconstants
Browse files Browse the repository at this point in the history
  • Loading branch information
colemanw committed Oct 25, 2016
1 parent 6a47b6a commit 71d5a44
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
4 changes: 2 additions & 2 deletions api/v3/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -2172,7 +2172,7 @@ function _civicrm_api3_validate_integer(&$params, &$fieldName, &$fieldInfo, $ent
return;
}

if (!empty($fieldValue)) {
if (!empty($fieldValue) || $fieldValue === '0' || $fieldValue === 0) {
// if value = 'user_contact_id' (or similar), replace value with contact id
if (!is_numeric($fieldValue) && is_scalar($fieldValue)) {
$realContactId = _civicrm_api3_resolve_contactID($fieldValue);
Expand Down Expand Up @@ -2390,7 +2390,7 @@ function _civicrm_api3_api_match_pseudoconstant_value(&$value, $options, $fieldN
}

// Translate value into key
$newValue = array_search($value, $options);
$newValue = array_search((string) $value, $options);
if ($newValue !== FALSE) {
$value = $newValue;
return;
Expand Down
23 changes: 23 additions & 0 deletions tests/phpunit/api/v3/GrantTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,27 @@ public function testDeleteGrant() {
$this->assertEquals(0, $checkDeleted['count']);
}

/**
* Test Grant status with `0` value.
*/
public function testGrantWithZeroStatus() {
$params = array(
'action' => 'create',
'grant_type_id' => "Emergency",
'amount_total' => 100,
'contact_id' => "1",
'status_id' => 0,
'id' => 1,
);
$validation = $this->callAPISuccess('Grant', 'validate', $params);

$expectedOut = array(
'status_id' => array(
'message' => "'0' is not a valid option for field status_id",
'code' => "incorrect_value",
),
);
$this->assertEquals($validation['values'][0], $expectedOut);
}

}

0 comments on commit 71d5a44

Please sign in to comment.