Import from SVN (r45945, r596)
[civicrm-core.git] / tests / phpunit / api / v3 / GroupTest.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
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. |
13 | |
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. |
18 | |
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 +--------------------------------------------------------------------+
26*/
27
28require_once 'CiviTest/CiviUnitTestCase.php';
29
30/**
31 * Test class for Group API - civicrm_group_*
32 *
33 * @package CiviCRM_APIv3
34 */
35
36class api_v3_GroupTest extends CiviUnitTestCase {
37 protected $_apiversion;
38 protected $_groupID;
39 public $_eNoticeCompliant = True;
40
41 function get_info() {
42 return array(
43 'name' => 'Group Get',
44 'description' => 'Test all Group Get API methods.',
45 'group' => 'CiviCRM API Tests',
46 );
47 }
48
49 function setUp() {
50 $this->_apiversion = 3;
51
52 parent::setUp();
53 $this->_groupID = $this->groupCreate(NULL, 3);
54 }
55
56 function tearDown() {
57
58 $this->groupDelete($this->_groupID);
59 }
60
61 function testgroupCreateEmptyParams() {
62 $params = array();
63 $group = civicrm_api('group', 'create', $params);
64 $this->assertEquals($group['error_message'], 'Mandatory key(s) missing from params array: version, title');
65 }
66
67 function testgroupCreateNoTitle() {
68 $params = array(
69 'name' => 'Test Group No title ',
70 'domain_id' => 1,
71 'description' => 'New Test Group Created',
72 'is_active' => 1,
73 'visibility' => 'Public Pages',
74 'group_type' => array(
75 '1' => 1,
76 '2' => 1,
77 ),
78 );
79
80 $group = civicrm_api('group', 'create', $params);
81 $this->assertEquals($group['error_message'], 'Mandatory key(s) missing from params array: version, title');
82 }
83
84 function testGetGroupEmptyParams() {
85 $params = '';
86 $group = civicrm_api('group', 'get', $params);
87
88 $this->assertEquals($group['error_message'], 'Input variable `params` is not an array');
89 }
90
91 function testGetGroupWithEmptyParams() {
92 $params = array('version' => $this->_apiversion);
93
94 $group = civicrm_api('group', 'get', $params);
95
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');
101 }
102
103 function testGetGroupParamsWithGroupId() {
104 $params = array('version' => $this->_apiversion);
105 $params['id'] = $this->_groupID;
106 $group = civicrm_api('group', 'get', $params);
107
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');
114 }
115 }
116
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'];
123
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');
130 }
131 }
132
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}"
140 );
141 }
142
143 function testGetGroupParamsWithGroupTitle() {
144 $params = array('version' => $this->_apiversion);
145 $params['title'] = 'New Test Group Created';
146 $group = civicrm_api('group', 'get', $params);
147
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');
154 }
155 }
156
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']);
162 }
163
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');
168 }
169
170 function testgroupdeleteParamsnoId() {
171 $params = array();
172 $group = civicrm_api('group', 'delete', $params);
173 $this->assertEquals($group['error_message'], 'Mandatory key(s) missing from params array: version, id');
174 }
175
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']);
182 }
183}
184