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);
}
// Translate value into key
- $newValue = array_search($value, $options);
+ // Cast $value to string to avoid a bug in array_search
+ $newValue = array_search((string) $value, $options);
if ($newValue !== FALSE) {
$value = $newValue;
return;
$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);
+ }
+
}