Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
b6708aeb | 2 | /* |
3 | +--------------------------------------------------------------------+ | |
81621fee | 4 | | CiviCRM version 4.7 | |
b6708aeb | 5 | +--------------------------------------------------------------------+ |
15a4309a | 6 | | Copyright CiviCRM LLC (c) 2004-2017 | |
b6708aeb | 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 | +--------------------------------------------------------------------+ | |
e70a7fc0 | 26 | */ |
6a488035 | 27 | |
e9479dcf EM |
28 | /** |
29 | * Class api_v3_LocBlockTest | |
acb109b7 | 30 | * @group headless |
e9479dcf | 31 | */ |
6a488035 TO |
32 | class api_v3_LocBlockTest extends CiviUnitTestCase { |
33 | protected $_apiversion = 3; | |
34 | protected $_entity = 'loc_block'; | |
b7c9bc4c | 35 | |
11e974ee EM |
36 | /** |
37 | * Set up. | |
38 | */ | |
6a488035 TO |
39 | public function setUp() { |
40 | parent::setUp(); | |
1fde2cb2 | 41 | $this->useTransaction(TRUE); |
6a488035 TO |
42 | } |
43 | ||
5e4f7f74 EM |
44 | /** |
45 | * Test creating location block. | |
46 | */ | |
6a488035 | 47 | public function testCreateLocBlock() { |
70c906cf | 48 | $email = $this->callAPISuccess('email', 'create', array( |
6a488035 | 49 | 'contact_id' => 'null', |
6a488035 TO |
50 | 'email' => 'test@loc.block', |
51 | )); | |
70c906cf | 52 | $phone = $this->callAPISuccess('phone', 'create', array( |
6a488035 TO |
53 | 'contact_id' => 'null', |
54 | 'location_type_id' => 1, | |
55 | 'phone' => '1234567', | |
56 | )); | |
70c906cf | 57 | $address = $this->callAPISuccess('address', 'create', array( |
6a488035 TO |
58 | 'contact_id' => 'null', |
59 | 'location_type_id' => 1, | |
60 | 'street_address' => '1234567', | |
61 | )); | |
62 | $params = array( | |
6a488035 TO |
63 | 'address_id' => $address['id'], |
64 | 'phone_id' => $phone['id'], | |
65 | 'email_id' => $email['id'], | |
66 | ); | |
69f028bc | 67 | $description = 'Create locBlock with existing entities'; |
a828d7b8 | 68 | $result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__, $description); |
6a488035 | 69 | $id = $result['id']; |
5e4f7f74 EM |
70 | $this->assertEquals(1, $result['count']); |
71 | $this->assertNotNull($result['values'][$id]['id']); | |
6a488035 TO |
72 | $this->getAndCheck($params, $id, $this->_entity); |
73 | } | |
74 | ||
5e4f7f74 EM |
75 | /** |
76 | * Test creating location block entities. | |
77 | */ | |
6a488035 TO |
78 | public function testCreateLocBlockEntities() { |
79 | $params = array( | |
6a488035 TO |
80 | 'email' => array( |
81 | 'location_type_id' => 1, | |
82 | 'email' => 'test2@loc.block', | |
83 | ), | |
84 | 'phone' => array( | |
85 | 'location_type_id' => 1, | |
86 | 'phone' => '987654321', | |
87 | ), | |
88 | 'phone_2' => array( | |
89 | 'location_type_id' => 1, | |
90 | 'phone' => '456-7890', | |
91 | ), | |
92 | 'address' => array( | |
93 | 'location_type_id' => 1, | |
94 | 'street_address' => '987654321', | |
95 | ), | |
96 | ); | |
5c49fee0 | 97 | $description = "Create entities and locBlock in 1 api call."; |
a828d7b8 | 98 | $result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__, $description, 'CreateEntities'); |
6a488035 | 99 | $id = $result['id']; |
5e4f7f74 | 100 | $this->assertEquals(1, $result['count']); |
6a488035 | 101 | |
5e4f7f74 | 102 | // Now check our results using the return param 'all'. |
69f028bc CW |
103 | $getParams = array( |
104 | 'id' => $id, | |
105 | 'return' => 'all', | |
82adafa2 | 106 | ); |
5e4f7f74 | 107 | // Can't use callAPISuccess with getsingle. |
a828d7b8 | 108 | $result = $this->callAPIAndDocument($this->_entity, 'get', $getParams, __FUNCTION__, __FILE__, 'Get entities and location block in 1 api call'); |
69f028bc | 109 | $result = array_pop($result['values']); |
5e4f7f74 EM |
110 | $this->assertNotNull($result['email_id']); |
111 | $this->assertNotNull($result['phone_id']); | |
112 | $this->assertNotNull($result['phone_2_id']); | |
113 | $this->assertNotNull($result['address_id']); | |
114 | $this->assertEquals($params['email']['email'], $result['email']['email']); | |
115 | $this->assertEquals($params['phone_2']['phone'], $result['phone_2']['phone']); | |
116 | $this->assertEquals($params['address']['street_address'], $result['address']['street_address']); | |
117 | ||
11e974ee | 118 | $this->callAPISuccess($this->_entity, 'delete', array('id' => $id)); |
6a488035 TO |
119 | } |
120 | ||
6a488035 | 121 | } |