Fix api_v3_LocBlockTest
authorColeman Watts <coleman@civicrm.org>
Thu, 13 Jun 2013 18:35:35 +0000 (11:35 -0700)
committerColeman Watts <coleman@civicrm.org>
Thu, 13 Jun 2013 18:35:35 +0000 (11:35 -0700)
api/v3/utils.php
tests/phpunit/api/v3/LocBlockTest.php

index 65324f3a7bbe5381b5ed8d0feb1bb6aa7e0ffbc2..9492dc8e3edf6d3caea304a7452a8a8f5abc5f9e 100644 (file)
@@ -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"));
       }
     }
index 8464feb03a9089cceef72cc949e8ac08b4fcb1f4..3d2232202763ac713ce358c1a04cba56fee39a1d 100644 (file)
@@ -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() {