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;
40 'name' => 'Group Contact Create',
41 'description' => 'Test all Group Contact Create API methods.',
42 'group' => 'CiviCRM API Tests',
47 * Set up for group contact tests
49 * @todo set up calls function that doesn't work @ the moment
54 $this->_contactId
= $this->individualCreate();
56 $this->_groupId1
= $this->groupCreate(NULL);
58 'contact_id' => $this->_contactId
,
59 'group_id' => $this->_groupId1
,
62 $result = $this->callAPISuccess('group_contact', 'create', $params);
65 'name' => 'Test Group 2',
67 'title' => 'New Test Group2 Created',
68 'description' => 'New Test Group2 Created',
70 'visibility' => 'User and User Admin Only',
73 $this->_groupId2
= $this->groupCreate();
75 'contact_id.1' => $this->_contactId
,
76 'group_id' => $this->_groupId2
,
79 $this->_group
= array(
80 $this->_groupId1
=> array('title' => 'New Test Group Created',
81 'visibility' => 'Public Pages',
84 $this->_groupId2
=> array(
85 'title' => 'New Test Group2 Created',
86 'visibility' => 'User and User Admin Only',
93 $tablesToTruncate = array(
97 $this->quickCleanup($tablesToTruncate);
100 ///////////////// civicrm_group_contact_get methods
103 'contact_id' => $this->_contactId
,
105 $result = $this->callAPIAndDocument('group_contact', 'get', $params, __FUNCTION__
, __FILE__
);
106 foreach ($result['values'] as $v) {
107 $this->assertEquals($v['title'], $this->_group
[$v['group_id']]['title']);
108 $this->assertEquals($v['visibility'], $this->_group
[$v['group_id']]['visibility']);
109 $this->assertEquals($v['in_method'], $this->_group
[$v['group_id']]['in_method']);
113 function testGetGroupID() {
114 $description = "Get all from group and display contacts";
115 $subfile = "GetWithGroupID";
117 'group_id' => $this->_groupId1
,
118 'api.group.get' => 1,
121 $result = $this->callAPIAndDocument('group_contact', 'get', $params, __FUNCTION__
, __FILE__
, $description, $subfile);
122 foreach ($result['values'][0]['api.group.get']['values'] as $values) {
123 $key = $values['id'];
124 $this->assertEquals($values['title'], $this->_group
[$key]['title']);
125 $this->assertEquals($values['visibility'], $this->_group
[$key]['visibility']);
129 function testCreateWithEmptyParams() {
131 $groups = $this->callAPIFailure('group_contact', 'create', $params);
132 $this->assertEquals($groups['error_message'],
133 'Mandatory key(s) missing from params array: group_id, contact_id'
137 function testCreateWithoutGroupIdParams() {
139 'contact_id' => $this->_contactId
, );
141 $groups = $this->callAPIFailure('group_contact', 'create', $params);
142 $this->assertEquals($groups['error_message'], 'Mandatory key(s) missing from params array: group_id');
145 function testCreateWithoutContactIdParams() {
147 'group_id' => $this->_groupId1
, );
148 $groups = $this->callAPIFailure('group_contact', 'create', $params);
149 $this->assertEquals($groups['error_message'], 'Mandatory key(s) missing from params array: contact_id');
152 function testCreate() {
154 'first_name' => 'Amiteshwar',
155 'middle_name' => 'L.',
156 'last_name' => 'Prasad',
159 'email' => 'amiteshwar.prasad@civicrm.org',
160 'contact_type' => 'Individual', );
162 $this->_contactId1
= $this->individualCreate($cont);
164 'contact_id' => $this->_contactId
,
165 'contact_id.2' => $this->_contactId1
,
166 'group_id' => $this->_groupId1
,
169 $result = $this->callAPIAndDocument('group_contact', 'create', $params, __FUNCTION__
, __FILE__
);
170 $this->assertEquals($result['not_added'], 1, "in line " . __LINE__
);
171 $this->assertEquals($result['added'], 1, "in line " . __LINE__
);
172 $this->assertEquals($result['total_count'], 2, "in line " . __LINE__
);
175 ///////////////// civicrm_group_contact_remove methods
176 function testDelete() {
178 'contact_id' => $this->_contactId
,
182 $result = $this->callAPIAndDocument('group_contact', 'delete', $params, __FUNCTION__
, __FILE__
);
183 $this->assertEquals($result['removed'], 1, "in line " . __LINE__
);
184 $this->assertEquals($result['total_count'], 1, "in line " . __LINE__
);