3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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
35 class api_v3_GroupTest
extends CiviUnitTestCase
{
36 protected $_apiversion;
39 public function setUp() {
40 $this->_apiversion
= 3;
43 $this->_groupID
= $this->groupCreate();
46 public function tearDown() {
48 $this->groupDelete($this->_groupID
);
51 public function testgroupCreateNoTitle() {
53 'name' => 'Test Group No title ',
55 'description' => 'New Test Group Created',
57 'visibility' => 'Public Pages',
58 'group_type' => array(
64 $group = $this->callAPIFailure('group', 'create', $params, 'Mandatory key(s) missing from params array: title');
68 public function testGetGroupWithEmptyParams() {
69 $group = $this->callAPISuccess('group', 'get', $params = array());
71 $group = $group["values"];
72 $this->assertNotNull(count($group));
73 $this->assertEquals($group[$this->_groupID
]['name'], "Test Group 1");
74 $this->assertEquals($group[$this->_groupID
]['is_active'], 1);
75 $this->assertEquals($group[$this->_groupID
]['visibility'], 'Public Pages');
78 public function testGetGroupParamsWithGroupId() {
79 $params = array('id' => $this->_groupID
);
80 $group = $this->callAPISuccess('group', 'get', $params);
82 foreach ($group['values'] as $v) {
83 $this->assertEquals($v['name'], "Test Group 1");
84 $this->assertEquals($v['title'], 'New Test Group Created');
85 $this->assertEquals($v['description'], 'New Test Group Created');
86 $this->assertEquals($v['is_active'], 1);
87 $this->assertEquals($v['visibility'], 'Public Pages');
91 public function testGetGroupParamsWithGroupName() {
93 'name' => "Test Group 1",
95 $group = $this->callAPIAndDocument('group', 'get', $params, __FUNCTION__
, __FILE__
);
96 $group = $group['values'];
98 foreach ($group as $v) {
99 $this->assertEquals($v['id'], $this->_groupID
);
100 $this->assertEquals($v['title'], 'New Test Group Created');
101 $this->assertEquals($v['description'], 'New Test Group Created');
102 $this->assertEquals($v['is_active'], 1);
103 $this->assertEquals($v['visibility'], 'Public Pages');
107 public function testGetGroupParamsWithReturnName() {
109 $params['id'] = $this->_groupID
;
110 $params['return.name'] = 1;
111 $group = $this->callAPISuccess('group', 'get', $params);
112 $this->assertEquals($group['values'][$this->_groupID
]['name'],
117 public function testGetGroupParamsWithGroupTitle() {
119 $params['title'] = 'New Test Group Created';
120 $group = $this->callAPISuccess('group', 'get', $params);
122 foreach ($group['values'] as $v) {
123 $this->assertEquals($v['id'], $this->_groupID
);
124 $this->assertEquals($v['name'], "Test Group 1");
125 $this->assertEquals($v['description'], 'New Test Group Created');
126 $this->assertEquals($v['is_active'], 1);
127 $this->assertEquals($v['visibility'], 'Public Pages');
132 * Test Group create with Group Type and Parent
134 public function testGroupCreateWithTypeAndParent() {
136 'name' => 'Test Group type',
137 'title' => 'Test Group Type',
138 'description' => 'Test Group with Group Type',
140 //check for empty parent
142 'visibility' => 'Public Pages',
143 'group_type' => array(1, 2),
145 $result = $this->callAPISuccess('Group', 'create', $params);
146 $group = $result['values'][$result['id']];
147 $this->assertEquals($group['name'], "Test Group type");
148 $this->assertEquals($group['is_active'], 1);
149 $this->assertEquals($group['parents'], "");
150 $this->assertEquals($group['group_type'], $params['group_type']);
151 //assert single value for group_type and parent
152 $params = array_merge($params, array(
153 'name' => 'Test Group 2',
154 'title' => 'Test Group 2',
156 'parents' => $result['id'],
159 $result = $this->callAPISuccess('Group', 'create', $params);
160 $group = $result["values"][$result['id']];
161 $this->assertEquals($group['group_type'], array($params['group_type']));
162 $this->assertEquals($group['parents'], $params['parents']);
165 public function testGetNonExistingGroup() {
167 $params['title'] = 'No such group Exist';
168 $group = $this->callAPISuccess('group', 'get', $params);
169 $this->assertEquals(0, $group['count']);
172 public function testgroupdeleteParamsnoId() {
173 $group = $this->callAPIFailure('group', 'delete', array(), 'Mandatory key(s) missing from params array: id');
176 public function testgetfields() {
177 $description = "Demonstrate use of getfields to interrogate api.";
178 $params = array('action' => 'create');
179 $result = $this->callAPIAndDocument('group', 'getfields', $params, __FUNCTION__
, __FILE__
, $description);
180 $this->assertEquals(1, $result['values']['is_active']['api.default']);
183 public function testIllegalParentsParams() {
185 'title' => 'Test illegal Group',
187 'description' => 'Testing illegal Parents params',
189 'parents' => "(SELECT api_key FROM civicrm_contact where id = 1)",
191 $this->callAPIFailure('group', 'create', $params);
192 unset($params['parents']);
193 $this->callAPISuccess('group', 'create', $params);
194 $group1 = $this->callAPISuccess('group', 'get', array(
195 'title' => 'Test illegal Group',
196 'parents' => array('IS NOT NULL' => 1),
198 $this->assertEquals(0, $group1['count']);
199 $params['title'] = 'Test illegal Group 2';
200 $params['parents'] = array();
201 $params['parents'][$this->_groupID
] = 'test Group';
202 $params['parents']["(SELECT api_key FROM civicrm_contact where id = 1)"] = "Test";
203 $group2 = $this->callAPIFailure('group', 'create', $params);
204 unset($params['parents']["(SELECT api_key FROM civicrm_contact where id = 1)"]);
205 $group2 = $this->callAPISuccess('group', 'create', $params);
206 $this->assertEquals(count($group2['values'][$group2['id']]['parents']), 1);