4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.4 |
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 = 3;
37 protected $_groupContactId;
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
55 $this->_contactId
= $this->individualCreate();
57 $this->_groupId1
= $this->groupCreate(NULL);
59 'contact_id' => $this->_contactId
,
60 'group_id' => $this->_groupId1
,
63 $result = $this->callAPISuccess('group_contact', 'create', $params);
64 $this->_groupContactId
= $result['id'];
67 'name' => 'Test Group 2',
69 'title' => 'New Test Group2 Created',
70 'description' => 'New Test Group2 Created',
72 'visibility' => 'User and User Admin Only',
75 $this->_groupId2
= $this->groupCreate($group, 3);
77 $this->_group
= array(
78 $this->_groupId1
=> array('title' => 'New Test Group Created',
79 'visibility' => 'Public Pages',
82 $this->_groupId2
=> array(
83 'title' => 'New Test Group2 Created',
84 'visibility' => 'User and User Admin Only',
91 $tablesToTruncate = array(
95 $this->quickCleanup($tablesToTruncate);
98 ///////////////// civicrm_group_contact_get methods
101 'contact_id' => $this->_contactId
,
103 $result = $this->callAPIAndDocument('group_contact', 'get', $params, __FUNCTION__
, __FILE__
);
104 foreach ($result['values'] as $v) {
105 $this->assertEquals($v['title'], $this->_group
[$v['group_id']]['title']);
106 $this->assertEquals($v['visibility'], $this->_group
[$v['group_id']]['visibility']);
107 $this->assertEquals($v['in_method'], $this->_group
[$v['group_id']]['in_method']);
111 function testGetGroupID() {
112 $description = "Get all from group and display contacts";
113 $subfile = "GetWithGroupID";
115 'group_id' => $this->_groupId1
,
116 'api.group.get' => 1,
119 $result = $this->callAPIAndDocument('group_contact', 'get', $params, __FUNCTION__
, __FILE__
, $description, $subfile);
120 foreach ($result['values'][0]['api.group.get']['values'] as $values) {
121 $key = $values['id'];
122 $this->assertEquals($values['title'], $this->_group
[$key]['title']);
123 $this->assertEquals($values['visibility'], $this->_group
[$key]['visibility']);
127 function testCreateWithEmptyParams() {
129 $groups = $this->callAPIFailure('group_contact', 'create', $params);
130 $this->assertEquals($groups['error_message'],
131 'Mandatory key(s) missing from params array: group_id, contact_id'
135 function testCreateWithoutGroupIdParams() {
137 'contact_id' => $this->_contactId
, );
139 $groups = $this->callAPIFailure('group_contact', 'create', $params);
140 $this->assertEquals($groups['error_message'], 'Mandatory key(s) missing from params array: group_id');
143 function testCreateWithoutContactIdParams() {
145 'group_id' => $this->_groupId1
, );
146 $groups = $this->callAPIFailure('group_contact', 'create', $params);
147 $this->assertEquals($groups['error_message'], 'Mandatory key(s) missing from params array: contact_id');
150 function testCreate() {
152 'first_name' => 'Amiteshwar',
153 'middle_name' => 'L.',
154 'last_name' => 'Prasad',
157 'email' => 'amiteshwar.prasad@civicrm.org',
158 'contact_type' => 'Individual', );
160 $this->_contactId1
= $this->individualCreate($cont);
162 'contact_id' => $this->_contactId
,
163 'contact_id.2' => $this->_contactId1
,
164 'group_id' => $this->_groupId1
,
167 $result = $this->callAPIAndDocument('group_contact', 'create', $params, __FUNCTION__
, __FILE__
);
168 $this->assertEquals($result['not_added'], 1, "in line " . __LINE__
);
169 $this->assertEquals($result['added'], 1, "in line " . __LINE__
);
170 $this->assertEquals($result['total_count'], 2, "in line " . __LINE__
);
173 ///////////////// civicrm_group_contact_remove methods
174 function testDelete() {
176 'contact_id' => $this->_contactId
,
180 $result = $this->callAPIAndDocument('group_contact', 'delete', $params, __FUNCTION__
, __FILE__
);
181 $this->assertEquals($result['removed'], 1, "in line " . __LINE__
);
182 $this->assertEquals($result['total_count'], 1, "in line " . __LINE__
);
185 function testDeletePermanent() {
187 'id' => $this->_groupContactId
,
188 'skip_undelete' => TRUE,
190 $this->callAPIAndDocument('group_contact', 'delete', $params, __FUNCTION__
, __FILE__
);
191 $result = $this->callAPISuccess('group_contact', 'get', $params);
192 $this->assertEquals(0, $result['count'], "in line " . __LINE__
);