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