4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.3 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2013 |
8 +--------------------------------------------------------------------+
9 | This file is a part of CiviCRM. |
11 | CiviCRM is free software; you can copy, modify, and distribute it |
12 | under the terms of the GNU Affero General Public License |
13 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
15 | CiviCRM is distributed in the hope that it will be useful, but |
16 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. |
20 | You should have received a copy of the GNU Affero General Public |
21 | License and the CiviCRM Licensing Exception along |
22 | with this program; if not, contact CiviCRM LLC |
23 | at info[AT]civicrm[DOT]org. If you have questions about the |
24 | GNU Affero General Public License or the licensing of CiviCRM, |
25 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
26 +--------------------------------------------------------------------+
30 require_once 'CiviTest/CiviUnitTestCase.php';
31 class api_v3_GroupContactTest
extends CiviUnitTestCase
{
33 protected $_contactId;
34 protected $_contactId1;
35 protected $_apiversion;
37 public $_eNoticeCompliant = True;
41 'name' => 'Group Contact Create',
42 'description' => 'Test all Group Contact Create API methods.',
43 'group' => 'CiviCRM API Tests',
48 * Set up for group contact tests
50 * @todo set up calls function that doesn't work @ the moment
53 $this->_apiversion
= 3;
56 $this->_contactId
= $this->individualCreate(NULL);
58 $this->_groupId1
= $this->groupCreate(NULL);
60 'contact_id' => $this->_contactId
,
61 'group_id' => $this->_groupId1
,
62 'version' => $this->_apiversion
,
65 $result = civicrm_api('group_contact', 'create', $params);
68 'name' => 'Test Group 2',
70 'title' => 'New Test Group2 Created',
71 'description' => 'New Test Group2 Created',
73 'visibility' => 'User and User Admin Only',
74 'version' => $this->_apiversion
,
77 $this->_groupId2
= $this->groupCreate($group, 3);
79 'contact_id.1' => $this->_contactId
,
80 'group_id' => $this->_groupId2
,
81 'version' => $this->_apiversion
,
83 //@todo uncomment me when I work
84 //civicrm_group_contact_create( $params );
86 $this->_group
= array(
87 $this->_groupId1
=> array('title' => 'New Test Group Created',
88 'visibility' => 'Public Pages',
91 $this->_groupId2
=> array(
92 'title' => 'New Test Group2 Created',
93 'visibility' => 'User and User Admin Only',
100 $tablesToTruncate = array(
104 $this->quickCleanup($tablesToTruncate);
107 ///////////////// civicrm_group_contact_get methods
110 'contact_id' => $this->_contactId
,
111 'version' => $this->_apiversion
,
113 $result = civicrm_api('group_contact', 'get', $params);
114 $this->documentMe($params, $result, __FUNCTION__
, __FILE__
);
115 foreach ($result['values'] as $v) {
116 $this->assertEquals($v['title'], $this->_group
[$v['group_id']]['title']);
117 $this->assertEquals($v['visibility'], $this->_group
[$v['group_id']]['visibility']);
118 $this->assertEquals($v['in_method'], $this->_group
[$v['group_id']]['in_method']);
122 function testGetGroupID() {
123 $description = "Get all from group and display contacts";
124 $subfile = "GetWithGroupID";
126 'group_id' => $this->_groupId1
,
127 'version' => $this->_apiversion
,
128 'api.group.get' => 1,
131 $result = civicrm_api('group_contact', 'get', $params);
132 $this->documentMe($params, $result, __FUNCTION__
, __FILE__
, $description, $subfile);
133 foreach ($result['values'][0]['api.group.get']['values'] as $values) {
134 $key = $values['id'];
135 $this->assertEquals($values['title'], $this->_group
[$key]['title']);
136 $this->assertEquals($values['visibility'], $this->_group
[$key]['visibility']);
141 ///////////////// civicrm_group_contact_add methods
142 function testCreateWithWrongParamsType() {
144 $groups = civicrm_api('group_contact', 'create', $params);
146 $this->assertEquals($groups['is_error'], 1);
147 $this->assertEquals($groups['error_message'], 'Input variable `params` is not an array');
150 function testCreateWithEmptyParams() {
152 $groups = civicrm_api('group_contact', 'create', $params);
154 $this->assertEquals($groups['is_error'], 1);
155 $this->assertEquals($groups['error_message'],
156 'Mandatory key(s) missing from params array: version, group_id, contact_id'
160 function testCreateWithoutGroupIdParams() {
162 'contact_id' => $this->_contactId
,
163 'version' => $this->_apiversion
,
166 $groups = civicrm_api('group_contact', 'create', $params);
168 $this->assertEquals($groups['is_error'], 1);
169 $this->assertEquals($groups['error_message'], 'Mandatory key(s) missing from params array: group_id');
172 function testCreateWithoutContactIdParams() {
174 'group_id' => $this->_groupId1
,
175 'version' => $this->_apiversion
,
177 $groups = civicrm_api('group_contact', 'create', $params);
179 $this->assertEquals($groups['is_error'], 1);
180 $this->assertEquals($groups['error_message'], 'Mandatory key(s) missing from params array: contact_id');
183 function testCreate() {
185 'first_name' => 'Amiteshwar',
186 'middle_name' => 'L.',
187 'last_name' => 'Prasad',
190 'email' => 'amiteshwar.prasad@civicrm.org',
191 'contact_type' => 'Individual',
192 'version' => $this->_apiversion
,
195 $this->_contactId1
= $this->individualCreate($cont);
197 'contact_id' => $this->_contactId
,
198 'contact_id.2' => $this->_contactId1
,
199 'group_id' => $this->_groupId1
,
200 'version' => $this->_apiversion
,
203 $result = civicrm_api('group_contact', 'create', $params);
204 $this->documentMe($params, $result, __FUNCTION__
, __FILE__
);
205 $this->assertEquals($result['is_error'], 0, "in line " . __LINE__
);
206 $this->assertEquals($result['not_added'], 1, "in line " . __LINE__
);
207 $this->assertEquals($result['added'], 1, "in line " . __LINE__
);
208 $this->assertEquals($result['total_count'], 2, "in line " . __LINE__
);
211 ///////////////// civicrm_group_contact_remove methods
212 function testDelete() {
214 'contact_id' => $this->_contactId
,
216 'version' => $this->_apiversion
,
219 $result = civicrm_api('group_contact', 'delete', $params);
220 $this->documentMe($params, $result, __FUNCTION__
, __FILE__
);
221 $this->assertEquals($result['is_error'], 0, "in line " . __LINE__
);
222 $this->assertEquals($result['removed'], 1, "in line " . __LINE__
);
223 $this->assertEquals($result['total_count'], 1, "in line " . __LINE__
);