3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
13 * Class api_v3_LocBlockTest
17 class api_v3_LocBlockTest
extends CiviUnitTestCase
{
19 protected $_apiversion = 3;
21 protected $_entity = 'loc_block';
26 public function setUp() {
28 $this->useTransaction(TRUE);
32 * Test creating location block.
34 public function testCreateLocBlock() {
35 $email = $this->callAPISuccess('email', 'create', [
36 'contact_id' => 'null',
37 'email' => 'test@loc.block',
39 $phone = $this->callAPISuccess('phone', 'create', [
40 'contact_id' => 'null',
41 'location_type_id' => 1,
44 $address = $this->callAPISuccess('address', 'create', [
45 'contact_id' => 'null',
46 'location_type_id' => 1,
47 'street_address' => '1234567',
50 'address_id' => $address['id'],
51 'phone_id' => $phone['id'],
52 'email_id' => $email['id'],
54 $description = 'Create locBlock with existing entities';
55 $result = $this->callAPIAndDocument($this->_entity
, 'create', $params, __FUNCTION__
, __FILE__
, $description);
57 $this->assertEquals(1, $result['count']);
58 $this->assertNotNull($result['values'][$id]['id']);
59 $this->getAndCheck($params, $id, $this->_entity
);
63 * Test creating location block entities.
65 public function testCreateLocBlockEntities() {
68 'location_type_id' => 1,
69 'email' => 'test2@loc.block',
72 'location_type_id' => 1,
73 'phone' => '987654321',
76 'location_type_id' => 1,
77 'phone' => '456-7890',
80 'location_type_id' => 1,
81 'street_address' => '987654321',
84 $description = "Create entities and locBlock in 1 api call.";
85 $result = $this->callAPIAndDocument($this->_entity
, 'create', $params, __FUNCTION__
, __FILE__
, $description, 'CreateEntities');
87 $this->assertEquals(1, $result['count']);
89 // Now check our results using the return param 'all'.
94 // Can't use callAPISuccess with getsingle.
95 $result = $this->callAPIAndDocument($this->_entity
, 'get', $getParams, __FUNCTION__
, __FILE__
, 'Get entities and location block in 1 api call');
96 $result = array_pop($result['values']);
97 $this->assertNotNull($result['email_id']);
98 $this->assertNotNull($result['phone_id']);
99 $this->assertNotNull($result['phone_2_id']);
100 $this->assertNotNull($result['address_id']);
101 $this->assertEquals($params['email']['email'], $result['email']['email']);
102 $this->assertEquals($params['phone_2']['phone'], $result['phone_2']['phone']);
103 $this->assertEquals($params['address']['street_address'], $result['address']['street_address']);
105 $this->callAPISuccess($this->_entity
, 'delete', ['id' => $id]);