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 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
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);
66 'name' => 'Test Group 2',
68 'title' => 'New Test Group2 Created',
69 'description' => 'New Test Group2 Created',
71 'visibility' => 'User and User Admin Only',
74 $this->_groupId2
= $this->groupCreate($group, 3);
76 'contact_id.1' => $this->_contactId
,
77 'group_id' => $this->_groupId2
,
80 $this->_group
= array(
81 $this->_groupId1
=> array('title' => 'New Test Group Created',
82 'visibility' => 'Public Pages',
85 $this->_groupId2
=> array(
86 'title' => 'New Test Group2 Created',
87 'visibility' => 'User and User Admin Only',
94 $tablesToTruncate = array(
98 $this->quickCleanup($tablesToTruncate);
101 ///////////////// civicrm_group_contact_get methods
104 'contact_id' => $this->_contactId
,
106 $result = $this->callAPIAndDocument('group_contact', 'get', $params, __FUNCTION__
, __FILE__
);
107 foreach ($result['values'] as $v) {
108 $this->assertEquals($v['title'], $this->_group
[$v['group_id']]['title']);
109 $this->assertEquals($v['visibility'], $this->_group
[$v['group_id']]['visibility']);
110 $this->assertEquals($v['in_method'], $this->_group
[$v['group_id']]['in_method']);
114 function testGetGroupID() {
115 $description = "Get all from group and display contacts";
116 $subfile = "GetWithGroupID";
118 'group_id' => $this->_groupId1
,
119 'api.group.get' => 1,
122 $result = $this->callAPIAndDocument('group_contact', 'get', $params, __FUNCTION__
, __FILE__
, $description, $subfile);
123 foreach ($result['values'][0]['api.group.get']['values'] as $values) {
124 $key = $values['id'];
125 $this->assertEquals($values['title'], $this->_group
[$key]['title']);
126 $this->assertEquals($values['visibility'], $this->_group
[$key]['visibility']);
130 function testCreateWithEmptyParams() {
132 $groups = $this->callAPIFailure('group_contact', 'create', $params);
133 $this->assertEquals($groups['error_message'],
134 'Mandatory key(s) missing from params array: group_id, contact_id'
138 function testCreateWithoutGroupIdParams() {
140 'contact_id' => $this->_contactId
, );
142 $groups = $this->callAPIFailure('group_contact', 'create', $params);
143 $this->assertEquals($groups['error_message'], 'Mandatory key(s) missing from params array: group_id');
146 function testCreateWithoutContactIdParams() {
148 'group_id' => $this->_groupId1
, );
149 $groups = $this->callAPIFailure('group_contact', 'create', $params);
150 $this->assertEquals($groups['error_message'], 'Mandatory key(s) missing from params array: contact_id');
153 function testCreate() {
155 'first_name' => 'Amiteshwar',
156 'middle_name' => 'L.',
157 'last_name' => 'Prasad',
160 'email' => 'amiteshwar.prasad@civicrm.org',
161 'contact_type' => 'Individual', );
163 $this->_contactId1
= $this->individualCreate($cont);
165 'contact_id' => $this->_contactId
,
166 'contact_id.2' => $this->_contactId1
,
167 'group_id' => $this->_groupId1
,
170 $result = $this->callAPIAndDocument('group_contact', 'create', $params, __FUNCTION__
, __FILE__
);
171 $this->assertEquals($result['not_added'], 1, "in line " . __LINE__
);
172 $this->assertEquals($result['added'], 1, "in line " . __LINE__
);
173 $this->assertEquals($result['total_count'], 2, "in line " . __LINE__
);
176 ///////////////// civicrm_group_contact_remove methods
177 function testDelete() {
179 'contact_id' => $this->_contactId
,
183 $result = $this->callAPIAndDocument('group_contact', 'delete', $params, __FUNCTION__
, __FILE__
);
184 $this->assertEquals($result['removed'], 1, "in line " . __LINE__
);
185 $this->assertEquals($result['total_count'], 1, "in line " . __LINE__
);