From: Coleman Watts Date: Fri, 7 Jun 2013 21:47:34 +0000 (-0700) Subject: More fixes for API option matching and validation CRM-12464 X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=283f988c7d9f8f0fda0dfe40b926566e02bea3fe;p=civicrm-core.git More fixes for API option matching and validation CRM-12464 ---------------------------------------- * CRM-12464: Add PseudoConstants to Schema Metadata http://issues.civicrm.org/jira/browse/CRM-12464 --- diff --git a/api/v3/utils.php b/api/v3/utils.php index fefb043a4a..54f0d378ec 100644 --- a/api/v3/utils.php +++ b/api/v3/utils.php @@ -1452,9 +1452,11 @@ function _civicrm_api3_validate_integer(&$params, &$fieldName, &$fieldInfo, $ent _civicrm_api3_api_match_pseudoconstant($params, $entity, $fieldName, $fieldInfo); } - // After swapping options, ensure we have an integer - if (!is_numeric($params[$fieldName]) || (int) $params[$fieldName] != $params[$fieldName]) { - throw new API_Exception("$fieldname is not a valid integer", 2001, array('error_field' => $fieldname,"type" => "integer")); + // After swapping options, ensure we have an integer(s) + foreach ((array) ($params[$fieldName]) as $value) { + if (!is_numeric($value) || (int) $value != $value) { + throw new API_Exception("$fieldName is not a valid integer", 2001, array('error_field' => $fieldName, "type" => "integer")); + } } // Check our field length @@ -1573,7 +1575,7 @@ function _civicrm_api3_api_match_pseudoconstant_value(&$value, $options, $fieldN $options = array_map("strtolower", $options); $value = array_search($value, $options); if ($value === FALSE) { - throw new Exception($errorMsg); + throw new API_Exception($errorMsg, 2001, array('error_field' => $fieldName)); } } diff --git a/tests/phpunit/api/v3/ActivityTest.php b/tests/phpunit/api/v3/ActivityTest.php index e8b26cbe80..2648ed8250 100644 --- a/tests/phpunit/api/v3/ActivityTest.php +++ b/tests/phpunit/api/v3/ActivityTest.php @@ -310,7 +310,8 @@ class api_v3_ActivityTest extends CiviUnitTestCase { $result = civicrm_api('activity', 'create', $params); $this->assertEquals($result['is_error'], 1, "In line " . __LINE__); $this->assertEquals("'44' is not a valid option for field priority_id", $result['error_message']); - $this->assertEquals('priority_id',$result['error_field']); + $this->assertEquals(2001, $result['error_code']); + $this->assertEquals('priority_id', $result['error_field']); } function testActivityCreateWithValidStringPriority() { @@ -1094,7 +1095,6 @@ class api_v3_ActivityTest extends CiviUnitTestCase { $params['target_contact_id'] = array($contact2 => $contact2); $result = civicrm_api('Activity', 'Create', $params); - $result = civicrm_api('activity', 'create', $params); $activityId = $result['id']; $this->assertAPISuccess($result); $getParams = array(