3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2016 |
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 +--------------------------------------------------------------------+
29 * Test class for Group API - civicrm_group_*
31 * @package CiviCRM_APIv3
34 class api_v3_GroupTest
extends CiviUnitTestCase
{
35 protected $_apiversion;
38 public function setUp() {
39 $this->_apiversion
= 3;
42 $this->_groupID
= $this->groupCreate();
45 public function tearDown() {
47 $this->groupDelete($this->_groupID
);
50 public function testgroupCreateNoTitle() {
52 'name' => 'Test Group No title ',
54 'description' => 'New Test Group Created',
56 'visibility' => 'Public Pages',
57 'group_type' => array(
63 $group = $this->callAPIFailure('group', 'create', $params, 'Mandatory key(s) missing from params array: title');
67 public function testGetGroupWithEmptyParams() {
68 $group = $this->callAPISuccess('group', 'get', $params = array());
70 $group = $group["values"];
71 $this->assertNotNull(count($group));
72 $this->assertEquals($group[$this->_groupID
]['name'], "Test Group 1");
73 $this->assertEquals($group[$this->_groupID
]['is_active'], 1);
74 $this->assertEquals($group[$this->_groupID
]['visibility'], 'Public Pages');
77 public function testGetGroupParamsWithGroupId() {
78 $params = array('id' => $this->_groupID
);
79 $group = $this->callAPISuccess('group', 'get', $params);
81 foreach ($group['values'] as $v) {
82 $this->assertEquals($v['name'], "Test Group 1");
83 $this->assertEquals($v['title'], 'New Test Group Created');
84 $this->assertEquals($v['description'], 'New Test Group Created');
85 $this->assertEquals($v['is_active'], 1);
86 $this->assertEquals($v['visibility'], 'Public Pages');
90 public function testGetGroupParamsWithGroupName() {
92 'name' => "Test Group 1",
94 $group = $this->callAPIAndDocument('group', 'get', $params, __FUNCTION__
, __FILE__
);
95 $group = $group['values'];
97 foreach ($group as $v) {
98 $this->assertEquals($v['id'], $this->_groupID
);
99 $this->assertEquals($v['title'], 'New Test Group Created');
100 $this->assertEquals($v['description'], 'New Test Group Created');
101 $this->assertEquals($v['is_active'], 1);
102 $this->assertEquals($v['visibility'], 'Public Pages');
106 public function testGetGroupParamsWithReturnName() {
108 $params['id'] = $this->_groupID
;
109 $params['return.name'] = 1;
110 $group = $this->callAPISuccess('group', 'get', $params);
111 $this->assertEquals($group['values'][$this->_groupID
]['name'],
116 public function testGetGroupParamsWithGroupTitle() {
118 $params['title'] = 'New Test Group Created';
119 $group = $this->callAPISuccess('group', 'get', $params);
121 foreach ($group['values'] as $v) {
122 $this->assertEquals($v['id'], $this->_groupID
);
123 $this->assertEquals($v['name'], "Test Group 1");
124 $this->assertEquals($v['description'], 'New Test Group Created');
125 $this->assertEquals($v['is_active'], 1);
126 $this->assertEquals($v['visibility'], 'Public Pages');
130 public function testGetNonExistingGroup() {
132 $params['title'] = 'No such group Exist';
133 $group = $this->callAPISuccess('group', 'get', $params);
134 $this->assertEquals(0, $group['count']);
137 public function testgroupdeleteParamsnoId() {
138 $group = $this->callAPIFailure('group', 'delete', array(), 'Mandatory key(s) missing from params array: id');
141 public function testgetfields() {
142 $description = "Demonstrate use of getfields to interrogate api.";
143 $params = array('action' => 'create');
144 $result = $this->callAPIAndDocument('group', 'getfields', $params, __FUNCTION__
, __FILE__
, $description);
145 $this->assertEquals(1, $result['values']['is_active']['api.default']);