Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 TO |
2 | /* |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06a1bc01 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
6a488035 TO |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | ||
29 | require_once 'CiviTest/CiviUnitTestCase.php'; | |
e9479dcf EM |
30 | |
31 | /** | |
32 | * Class api_v3_GroupContactTest | |
33 | */ | |
6a488035 TO |
34 | class api_v3_GroupContactTest extends CiviUnitTestCase { |
35 | ||
36 | protected $_contactId; | |
37 | protected $_contactId1; | |
7fbb4198 | 38 | protected $_apiversion = 3; |
6a488035 | 39 | protected $_groupId1; |
6a488035 | 40 | |
c490a46a | 41 | /** |
eceb18cc | 42 | * Set up for group contact tests. |
c490a46a CW |
43 | * |
44 | * @todo set up calls function that doesn't work @ the moment | |
45 | */ | |
00be9182 | 46 | public function setUp() { |
6a488035 | 47 | parent::setUp(); |
10f7c4d2 | 48 | $this->useTransaction(TRUE); |
6a488035 | 49 | |
e4d5f1e2 | 50 | $this->_contactId = $this->individualCreate(); |
6a488035 | 51 | |
72e41e3a | 52 | $this->_groupId1 = $this->groupCreate(); |
6a488035 TO |
53 | $params = array( |
54 | 'contact_id' => $this->_contactId, | |
55 | 'group_id' => $this->_groupId1, | |
6a488035 TO |
56 | ); |
57 | ||
7fbb4198 | 58 | $result = $this->callAPISuccess('group_contact', 'create', $params); |
6a488035 TO |
59 | |
60 | $group = array( | |
61 | 'name' => 'Test Group 2', | |
62 | 'domain_id' => 1, | |
63 | 'title' => 'New Test Group2 Created', | |
64 | 'description' => 'New Test Group2 Created', | |
65 | 'is_active' => 1, | |
66 | 'visibility' => 'User and User Admin Only', | |
6a488035 TO |
67 | ); |
68 | ||
d8e39cba | 69 | $this->_groupId2 = $this->groupCreate($group); |
6a488035 TO |
70 | |
71 | $this->_group = array( | |
6c6e6187 | 72 | $this->_groupId1 => array( |
92915c55 | 73 | 'title' => 'New Test Group Created', |
6a488035 TO |
74 | 'visibility' => 'Public Pages', |
75 | 'in_method' => 'API', | |
76 | ), | |
77 | $this->_groupId2 => array( | |
78 | 'title' => 'New Test Group2 Created', | |
79 | 'visibility' => 'User and User Admin Only', | |
80 | 'in_method' => 'API', | |
81 | ), | |
82 | ); | |
83 | } | |
84 | ||
36e590d4 TO |
85 | ///////////////// civicrm_group_contact_get methods |
86 | ||
389bcebf | 87 | /** |
36e590d4 | 88 | * Test GroupContact.get by ID. |
389bcebf | 89 | */ |
00be9182 | 90 | public function testGet() { |
6a488035 TO |
91 | $params = array( |
92 | 'contact_id' => $this->_contactId, | |
6a488035 | 93 | ); |
7fbb4198 | 94 | $result = $this->callAPIAndDocument('group_contact', 'get', $params, __FUNCTION__, __FILE__); |
6a488035 TO |
95 | foreach ($result['values'] as $v) { |
96 | $this->assertEquals($v['title'], $this->_group[$v['group_id']]['title']); | |
97 | $this->assertEquals($v['visibility'], $this->_group[$v['group_id']]['visibility']); | |
98 | $this->assertEquals($v['in_method'], $this->_group[$v['group_id']]['in_method']); | |
99 | } | |
100 | } | |
101 | ||
00be9182 | 102 | public function testGetGroupID() { |
5c49fee0 | 103 | $description = "Get all from group and display contacts."; |
92915c55 TO |
104 | $subfile = "GetWithGroupID"; |
105 | $params = array( | |
6a488035 | 106 | 'group_id' => $this->_groupId1, |
6a488035 TO |
107 | 'api.group.get' => 1, |
108 | 'sequential' => 1, | |
109 | ); | |
7fbb4198 | 110 | $result = $this->callAPIAndDocument('group_contact', 'get', $params, __FUNCTION__, __FILE__, $description, $subfile); |
6a488035 TO |
111 | foreach ($result['values'][0]['api.group.get']['values'] as $values) { |
112 | $key = $values['id']; | |
113 | $this->assertEquals($values['title'], $this->_group[$key]['title']); | |
114 | $this->assertEquals($values['visibility'], $this->_group[$key]['visibility']); | |
115 | } | |
116 | } | |
117 | ||
00be9182 | 118 | public function testCreateWithEmptyParams() { |
6a488035 | 119 | $params = array(); |
d0e1eff2 | 120 | $groups = $this->callAPIFailure('group_contact', 'create', $params); |
6a488035 | 121 | $this->assertEquals($groups['error_message'], |
d0e1eff2 | 122 | 'Mandatory key(s) missing from params array: group_id, contact_id' |
6a488035 TO |
123 | ); |
124 | } | |
125 | ||
00be9182 | 126 | public function testCreateWithoutGroupIdParams() { |
6a488035 | 127 | $params = array( |
92915c55 TO |
128 | 'contact_id' => $this->_contactId, |
129 | ); | |
6a488035 | 130 | |
d0e1eff2 | 131 | $groups = $this->callAPIFailure('group_contact', 'create', $params); |
6a488035 TO |
132 | $this->assertEquals($groups['error_message'], 'Mandatory key(s) missing from params array: group_id'); |
133 | } | |
134 | ||
00be9182 | 135 | public function testCreateWithoutContactIdParams() { |
6a488035 | 136 | $params = array( |
92915c55 TO |
137 | 'group_id' => $this->_groupId1, |
138 | ); | |
d0e1eff2 | 139 | $groups = $this->callAPIFailure('group_contact', 'create', $params); |
6a488035 TO |
140 | $this->assertEquals($groups['error_message'], 'Mandatory key(s) missing from params array: contact_id'); |
141 | } | |
142 | ||
00be9182 | 143 | public function testCreate() { |
6a488035 TO |
144 | $cont = array( |
145 | 'first_name' => 'Amiteshwar', | |
146 | 'middle_name' => 'L.', | |
147 | 'last_name' => 'Prasad', | |
148 | 'prefix_id' => 3, | |
149 | 'suffix_id' => 3, | |
150 | 'email' => 'amiteshwar.prasad@civicrm.org', | |
92915c55 TO |
151 | 'contact_type' => 'Individual', |
152 | ); | |
6a488035 TO |
153 | |
154 | $this->_contactId1 = $this->individualCreate($cont); | |
155 | $params = array( | |
156 | 'contact_id' => $this->_contactId, | |
157 | 'contact_id.2' => $this->_contactId1, | |
158 | 'group_id' => $this->_groupId1, | |
6a488035 TO |
159 | ); |
160 | ||
7fbb4198 | 161 | $result = $this->callAPIAndDocument('group_contact', 'create', $params, __FUNCTION__, __FILE__); |
6a488035 TO |
162 | $this->assertEquals($result['not_added'], 1, "in line " . __LINE__); |
163 | $this->assertEquals($result['added'], 1, "in line " . __LINE__); | |
164 | $this->assertEquals($result['total_count'], 2, "in line " . __LINE__); | |
165 | } | |
166 | ||
36e590d4 TO |
167 | ///////////////// civicrm_group_contact_remove methods |
168 | ||
389bcebf | 169 | /** |
36e590d4 | 170 | * Test GroupContact.delete by contact+group ID. |
389bcebf | 171 | */ |
00be9182 | 172 | public function testDelete() { |
6a488035 TO |
173 | $params = array( |
174 | 'contact_id' => $this->_contactId, | |
10f7c4d2 | 175 | 'group_id' => $this->_groupId1, |
6a488035 TO |
176 | ); |
177 | ||
7fbb4198 | 178 | $result = $this->callAPIAndDocument('group_contact', 'delete', $params, __FUNCTION__, __FILE__); |
6a488035 TO |
179 | $this->assertEquals($result['removed'], 1, "in line " . __LINE__); |
180 | $this->assertEquals($result['total_count'], 1, "in line " . __LINE__); | |
181 | } | |
3d700d00 | 182 | |
00be9182 | 183 | public function testDeletePermanent() { |
a9739e5d | 184 | $result = $this->callAPISuccess('group_contact', 'get', array('contact_id' => $this->_contactId)); |
3d700d00 | 185 | $params = array( |
a9739e5d | 186 | 'id' => $result['id'], |
3d700d00 CW |
187 | 'skip_undelete' => TRUE, |
188 | ); | |
189 | $this->callAPIAndDocument('group_contact', 'delete', $params, __FUNCTION__, __FILE__); | |
190 | $result = $this->callAPISuccess('group_contact', 'get', $params); | |
191 | $this->assertEquals(0, $result['count'], "in line " . __LINE__); | |
a9739e5d | 192 | $this->assertArrayNotHasKey('id', $result, "in line " . __LINE__); |
3d700d00 | 193 | } |
96025800 | 194 | |
6a488035 | 195 | } |