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
86 public function testGet() {
88 'contact_id' => $this->_contactId
,
90 $result = $this->callAPIAndDocument('group_contact', 'get', $params, __FUNCTION__
, __FILE__
);
91 foreach ($result['values'] as $v) {
92 $this->assertEquals($v['title'], $this->_group
[$v['group_id']]['title']);
93 $this->assertEquals($v['visibility'], $this->_group
[$v['group_id']]['visibility']);
94 $this->assertEquals($v['in_method'], $this->_group
[$v['group_id']]['in_method']);
98 public function testGetGroupID() {
99 $description = "Get all from group and display contacts";
100 $subfile = "GetWithGroupID";
102 'group_id' => $this->_groupId1
,
103 'api.group.get' => 1,
106 $result = $this->callAPIAndDocument('group_contact', 'get', $params, __FUNCTION__
, __FILE__
, $description, $subfile);
107 foreach ($result['values'][0]['api.group.get']['values'] as $values) {
108 $key = $values['id'];
109 $this->assertEquals($values['title'], $this->_group
[$key]['title']);
110 $this->assertEquals($values['visibility'], $this->_group
[$key]['visibility']);
114 public function testCreateWithEmptyParams() {
116 $groups = $this->callAPIFailure('group_contact', 'create', $params);
117 $this->assertEquals($groups['error_message'],
118 'Mandatory key(s) missing from params array: group_id, contact_id'
122 public function testCreateWithoutGroupIdParams() {
124 'contact_id' => $this->_contactId
,
127 $groups = $this->callAPIFailure('group_contact', 'create', $params);
128 $this->assertEquals($groups['error_message'], 'Mandatory key(s) missing from params array: group_id');
131 public function testCreateWithoutContactIdParams() {
133 'group_id' => $this->_groupId1
,
135 $groups = $this->callAPIFailure('group_contact', 'create', $params);
136 $this->assertEquals($groups['error_message'], 'Mandatory key(s) missing from params array: contact_id');
139 public function testCreate() {
141 'first_name' => 'Amiteshwar',
142 'middle_name' => 'L.',
143 'last_name' => 'Prasad',
146 'email' => 'amiteshwar.prasad@civicrm.org',
147 'contact_type' => 'Individual',
150 $this->_contactId1
= $this->individualCreate($cont);
152 'contact_id' => $this->_contactId
,
153 'contact_id.2' => $this->_contactId1
,
154 'group_id' => $this->_groupId1
,
157 $result = $this->callAPIAndDocument('group_contact', 'create', $params, __FUNCTION__
, __FILE__
);
158 $this->assertEquals($result['not_added'], 1, "in line " . __LINE__
);
159 $this->assertEquals($result['added'], 1, "in line " . __LINE__
);
160 $this->assertEquals($result['total_count'], 2, "in line " . __LINE__
);
163 ///////////////// civicrm_group_contact_remove methods
164 public function testDelete() {
166 'contact_id' => $this->_contactId
,
167 'group_id' => $this->_groupId1
,
170 $result = $this->callAPIAndDocument('group_contact', 'delete', $params, __FUNCTION__
, __FILE__
);
171 $this->assertEquals($result['removed'], 1, "in line " . __LINE__
);
172 $this->assertEquals($result['total_count'], 1, "in line " . __LINE__
);
175 public function testDeletePermanent() {
176 $result = $this->callAPISuccess('group_contact', 'get', array('contact_id' => $this->_contactId
));
178 'id' => $result['id'],
179 'skip_undelete' => TRUE,
181 $this->callAPIAndDocument('group_contact', 'delete', $params, __FUNCTION__
, __FILE__
);
182 $result = $this->callAPISuccess('group_contact', 'get', $params);
183 $this->assertEquals(0, $result['count'], "in line " . __LINE__
);
184 $this->assertArrayNotHasKey('id', $result, "in line " . __LINE__
);