CRM-13014 support userLoginFinalize() for UF classes (fix civimobile)
[civicrm-core.git] / tests / phpunit / api / v3 / GroupContactTest.php
CommitLineData
6a488035
TO
1<?php
2// $Id$
3
4/*
5 +--------------------------------------------------------------------+
6 | CiviCRM version 4.3 |
7 +--------------------------------------------------------------------+
8 | Copyright CiviCRM LLC (c) 2004-2013 |
9 +--------------------------------------------------------------------+
10 | This file is a part of CiviCRM. |
11 | |
12 | CiviCRM is free software; you can copy, modify, and distribute it |
13 | under the terms of the GNU Affero General Public License |
14 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
15 | |
16 | CiviCRM is distributed in the hope that it will be useful, but |
17 | WITHOUT ANY WARRANTY; without even the implied warranty of |
18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
19 | See the GNU Affero General Public License for more details. |
20 | |
21 | You should have received a copy of the GNU Affero General Public |
22 | License and the CiviCRM Licensing Exception along |
23 | with this program; if not, contact CiviCRM LLC |
24 | at info[AT]civicrm[DOT]org. If you have questions about the |
25 | GNU Affero General Public License or the licensing of CiviCRM, |
26 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
27 +--------------------------------------------------------------------+
28*/
29
30
31require_once 'CiviTest/CiviUnitTestCase.php';
32class api_v3_GroupContactTest extends CiviUnitTestCase {
33
34 protected $_contactId;
35 protected $_contactId1;
36 protected $_apiversion;
37 protected $_groupId1;
38 public $_eNoticeCompliant = True;
39
40 function get_info() {
41 return array(
42 'name' => 'Group Contact Create',
43 'description' => 'Test all Group Contact Create API methods.',
44 'group' => 'CiviCRM API Tests',
45 );
46 }
47
48 /*
49 * Set up for group contact tests
50 *
51 * @todo set up calls function that doesn't work @ the moment
52 */
53 function setUp() {
54 $this->_apiversion = 3;
55 parent::setUp();
56
57 $this->_contactId = $this->individualCreate(NULL);
58
59 $this->_groupId1 = $this->groupCreate(NULL);
60 $params = array(
61 'contact_id' => $this->_contactId,
62 'group_id' => $this->_groupId1,
63 'version' => $this->_apiversion,
64 );
65
66 $result = civicrm_api('group_contact', 'create', $params);
67
68 $group = array(
69 'name' => 'Test Group 2',
70 'domain_id' => 1,
71 'title' => 'New Test Group2 Created',
72 'description' => 'New Test Group2 Created',
73 'is_active' => 1,
74 'visibility' => 'User and User Admin Only',
75 'version' => $this->_apiversion,
76 );
77
78 $this->_groupId2 = $this->groupCreate($group, 3);
79 $params = array(
80 'contact_id.1' => $this->_contactId,
81 'group_id' => $this->_groupId2,
82 'version' => $this->_apiversion,
83 );
84 //@todo uncomment me when I work
85 //civicrm_group_contact_create( $params );
86
87 $this->_group = array(
88 $this->_groupId1 => array('title' => 'New Test Group Created',
89 'visibility' => 'Public Pages',
90 'in_method' => 'API',
91 ),
92 $this->_groupId2 => array(
93 'title' => 'New Test Group2 Created',
94 'visibility' => 'User and User Admin Only',
95 'in_method' => 'API',
96 ),
97 );
98 }
99
100 function tearDown() {
101 $tablesToTruncate = array(
102 'civicrm_contact',
103 'civicrm_group',
104 );
105 $this->quickCleanup($tablesToTruncate);
106 }
107
108 ///////////////// civicrm_group_contact_get methods
109 function testGet() {
110 $params = array(
111 'contact_id' => $this->_contactId,
112 'version' => $this->_apiversion,
113 );
114 $result = civicrm_api('group_contact', 'get', $params);
115 $this->documentMe($params, $result, __FUNCTION__, __FILE__);
116 foreach ($result['values'] as $v) {
117 $this->assertEquals($v['title'], $this->_group[$v['group_id']]['title']);
118 $this->assertEquals($v['visibility'], $this->_group[$v['group_id']]['visibility']);
119 $this->assertEquals($v['in_method'], $this->_group[$v['group_id']]['in_method']);
120 }
121 }
122
123 function testGetGroupID() {
124 $description = "Get all from group and display contacts";
125 $subfile = "GetWithGroupID";
126 $params = array(
127 'group_id' => $this->_groupId1,
128 'version' => $this->_apiversion,
129 'api.group.get' => 1,
130 'sequential' => 1,
131 );
132 $result = civicrm_api('group_contact', 'get', $params);
133 $this->documentMe($params, $result, __FUNCTION__, __FILE__, $description, $subfile);
134 foreach ($result['values'][0]['api.group.get']['values'] as $values) {
135 $key = $values['id'];
136 $this->assertEquals($values['title'], $this->_group[$key]['title']);
137 $this->assertEquals($values['visibility'], $this->_group[$key]['visibility']);
138 }
139 }
140
141
142 ///////////////// civicrm_group_contact_add methods
143 function testCreateWithWrongParamsType() {
144 $params = 1;
145 $groups = civicrm_api('group_contact', 'create', $params);
146
147 $this->assertEquals($groups['is_error'], 1);
148 $this->assertEquals($groups['error_message'], 'Input variable `params` is not an array');
149 }
150
151 function testCreateWithEmptyParams() {
152 $params = array();
153 $groups = civicrm_api('group_contact', 'create', $params);
154
155 $this->assertEquals($groups['is_error'], 1);
156 $this->assertEquals($groups['error_message'],
157 'Mandatory key(s) missing from params array: version, group_id, contact_id'
158 );
159 }
160
161 function testCreateWithoutGroupIdParams() {
162 $params = array(
163 'contact_id' => $this->_contactId,
164 'version' => $this->_apiversion,
165 );
166
167 $groups = civicrm_api('group_contact', 'create', $params);
168
169 $this->assertEquals($groups['is_error'], 1);
170 $this->assertEquals($groups['error_message'], 'Mandatory key(s) missing from params array: group_id');
171 }
172
173 function testCreateWithoutContactIdParams() {
174 $params = array(
175 'group_id' => $this->_groupId1,
176 'version' => $this->_apiversion,
177 );
178 $groups = civicrm_api('group_contact', 'create', $params);
179
180 $this->assertEquals($groups['is_error'], 1);
181 $this->assertEquals($groups['error_message'], 'Mandatory key(s) missing from params array: contact_id');
182 }
183
184 function testCreate() {
185 $cont = array(
186 'first_name' => 'Amiteshwar',
187 'middle_name' => 'L.',
188 'last_name' => 'Prasad',
189 'prefix_id' => 3,
190 'suffix_id' => 3,
191 'email' => 'amiteshwar.prasad@civicrm.org',
192 'contact_type' => 'Individual',
193 'version' => $this->_apiversion,
194 );
195
196 $this->_contactId1 = $this->individualCreate($cont);
197 $params = array(
198 'contact_id' => $this->_contactId,
199 'contact_id.2' => $this->_contactId1,
200 'group_id' => $this->_groupId1,
201 'version' => $this->_apiversion,
202 );
203
204 $result = civicrm_api('group_contact', 'create', $params);
205 $this->documentMe($params, $result, __FUNCTION__, __FILE__);
206 $this->assertEquals($result['is_error'], 0, "in line " . __LINE__);
207 $this->assertEquals($result['not_added'], 1, "in line " . __LINE__);
208 $this->assertEquals($result['added'], 1, "in line " . __LINE__);
209 $this->assertEquals($result['total_count'], 2, "in line " . __LINE__);
210 }
211
212 ///////////////// civicrm_group_contact_remove methods
213 function testDelete() {
214 $params = array(
215 'contact_id' => $this->_contactId,
216 'group_id' => 1,
217 'version' => $this->_apiversion,
218 );
219
220 $result = civicrm_api('group_contact', 'delete', $params);
221 $this->documentMe($params, $result, __FUNCTION__, __FILE__);
222 $this->assertEquals($result['is_error'], 0, "in line " . __LINE__);
223 $this->assertEquals($result['removed'], 1, "in line " . __LINE__);
224 $this->assertEquals($result['total_count'], 1, "in line " . __LINE__);
225 }
226}
227