3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
29 require_once 'CiviTest/CiviUnitTestCase.php';
32 * Class api_v3_GroupContactTest
34 class api_v3_GroupContactTest
extends CiviUnitTestCase
{
36 protected $_contactId;
37 protected $_contactId1;
38 protected $_apiversion = 3;
42 * Set up for group contact tests
44 * @todo set up calls function that doesn't work @ the moment
46 public function setUp() {
48 $this->useTransaction(TRUE);
50 $this->_contactId
= $this->individualCreate();
52 $this->_groupId1
= $this->groupCreate();
54 'contact_id' => $this->_contactId
,
55 'group_id' => $this->_groupId1
,
58 $result = $this->callAPISuccess('group_contact', 'create', $params);
61 'name' => 'Test Group 2',
63 'title' => 'New Test Group2 Created',
64 'description' => 'New Test Group2 Created',
66 'visibility' => 'User and User Admin Only',
69 $this->_groupId2
= $this->groupCreate($group);
71 $this->_group
= array(
72 $this->_groupId1
=> array(
73 'title' => 'New Test Group Created',
74 'visibility' => 'Public Pages',
77 $this->_groupId2
=> array(
78 'title' => 'New Test Group2 Created',
79 'visibility' => 'User and User Admin Only',
85 ///////////////// civicrm_group_contact_get methods
88 * Test GroupContact.get by ID.
90 public function testGet() {
92 'contact_id' => $this->_contactId
,
94 $result = $this->callAPIAndDocument('group_contact', 'get', $params, __FUNCTION__
, __FILE__
);
95 foreach ($result['values'] as $v) {
96 $this->assertEquals($v['title'], $this->_group
[$v['group_id']]['title']);
97 $this->assertEquals($v['visibility'], $this->_group
[$v['group_id']]['visibility']);
98 $this->assertEquals($v['in_method'], $this->_group
[$v['group_id']]['in_method']);
102 public function testGetGroupID() {
103 $description = "Get all from group and display contacts";
104 $subfile = "GetWithGroupID";
106 'group_id' => $this->_groupId1
,
107 'api.group.get' => 1,
110 $result = $this->callAPIAndDocument('group_contact', 'get', $params, __FUNCTION__
, __FILE__
, $description, $subfile);
111 foreach ($result['values'][0]['api.group.get']['values'] as $values) {
112 $key = $values['id'];
113 $this->assertEquals($values['title'], $this->_group
[$key]['title']);
114 $this->assertEquals($values['visibility'], $this->_group
[$key]['visibility']);
118 public function testCreateWithEmptyParams() {
120 $groups = $this->callAPIFailure('group_contact', 'create', $params);
121 $this->assertEquals($groups['error_message'],
122 'Mandatory key(s) missing from params array: group_id, contact_id'
126 public function testCreateWithoutGroupIdParams() {
128 'contact_id' => $this->_contactId
,
131 $groups = $this->callAPIFailure('group_contact', 'create', $params);
132 $this->assertEquals($groups['error_message'], 'Mandatory key(s) missing from params array: group_id');
135 public function testCreateWithoutContactIdParams() {
137 'group_id' => $this->_groupId1
,
139 $groups = $this->callAPIFailure('group_contact', 'create', $params);
140 $this->assertEquals($groups['error_message'], 'Mandatory key(s) missing from params array: contact_id');
143 public function testCreate() {
145 'first_name' => 'Amiteshwar',
146 'middle_name' => 'L.',
147 'last_name' => 'Prasad',
150 'email' => 'amiteshwar.prasad@civicrm.org',
151 'contact_type' => 'Individual',
154 $this->_contactId1
= $this->individualCreate($cont);
156 'contact_id' => $this->_contactId
,
157 'contact_id.2' => $this->_contactId1
,
158 'group_id' => $this->_groupId1
,
161 $result = $this->callAPIAndDocument('group_contact', 'create', $params, __FUNCTION__
, __FILE__
);
162 $this->assertEquals($result['not_added'], 1, "in line " . __LINE__
);
163 $this->assertEquals($result['added'], 1, "in line " . __LINE__
);
164 $this->assertEquals($result['total_count'], 2, "in line " . __LINE__
);
167 ///////////////// civicrm_group_contact_remove methods
170 * Test GroupContact.delete by contact+group ID.
172 public function testDelete() {
174 'contact_id' => $this->_contactId
,
175 'group_id' => $this->_groupId1
,
178 $result = $this->callAPIAndDocument('group_contact', 'delete', $params, __FUNCTION__
, __FILE__
);
179 $this->assertEquals($result['removed'], 1, "in line " . __LINE__
);
180 $this->assertEquals($result['total_count'], 1, "in line " . __LINE__
);
183 public function testDeletePermanent() {
184 $result = $this->callAPISuccess('group_contact', 'get', array('contact_id' => $this->_contactId
));
186 'id' => $result['id'],
187 'skip_undelete' => TRUE,
189 $this->callAPIAndDocument('group_contact', 'delete', $params, __FUNCTION__
, __FILE__
);
190 $result = $this->callAPISuccess('group_contact', 'get', $params);
191 $this->assertEquals(0, $result['count'], "in line " . __LINE__
);
192 $this->assertArrayNotHasKey('id', $result, "in line " . __LINE__
);