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