From: Coleman Watts Date: Thu, 13 Jun 2013 18:35:35 +0000 (-0700) Subject: Fix api_v3_LocBlockTest X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=70c906cfed0657aad2b8cfad3dafe63f10d8ee4d;p=civicrm-core.git Fix api_v3_LocBlockTest --- diff --git a/api/v3/utils.php b/api/v3/utils.php index 65324f3a7b..9492dc8e3e 100644 --- a/api/v3/utils.php +++ b/api/v3/utils.php @@ -1456,7 +1456,7 @@ function _civicrm_api3_validate_integer(&$params, &$fieldName, &$fieldInfo, $ent // After swapping options, ensure we have an integer(s) foreach ((array) ($params[$fieldName]) as $value) { - if (!is_numeric($value) || (int) $value != $value) { + if (!is_numeric($value) && $value !== 'null') { throw new API_Exception("$fieldName is not a valid integer", 2001, array('error_field' => $fieldName, "type" => "integer")); } } diff --git a/tests/phpunit/api/v3/LocBlockTest.php b/tests/phpunit/api/v3/LocBlockTest.php index 8464feb03a..3d22322027 100644 --- a/tests/phpunit/api/v3/LocBlockTest.php +++ b/tests/phpunit/api/v3/LocBlockTest.php @@ -39,31 +39,27 @@ class api_v3_LocBlockTest extends CiviUnitTestCase { } public function testCreateLocBlock() { - $email = civicrm_api('email', 'create', array( - 'version' => $this->_apiversion, + $email = $this->callAPISuccess('email', 'create', array( 'contact_id' => 'null', 'location_type_id' => 1, 'email' => 'test@loc.block', )); - $phone = civicrm_api('phone', 'create', array( - 'version' => $this->_apiversion, + $phone = $this->callAPISuccess('phone', 'create', array( 'contact_id' => 'null', 'location_type_id' => 1, 'phone' => '1234567', )); - $address = civicrm_api('address', 'create', array( - 'version' => $this->_apiversion, + $address = $this->callAPISuccess('address', 'create', array( 'contact_id' => 'null', 'location_type_id' => 1, 'street_address' => '1234567', )); $params = array( - 'version' => $this->_apiversion, 'address_id' => $address['id'], 'phone_id' => $phone['id'], 'email_id' => $email['id'], ); - $result = civicrm_api($this->_entity, 'create', $params); + $result = $this->callAPISuccess($this->_entity, 'create', $params); $id = $result['id']; $this->documentMe($params, $result, __FUNCTION__, __FILE__); $this->assertAPISuccess($result, 'In line ' . __LINE__); @@ -74,7 +70,6 @@ class api_v3_LocBlockTest extends CiviUnitTestCase { public function testCreateLocBlockEntities() { $params = array( - 'version' => $this->_apiversion, 'email' => array( 'location_type_id' => 1, 'email' => 'test2@loc.block', @@ -92,10 +87,8 @@ class api_v3_LocBlockTest extends CiviUnitTestCase { 'street_address' => '987654321', ), ); - $result = civicrm_api($this->_entity, 'create', $params); + $result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__, 'Create entities and location block in 1 api call', NULL, 'createEntities'); $id = $result['id']; - $this->documentMe($params, $result, __FUNCTION__, __FILE__, 'Create entities and location block in 1 api call', NULL, 'createEntities'); - $this->assertAPISuccess($result, 'In line ' . __LINE__); $this->assertEquals(1, $result['count'], 'In line ' . __LINE__); // Now check our results using the return param 'all' @@ -104,6 +97,7 @@ class api_v3_LocBlockTest extends CiviUnitTestCase { 'id' => $id, 'return' => 'all' ); + // Can't use callAPISuccess with getsingle $result = civicrm_api($this->_entity, 'getsingle', $getParams); $this->documentMe($getParams, $result, __FUNCTION__, __FILE__, 'Get entities and location block in 1 api call', NULL, 'get'); $this->assertNotNull($result['email_id'], 'In line ' . __LINE__); @@ -114,11 +108,7 @@ class api_v3_LocBlockTest extends CiviUnitTestCase { $this->assertEquals($params['phone_2']['phone'], $result['phone_2']['phone'], 'In line ' . __LINE__); $this->assertEquals($params['address']['street_address'], $result['address']['street_address'], 'In line ' . __LINE__); // Delete block - $result = civicrm_api($this->_entity, 'delete', array( - 'version' => $this->_apiversion, - 'id' => $id, - )); - $this->assertAPISuccess($result, 'In line ' . __LINE__); + $result = $this->callAPISuccess($this->_entity, 'delete', array('id' => $id)); } public static function setUpBeforeClass() {