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 | +--------------------------------------------------------------------+ | |
26 | */ | |
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 CW |
41 | /** |
42 | * Set up for group contact tests | |
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 | ||
6a488035 | 85 | ///////////////// civicrm_group_contact_get methods |
00be9182 | 86 | public function testGet() { |
6a488035 TO |
87 | $params = array( |
88 | 'contact_id' => $this->_contactId, | |
6a488035 | 89 | ); |
7fbb4198 | 90 | $result = $this->callAPIAndDocument('group_contact', 'get', $params, __FUNCTION__, __FILE__); |
6a488035 TO |
91 | foreach ($result['values'] as $v) { |
92 | $this->assertEquals($v['title'], $this->_group[$v['group_id']]['title']); | |
93 | $this->assertEquals($v['visibility'], $this->_group[$v['group_id']]['visibility']); | |
94 | $this->assertEquals($v['in_method'], $this->_group[$v['group_id']]['in_method']); | |
95 | } | |
96 | } | |
97 | ||
00be9182 | 98 | public function testGetGroupID() { |
6a488035 | 99 | $description = "Get all from group and display contacts"; |
92915c55 TO |
100 | $subfile = "GetWithGroupID"; |
101 | $params = array( | |
6a488035 | 102 | 'group_id' => $this->_groupId1, |
6a488035 TO |
103 | 'api.group.get' => 1, |
104 | 'sequential' => 1, | |
105 | ); | |
7fbb4198 | 106 | $result = $this->callAPIAndDocument('group_contact', 'get', $params, __FUNCTION__, __FILE__, $description, $subfile); |
6a488035 TO |
107 | foreach ($result['values'][0]['api.group.get']['values'] as $values) { |
108 | $key = $values['id']; | |
109 | $this->assertEquals($values['title'], $this->_group[$key]['title']); | |
110 | $this->assertEquals($values['visibility'], $this->_group[$key]['visibility']); | |
111 | } | |
112 | } | |
113 | ||
00be9182 | 114 | public function testCreateWithEmptyParams() { |
6a488035 | 115 | $params = array(); |
d0e1eff2 | 116 | $groups = $this->callAPIFailure('group_contact', 'create', $params); |
6a488035 | 117 | $this->assertEquals($groups['error_message'], |
d0e1eff2 | 118 | 'Mandatory key(s) missing from params array: group_id, contact_id' |
6a488035 TO |
119 | ); |
120 | } | |
121 | ||
00be9182 | 122 | public function testCreateWithoutGroupIdParams() { |
6a488035 | 123 | $params = array( |
92915c55 TO |
124 | 'contact_id' => $this->_contactId, |
125 | ); | |
6a488035 | 126 | |
d0e1eff2 | 127 | $groups = $this->callAPIFailure('group_contact', 'create', $params); |
6a488035 TO |
128 | $this->assertEquals($groups['error_message'], 'Mandatory key(s) missing from params array: group_id'); |
129 | } | |
130 | ||
00be9182 | 131 | public function testCreateWithoutContactIdParams() { |
6a488035 | 132 | $params = array( |
92915c55 TO |
133 | 'group_id' => $this->_groupId1, |
134 | ); | |
d0e1eff2 | 135 | $groups = $this->callAPIFailure('group_contact', 'create', $params); |
6a488035 TO |
136 | $this->assertEquals($groups['error_message'], 'Mandatory key(s) missing from params array: contact_id'); |
137 | } | |
138 | ||
00be9182 | 139 | public function testCreate() { |
6a488035 TO |
140 | $cont = array( |
141 | 'first_name' => 'Amiteshwar', | |
142 | 'middle_name' => 'L.', | |
143 | 'last_name' => 'Prasad', | |
144 | 'prefix_id' => 3, | |
145 | 'suffix_id' => 3, | |
146 | 'email' => 'amiteshwar.prasad@civicrm.org', | |
92915c55 TO |
147 | 'contact_type' => 'Individual', |
148 | ); | |
6a488035 TO |
149 | |
150 | $this->_contactId1 = $this->individualCreate($cont); | |
151 | $params = array( | |
152 | 'contact_id' => $this->_contactId, | |
153 | 'contact_id.2' => $this->_contactId1, | |
154 | 'group_id' => $this->_groupId1, | |
6a488035 TO |
155 | ); |
156 | ||
7fbb4198 | 157 | $result = $this->callAPIAndDocument('group_contact', 'create', $params, __FUNCTION__, __FILE__); |
6a488035 TO |
158 | $this->assertEquals($result['not_added'], 1, "in line " . __LINE__); |
159 | $this->assertEquals($result['added'], 1, "in line " . __LINE__); | |
160 | $this->assertEquals($result['total_count'], 2, "in line " . __LINE__); | |
161 | } | |
162 | ||
163 | ///////////////// civicrm_group_contact_remove methods | |
00be9182 | 164 | public function testDelete() { |
6a488035 TO |
165 | $params = array( |
166 | 'contact_id' => $this->_contactId, | |
10f7c4d2 | 167 | 'group_id' => $this->_groupId1, |
6a488035 TO |
168 | ); |
169 | ||
7fbb4198 | 170 | $result = $this->callAPIAndDocument('group_contact', 'delete', $params, __FUNCTION__, __FILE__); |
6a488035 TO |
171 | $this->assertEquals($result['removed'], 1, "in line " . __LINE__); |
172 | $this->assertEquals($result['total_count'], 1, "in line " . __LINE__); | |
173 | } | |
3d700d00 | 174 | |
00be9182 | 175 | public function testDeletePermanent() { |
a9739e5d | 176 | $result = $this->callAPISuccess('group_contact', 'get', array('contact_id' => $this->_contactId)); |
3d700d00 | 177 | $params = array( |
a9739e5d | 178 | 'id' => $result['id'], |
3d700d00 CW |
179 | 'skip_undelete' => TRUE, |
180 | ); | |
181 | $this->callAPIAndDocument('group_contact', 'delete', $params, __FUNCTION__, __FILE__); | |
182 | $result = $this->callAPISuccess('group_contact', 'get', $params); | |
183 | $this->assertEquals(0, $result['count'], "in line " . __LINE__); | |
a9739e5d | 184 | $this->assertArrayNotHasKey('id', $result, "in line " . __LINE__); |
3d700d00 | 185 | } |
6a488035 | 186 | } |