diff --git a/api/v3/examples/LocBlockCreateEntities.php b/api/v3/examples/LocBlock/createEntities.php similarity index 92% rename from api/v3/examples/LocBlockCreateEntities.php rename to api/v3/examples/LocBlock/createEntities.php index dad0145a108a589d8d808557c014b12c8fb014a8..a19667aa6b4fe25ee674ba2f5fbe30c063806cb8 100644 --- a/api/v3/examples/LocBlockCreateEntities.php +++ b/api/v3/examples/LocBlock/createEntities.php @@ -1,9 +1,9 @@ <?php /** - * Test Generated example of using loc_block createEntities API - * Create entities and location block in 1 api call * + * Test Generated example of using loc_block create API + * Create entities and locBlock in 1 api call * */ -function loc_block_createentities_example(){ +function loc_block_create_example(){ $params = array( 'email' => array( 'location_type_id' => 1, @@ -24,7 +24,7 @@ $params = array( ); try{ - $result = civicrm_api3('loc_block', 'createEntities', $params); + $result = civicrm_api3('loc_block', 'create', $params); } catch (CiviCRM_API3_Exception $e) { // handle error here @@ -40,7 +40,7 @@ return $result; /** * Function returns array of result expected from previous function */ -function loc_block_createentities_expectedresult(){ +function loc_block_create_expectedresult(){ $expectedResult = array( 'is_error' => 0, diff --git a/api/v3/examples/LocBlockGet.php b/api/v3/examples/LocBlock/getEntities.php similarity index 52% rename from api/v3/examples/LocBlockGet.php rename to api/v3/examples/LocBlock/getEntities.php index ec9c0375fcc029c7c2571342b6a7874209f666c5..9043e8c57a23ce92aea20741bd87a1b576d205c9 100644 --- a/api/v3/examples/LocBlockGet.php +++ b/api/v3/examples/LocBlock/getEntities.php @@ -29,43 +29,51 @@ return $result; function loc_block_get_expectedresult(){ $expectedResult = array( - 'id' => '3', - 'address_id' => '3', - 'email_id' => '4', - 'phone_id' => '3', - 'phone_2_id' => '4', - 'address' => array( - 'id' => '3', - 'location_type_id' => '1', - 'is_primary' => 0, - 'is_billing' => 0, - 'street_address' => '987654321', - 'manual_geo_code' => 0, - ), - 'email' => array( - 'id' => '4', - 'location_type_id' => '1', - 'email' => 'test2@loc.block', - 'is_primary' => 0, - 'is_billing' => 0, - 'on_hold' => 0, - 'is_bulkmail' => 0, - ), - 'phone' => array( - 'id' => '3', - 'location_type_id' => '1', - 'is_primary' => 0, - 'is_billing' => 0, - 'phone' => '987654321', - 'phone_numeric' => '987654321', - ), - 'phone_2' => array( - 'id' => '4', - 'location_type_id' => '1', - 'is_primary' => 0, - 'is_billing' => 0, - 'phone' => '456-7890', - 'phone_numeric' => '4567890', + 'is_error' => 0, + 'version' => 3, + 'count' => 1, + 'id' => 3, + 'values' => array( + '3' => array( + 'id' => '3', + 'address_id' => '3', + 'email_id' => '4', + 'phone_id' => '3', + 'phone_2_id' => '4', + 'address' => array( + 'id' => '3', + 'location_type_id' => '1', + 'is_primary' => 0, + 'is_billing' => 0, + 'street_address' => '987654321', + 'manual_geo_code' => 0, + ), + 'email' => array( + 'id' => '4', + 'location_type_id' => '1', + 'email' => 'test2@loc.block', + 'is_primary' => 0, + 'is_billing' => 0, + 'on_hold' => 0, + 'is_bulkmail' => 0, + ), + 'phone' => array( + 'id' => '3', + 'location_type_id' => '1', + 'is_primary' => 0, + 'is_billing' => 0, + 'phone' => '987654321', + 'phone_numeric' => '987654321', + ), + 'phone_2' => array( + 'id' => '4', + 'location_type_id' => '1', + 'is_primary' => 0, + 'is_billing' => 0, + 'phone' => '456-7890', + 'phone_numeric' => '4567890', + ), + ), ), ); diff --git a/api/v3/examples/LocBlockCreate.php b/api/v3/examples/LocBlock/simpleCreate.php similarity index 97% rename from api/v3/examples/LocBlockCreate.php rename to api/v3/examples/LocBlock/simpleCreate.php index 7f893f4d351ba5e333fa305937f1f531a8e3271b..a681afb6f66b67052da7818551c85487dce45772 100644 --- a/api/v3/examples/LocBlockCreate.php +++ b/api/v3/examples/LocBlock/simpleCreate.php @@ -1,7 +1,7 @@ <?php /** * Test Generated example of using loc_block create API - * * + * Create locBlock with existing entities * */ function loc_block_create_example(){ $params = array( diff --git a/tests/phpunit/CiviTest/CiviUnitTestCase.php b/tests/phpunit/CiviTest/CiviUnitTestCase.php index fbc5dd20460a77d1c50525685569d08e4c6621ae..6833161f310a714cc10212c956bf5aea3f5c23a9 100644 --- a/tests/phpunit/CiviTest/CiviUnitTestCase.php +++ b/tests/phpunit/CiviTest/CiviUnitTestCase.php @@ -796,6 +796,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { } return $result; } + /** * This function exists to wrap api functions * so we can ensure they succeed, generate and example & throw exceptions without litterering the test with checks @@ -805,6 +806,10 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase { * @param array $params * @param string $function - pass this in to create a generated example * @param string $file - pass this in to create a generated example + * @param string $description + * @param string|null $subfile + * @param string|null $actionName + * @return array|int */ function callAPIAndDocument($entity, $action, $params, $function, $file, $description = "", $subfile = NULL, $actionName = NULL){ $params['version'] = $this->_apiversion; diff --git a/tests/phpunit/api/v3/LocBlockTest.php b/tests/phpunit/api/v3/LocBlockTest.php index b44577123ceff9933a5fa3a62976ad16917b87c0..f33dc5212a221c36cbe6697e53f45778de316f25 100644 --- a/tests/phpunit/api/v3/LocBlockTest.php +++ b/tests/phpunit/api/v3/LocBlockTest.php @@ -58,7 +58,8 @@ class api_v3_LocBlockTest extends CiviUnitTestCase { 'phone_id' => $phone['id'], 'email_id' => $email['id'], ); - $result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__); + $description = 'Create locBlock with existing entities'; + $result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__, $description, 'simpleCreate'); $id = $result['id']; $this->assertEquals(1, $result['count'], 'In line ' . __LINE__); $this->assertNotNull($result['values'][$id]['id'], 'In line ' . __LINE__); @@ -84,16 +85,19 @@ class api_v3_LocBlockTest extends CiviUnitTestCase { 'street_address' => '987654321', ), ); - $result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__, 'Create entities and location block in 1 api call', NULL, 'createEntities'); + $description = "Create entities and locBlock in 1 api call"; + $result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__, $description, 'createEntities'); $id = $result['id']; $this->assertEquals(1, $result['count'], 'In line ' . __LINE__); // Now check our results using the return param 'all' - $getParams = array( 'id' => $id, - 'return' => 'all' + $getParams = array( + 'id' => $id, + 'return' => 'all', ); // Can't use callAPISuccess with getsingle - $result = $this->callAPIAndDocument($this->_entity, 'getsingle', $getParams, __FUNCTION__, __FILE__, 'Get entities and location block in 1 api call', NULL, 'get'); + $result = $this->callAPIAndDocument($this->_entity, 'get', $getParams, __FUNCTION__, __FILE__, 'Get entities and location block in 1 api call', 'getEntities', 'get'); + $result = array_pop($result['values']); $this->assertNotNull($result['email_id'], 'In line ' . __LINE__); $this->assertNotNull($result['phone_id'], 'In line ' . __LINE__); $this->assertNotNull($result['phone_2_id'], 'In line ' . __LINE__);