3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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 +--------------------------------------------------------------------+
28 require_once 'CiviTest/CiviUnitTestCase.php';
31 * Test class for Group API - civicrm_group_*
33 * @package CiviCRM_APIv3
36 class api_v3_GroupTest
extends CiviUnitTestCase
{
37 protected $_apiversion;
39 public $_eNoticeCompliant = True;
43 'name' => 'Group Get',
44 'description' => 'Test all Group Get API methods.',
45 'group' => 'CiviCRM API Tests',
50 $this->_apiversion
= 3;
53 $this->_groupID
= $this->groupCreate(NULL, 3);
58 $this->groupDelete($this->_groupID
);
61 function testgroupCreateEmptyParams() {
63 $group = civicrm_api('group', 'create', $params);
64 $this->assertEquals($group['error_message'], 'Mandatory key(s) missing from params array: version, title');
67 function testgroupCreateNoTitle() {
69 'name' => 'Test Group No title ',
71 'description' => 'New Test Group Created',
73 'visibility' => 'Public Pages',
74 'group_type' => array(
80 $group = civicrm_api('group', 'create', $params);
81 $this->assertEquals($group['error_message'], 'Mandatory key(s) missing from params array: version, title');
84 function testGetGroupEmptyParams() {
86 $group = civicrm_api('group', 'get', $params);
88 $this->assertEquals($group['error_message'], 'Input variable `params` is not an array');
91 function testGetGroupWithEmptyParams() {
92 $params = array('version' => $this->_apiversion
);
94 $group = civicrm_api('group', 'get', $params);
96 $group = $group["values"];
97 $this->assertNotNull(count($group));
98 $this->assertEquals($group[$this->_groupID
]['name'], "Test Group 1_{$this->_groupID}");
99 $this->assertEquals($group[$this->_groupID
]['is_active'], 1);
100 $this->assertEquals($group[$this->_groupID
]['visibility'], 'Public Pages');
103 function testGetGroupParamsWithGroupId() {
104 $params = array('version' => $this->_apiversion
);
105 $params['id'] = $this->_groupID
;
106 $group = civicrm_api('group', 'get', $params);
108 foreach ($group['values'] as $v) {
109 $this->assertEquals($v['name'], "Test Group 1_{$this->_groupID}");
110 $this->assertEquals($v['title'], 'New Test Group Created');
111 $this->assertEquals($v['description'], 'New Test Group Created');
112 $this->assertEquals($v['is_active'], 1);
113 $this->assertEquals($v['visibility'], 'Public Pages');
117 function testGetGroupParamsWithGroupName() {
118 $params = array('version' => $this->_apiversion
);
119 $params['name'] = "Test Group 1_{$this->_groupID}";
120 $group = civicrm_api('group', 'get', $params);
121 $this->documentMe($params, $group, __FUNCTION__
, __FILE__
);
122 $group = $group['values'];
124 foreach ($group as $v) {
125 $this->assertEquals($v['id'], $this->_groupID
);
126 $this->assertEquals($v['title'], 'New Test Group Created');
127 $this->assertEquals($v['description'], 'New Test Group Created');
128 $this->assertEquals($v['is_active'], 1);
129 $this->assertEquals($v['visibility'], 'Public Pages');
133 function testGetGroupParamsWithReturnName() {
134 $params = array('version' => $this->_apiversion
);
135 $params['id'] = $this->_groupID
;
136 $params['return.name'] = 1;
137 $group = civicrm_api('group', 'get', $params);
138 $this->assertEquals($group['values'][$this->_groupID
]['name'],
139 "Test Group 1_{$this->_groupID}"
143 function testGetGroupParamsWithGroupTitle() {
144 $params = array('version' => $this->_apiversion
);
145 $params['title'] = 'New Test Group Created';
146 $group = civicrm_api('group', 'get', $params);
148 foreach ($group['values'] as $v) {
149 $this->assertEquals($v['id'], $this->_groupID
);
150 $this->assertEquals($v['name'], "Test Group 1_{$this->_groupID}");
151 $this->assertEquals($v['description'], 'New Test Group Created');
152 $this->assertEquals($v['is_active'], 1);
153 $this->assertEquals($v['visibility'], 'Public Pages');
157 function testGetNonExistingGroup() {
158 $params = array('version' => $this->_apiversion
);
159 $params['title'] = 'No such group Exist';
160 $group = civicrm_api('group', 'get', $params);
161 $this->assertEquals(0, $group['is_error']);
164 function testgroupdeleteNonArrayParams() {
165 $params = 'TestNotArray';
166 $group = civicrm_api('group', 'delete', $params);
167 $this->assertEquals($group['error_message'], 'Input variable `params` is not an array');
170 function testgroupdeleteParamsnoId() {
172 $group = civicrm_api('group', 'delete', $params);
173 $this->assertEquals($group['error_message'], 'Mandatory key(s) missing from params array: version, id');
176 function testgetfields() {
177 $description = "demonstrate use of getfields to interogate api";
178 $params = array('version' => 3, 'action' => 'create');
179 $result = civicrm_api('group', 'getfields', $params);
180 $this->documentMe($params, $result, __FUNCTION__
, __FILE__
, $description, 'getfields', 'getfields');
181 $this->assertEquals(1, $result['values']['is_active']['api.default']);