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 = $this->callAPIFailure('group_contact', 'create', $params);
145 $this->assertEquals($groups['error_message'], 'Input variable `params` is not an array');
148 function testCreateWithEmptyParams() {
150 $groups = $this->callAPIFailure('group_contact', 'create', $params);
151 $this->assertEquals($groups['error_message'],
152 'Mandatory key(s) missing from params array: group_id, contact_id'
156 function testCreateWithoutGroupIdParams() {
158 'contact_id' => $this->_contactId
,
159 'version' => $this->_apiversion
,
162 $groups = $this->callAPIFailure('group_contact', 'create', $params);
163 $this->assertEquals($groups['error_message'], 'Mandatory key(s) missing from params array: group_id');
166 function testCreateWithoutContactIdParams() {
168 'group_id' => $this->_groupId1
,
169 'version' => $this->_apiversion
,
171 $groups = $this->callAPIFailure('group_contact', 'create', $params);
172 $this->assertEquals($groups['error_message'], 'Mandatory key(s) missing from params array: contact_id');
175 function testCreate() {
177 'first_name' => 'Amiteshwar',
178 'middle_name' => 'L.',
179 'last_name' => 'Prasad',
182 'email' => 'amiteshwar.prasad@civicrm.org',
183 'contact_type' => 'Individual',
184 'version' => $this->_apiversion
,
187 $this->_contactId1
= $this->individualCreate($cont);
189 'contact_id' => $this->_contactId
,
190 'contact_id.2' => $this->_contactId1
,
191 'group_id' => $this->_groupId1
,
192 'version' => $this->_apiversion
,
195 $result = civicrm_api('group_contact', 'create', $params);
196 $this->documentMe($params, $result, __FUNCTION__
, __FILE__
);
197 $this->assertAPISuccess($result, "in line " . __LINE__
);
198 $this->assertEquals($result['not_added'], 1, "in line " . __LINE__
);
199 $this->assertEquals($result['added'], 1, "in line " . __LINE__
);
200 $this->assertEquals($result['total_count'], 2, "in line " . __LINE__
);
203 ///////////////// civicrm_group_contact_remove methods
204 function testDelete() {
206 'contact_id' => $this->_contactId
,
208 'version' => $this->_apiversion
,
211 $result = civicrm_api('group_contact', 'delete', $params);
212 $this->documentMe($params, $result, __FUNCTION__
, __FILE__
);
213 $this->assertAPISuccess($result, "in line " . __LINE__
);
214 $this->assertEquals($result['removed'], 1, "in line " . __LINE__
);
215 $this->assertEquals($result['total_count'], 1, "in line " . __LINE__
);