Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06a1bc01 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
6a488035 TO |
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 | * | |
6c6e6187 | 33 | * @package CiviCRM_APIv3 |
6a488035 TO |
34 | */ |
35 | ||
36 | class api_v3_GroupTest extends CiviUnitTestCase { | |
37 | protected $_apiversion; | |
38 | protected $_groupID; | |
6a488035 | 39 | |
00be9182 | 40 | public function setUp() { |
6a488035 TO |
41 | $this->_apiversion = 3; |
42 | ||
43 | parent::setUp(); | |
fadb804f | 44 | $this->_groupID = $this->groupCreate(); |
6a488035 TO |
45 | } |
46 | ||
00be9182 | 47 | public function tearDown() { |
6a488035 TO |
48 | |
49 | $this->groupDelete($this->_groupID); | |
50 | } | |
51 | ||
00be9182 | 52 | public function testgroupCreateNoTitle() { |
6a488035 TO |
53 | $params = array( |
54 | 'name' => 'Test Group No title ', | |
55 | 'domain_id' => 1, | |
56 | 'description' => 'New Test Group Created', | |
57 | 'is_active' => 1, | |
58 | 'visibility' => 'Public Pages', | |
59 | 'group_type' => array( | |
60 | '1' => 1, | |
61 | '2' => 1, | |
62 | ), | |
63 | ); | |
64 | ||
b26e776b | 65 | $group = $this->callAPIFailure('group', 'create', $params, 'Mandatory key(s) missing from params array: title'); |
6a488035 TO |
66 | } |
67 | ||
6a488035 | 68 | |
00be9182 | 69 | public function testGetGroupWithEmptyParams() { |
b26e776b | 70 | $group = $this->callAPISuccess('group', 'get', $params = array()); |
6a488035 TO |
71 | |
72 | $group = $group["values"]; | |
73 | $this->assertNotNull(count($group)); | |
5667b84b | 74 | $this->assertEquals($group[$this->_groupID]['name'], "Test Group 1"); |
6a488035 TO |
75 | $this->assertEquals($group[$this->_groupID]['is_active'], 1); |
76 | $this->assertEquals($group[$this->_groupID]['visibility'], 'Public Pages'); | |
77 | } | |
78 | ||
00be9182 | 79 | public function testGetGroupParamsWithGroupId() { |
b26e776b | 80 | $params = array('id' => $this->_groupID); |
81 | $group = $this->callAPISuccess('group', 'get', $params); | |
6a488035 TO |
82 | |
83 | foreach ($group['values'] as $v) { | |
5667b84b | 84 | $this->assertEquals($v['name'], "Test Group 1"); |
6a488035 TO |
85 | $this->assertEquals($v['title'], 'New Test Group Created'); |
86 | $this->assertEquals($v['description'], 'New Test Group Created'); | |
87 | $this->assertEquals($v['is_active'], 1); | |
88 | $this->assertEquals($v['visibility'], 'Public Pages'); | |
89 | } | |
90 | } | |
91 | ||
00be9182 | 92 | public function testGetGroupParamsWithGroupName() { |
b26e776b | 93 | $params = array( |
5667b84b | 94 | 'name' => "Test Group 1", |
b26e776b | 95 | ); |
96 | $group = $this->callAPIAndDocument('group', 'get', $params, __FUNCTION__, __FILE__); | |
6a488035 TO |
97 | $group = $group['values']; |
98 | ||
99 | foreach ($group as $v) { | |
100 | $this->assertEquals($v['id'], $this->_groupID); | |
101 | $this->assertEquals($v['title'], 'New Test Group Created'); | |
102 | $this->assertEquals($v['description'], 'New Test Group Created'); | |
103 | $this->assertEquals($v['is_active'], 1); | |
104 | $this->assertEquals($v['visibility'], 'Public Pages'); | |
105 | } | |
106 | } | |
107 | ||
00be9182 | 108 | public function testGetGroupParamsWithReturnName() { |
b26e776b | 109 | $params = array(); |
6a488035 TO |
110 | $params['id'] = $this->_groupID; |
111 | $params['return.name'] = 1; | |
b26e776b | 112 | $group = $this->callAPISuccess('group', 'get', $params); |
6a488035 | 113 | $this->assertEquals($group['values'][$this->_groupID]['name'], |
5667b84b | 114 | "Test Group 1" |
6a488035 TO |
115 | ); |
116 | } | |
117 | ||
00be9182 | 118 | public function testGetGroupParamsWithGroupTitle() { |
5667b84b | 119 | $params = array(); |
6a488035 | 120 | $params['title'] = 'New Test Group Created'; |
5667b84b | 121 | $group = $this->callAPISuccess('group', 'get', $params); |
6a488035 TO |
122 | |
123 | foreach ($group['values'] as $v) { | |
124 | $this->assertEquals($v['id'], $this->_groupID); | |
5667b84b | 125 | $this->assertEquals($v['name'], "Test Group 1"); |
6a488035 TO |
126 | $this->assertEquals($v['description'], 'New Test Group Created'); |
127 | $this->assertEquals($v['is_active'], 1); | |
128 | $this->assertEquals($v['visibility'], 'Public Pages'); | |
129 | } | |
130 | } | |
131 | ||
00be9182 | 132 | public function testGetNonExistingGroup() { |
5667b84b | 133 | $params = array(); |
6a488035 | 134 | $params['title'] = 'No such group Exist'; |
5667b84b | 135 | $group = $this->callAPISuccess('group', 'get', $params); |
d0e1eff2 | 136 | $this->assertEquals(0, $group['count']); |
6a488035 TO |
137 | } |
138 | ||
00be9182 | 139 | public function testgroupdeleteParamsnoId() { |
b26e776b | 140 | $group = $this->callAPIFailure('group', 'delete', array(), 'Mandatory key(s) missing from params array: id'); |
6a488035 TO |
141 | } |
142 | ||
00be9182 | 143 | public function testgetfields() { |
9657ccf2 | 144 | $description = "demonstrate use of getfields to interrogate api"; |
5667b84b | 145 | $params = array('action' => 'create'); |
b26e776b | 146 | $result = $this->callAPIAndDocument('group', 'getfields', $params, __FUNCTION__, __FILE__, $description, 'getfields', 'getfields'); |
6a488035 TO |
147 | $this->assertEquals(1, $result['values']['is_active']['api.default']); |
148 | } | |
149 | } |