cdded66d50f7dfb4f6f024d4e31ee27eeeabff0a
[civicrm-core.git] / tests / phpunit / api / v3 / LocBlockTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
26 */
27
28 /**
29 * Class api_v3_LocBlockTest
30 */
31 class api_v3_LocBlockTest extends CiviUnitTestCase {
32 protected $_apiversion = 3;
33 protected $_entity = 'loc_block';
34
35 /**
36 * Set up.
37 */
38 public function setUp() {
39 parent::setUp();
40 $this->useTransaction(TRUE);
41 }
42
43 /**
44 * Test creating location block.
45 */
46 public function testCreateLocBlock() {
47 $email = $this->callAPISuccess('email', 'create', array(
48 'contact_id' => 'null',
49 'email' => 'test@loc.block',
50 ));
51 $phone = $this->callAPISuccess('phone', 'create', array(
52 'contact_id' => 'null',
53 'location_type_id' => 1,
54 'phone' => '1234567',
55 ));
56 $address = $this->callAPISuccess('address', 'create', array(
57 'contact_id' => 'null',
58 'location_type_id' => 1,
59 'street_address' => '1234567',
60 ));
61 $params = array(
62 'address_id' => $address['id'],
63 'phone_id' => $phone['id'],
64 'email_id' => $email['id'],
65 );
66 $description = 'Create locBlock with existing entities';
67 $result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__, $description);
68 $id = $result['id'];
69 $this->assertEquals(1, $result['count']);
70 $this->assertNotNull($result['values'][$id]['id']);
71 $this->getAndCheck($params, $id, $this->_entity);
72 }
73
74 /**
75 * Test creating location block entities.
76 */
77 public function testCreateLocBlockEntities() {
78 $params = array(
79 'email' => array(
80 'location_type_id' => 1,
81 'email' => 'test2@loc.block',
82 ),
83 'phone' => array(
84 'location_type_id' => 1,
85 'phone' => '987654321',
86 ),
87 'phone_2' => array(
88 'location_type_id' => 1,
89 'phone' => '456-7890',
90 ),
91 'address' => array(
92 'location_type_id' => 1,
93 'street_address' => '987654321',
94 ),
95 );
96 $description = "Create entities and locBlock in 1 api call.";
97 $result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__, $description, 'CreateEntities');
98 $id = $result['id'];
99 $this->assertEquals(1, $result['count']);
100
101 // Now check our results using the return param 'all'.
102 $getParams = array(
103 'id' => $id,
104 'return' => 'all',
105 );
106 // Can't use callAPISuccess with getsingle.
107 $result = $this->callAPIAndDocument($this->_entity, 'get', $getParams, __FUNCTION__, __FILE__, 'Get entities and location block in 1 api call');
108 $result = array_pop($result['values']);
109 $this->assertNotNull($result['email_id']);
110 $this->assertNotNull($result['phone_id']);
111 $this->assertNotNull($result['phone_2_id']);
112 $this->assertNotNull($result['address_id']);
113 $this->assertEquals($params['email']['email'], $result['email']['email']);
114 $this->assertEquals($params['phone_2']['phone'], $result['phone_2']['phone']);
115 $this->assertEquals($params['address']['street_address'], $result['address']['street_address']);
116
117 $this->callAPISuccess($this->_entity, 'delete', array('id' => $id));
118 }
119
120 }