Merge pull request #2762 from amitajgaonkar/WebtestIssues
[civicrm-core.git] / tests / phpunit / api / v3 / GroupTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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
28 require_once 'CiviTest/CiviUnitTestCase.php';
29
30 /**
31 * Test class for Group API - civicrm_group_*
32 *
33 * @package CiviCRM_APIv3
34 */
35
36 class api_v3_GroupTest extends CiviUnitTestCase {
37 protected $_apiversion;
38 protected $_groupID;
39
40 function get_info() {
41 return array(
42 'name' => 'Group Get',
43 'description' => 'Test all Group Get API methods.',
44 'group' => 'CiviCRM API Tests',
45 );
46 }
47
48 function setUp() {
49 $this->_apiversion = 3;
50
51 parent::setUp();
52 $this->_groupID = $this->groupCreate();
53 }
54
55 function tearDown() {
56
57 $this->groupDelete($this->_groupID);
58 }
59
60 function testgroupCreateNoTitle() {
61 $params = array(
62 'name' => 'Test Group No title ',
63 'domain_id' => 1,
64 'description' => 'New Test Group Created',
65 'is_active' => 1,
66 'visibility' => 'Public Pages',
67 'group_type' => array(
68 '1' => 1,
69 '2' => 1,
70 ),
71 );
72
73 $group = $this->callAPIFailure('group', 'create', $params, 'Mandatory key(s) missing from params array: title');
74 }
75
76
77 function testGetGroupWithEmptyParams() {
78 $group = $this->callAPISuccess('group', 'get', $params = array());
79
80 $group = $group["values"];
81 $this->assertNotNull(count($group));
82 $this->assertEquals($group[$this->_groupID]['name'], "Test Group 1");
83 $this->assertEquals($group[$this->_groupID]['is_active'], 1);
84 $this->assertEquals($group[$this->_groupID]['visibility'], 'Public Pages');
85 }
86
87 function testGetGroupParamsWithGroupId() {
88 $params = array('id' => $this->_groupID);
89 $group = $this->callAPISuccess('group', 'get', $params);
90
91 foreach ($group['values'] as $v) {
92 $this->assertEquals($v['name'], "Test Group 1");
93 $this->assertEquals($v['title'], 'New Test Group Created');
94 $this->assertEquals($v['description'], 'New Test Group Created');
95 $this->assertEquals($v['is_active'], 1);
96 $this->assertEquals($v['visibility'], 'Public Pages');
97 }
98 }
99
100 function testGetGroupParamsWithGroupName() {
101 $params = array(
102 'name' => "Test Group 1",
103 );
104 $group = $this->callAPIAndDocument('group', 'get', $params, __FUNCTION__, __FILE__);
105 $group = $group['values'];
106
107 foreach ($group as $v) {
108 $this->assertEquals($v['id'], $this->_groupID);
109 $this->assertEquals($v['title'], 'New Test Group Created');
110 $this->assertEquals($v['description'], 'New Test Group Created');
111 $this->assertEquals($v['is_active'], 1);
112 $this->assertEquals($v['visibility'], 'Public Pages');
113 }
114 }
115
116 function testGetGroupParamsWithReturnName() {
117 $params = array();
118 $params['id'] = $this->_groupID;
119 $params['return.name'] = 1;
120 $group = $this->callAPISuccess('group', 'get', $params);
121 $this->assertEquals($group['values'][$this->_groupID]['name'],
122 "Test Group 1"
123 );
124 }
125
126 function testGetGroupParamsWithGroupTitle() {
127 $params = array();
128 $params['title'] = 'New Test Group Created';
129 $group = $this->callAPISuccess('group', 'get', $params);
130
131 foreach ($group['values'] as $v) {
132 $this->assertEquals($v['id'], $this->_groupID);
133 $this->assertEquals($v['name'], "Test Group 1");
134 $this->assertEquals($v['description'], 'New Test Group Created');
135 $this->assertEquals($v['is_active'], 1);
136 $this->assertEquals($v['visibility'], 'Public Pages');
137 }
138 }
139
140 function testGetNonExistingGroup() {
141 $params = array();
142 $params['title'] = 'No such group Exist';
143 $group = $this->callAPISuccess('group', 'get', $params);
144 $this->assertEquals(0, $group['count']);
145 }
146
147 function testgroupdeleteParamsnoId() {
148 $group = $this->callAPIFailure('group', 'delete', array(), 'Mandatory key(s) missing from params array: id');
149 }
150
151 function testgetfields() {
152 $description = "demonstrate use of getfields to interogate api";
153 $params = array('action' => 'create');
154 $result = $this->callAPIAndDocument('group', 'getfields', $params, __FUNCTION__, __FILE__, $description, 'getfields', 'getfields');
155 $this->assertEquals(1, $result['values']['is_active']['api.default']);
156 }
157 }
158