3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
13 * Test class for GroupNesting API - civicrm_group_nesting_*
18 class api_v3_GroupNestingTest
extends CiviUnitTestCase
{
21 * Sets up the fixture, for example, opens a network connection.
23 * This method is called before a test is executed.
25 protected function setUp() {
28 $this->ids
['Group'] = [];
29 $this->ids
['Group']['parent'] = $this->callAPISuccess('Group', 'create', [
30 'name' => 'Administrators',
31 'title' => 'Administrators',
33 $this->ids
['Group']['child'] = $this->callAPISuccess('Group', 'create', [
34 'name' => 'Newsletter Subscribers',
35 'title' => 'Newsletter Subscribers',
36 'parents' => $this->ids
['Group']['parent'],
38 $this->ids
['Group']['child2'] = $this->callAPISuccess('Group', 'create', [
39 'name' => 'Another Newsletter Subscribers',
40 'title' => 'Another Newsletter Subscribers',
41 'parents' => $this->ids
['Group']['parent'],
43 $this->ids
['Group']['child3'] = $this->callAPISuccess('Group', 'create', [
44 'name' => 'Super Special Newsletter Subscribers',
45 'title' => 'Super Special Newsletter Subscribers',
46 'parents' => [$this->ids
['Group']['parent'], $this->ids
['Group']['child']],
52 * Tears down the fixture.
54 * This method is called after a test is executed.
58 protected function tearDown() {
62 'civicrm_group_nesting',
73 * Test civicrm_group_nesting_get.
75 * @dataProvider versionThreeAndFour
77 public function testGet() {
79 'parent_group_id' => $this->ids
['Group']['parent'],
80 'child_group_id' => $this->ids
['Group']['child'],
83 $result = $this->callAPIAndDocument('group_nesting', 'get', $params, __FUNCTION__
, __FILE__
);
87 'child_group_id' => $this->ids
['Group']['child'],
88 'parent_group_id' => $this->ids
['Group']['parent'],
92 $this->assertEquals($expected, $result['values']);
96 * Test civicrm_group_nesting_get with just one param (child_group_id).
98 * @dataProvider versionThreeAndFour
100 public function testGetWithChildGroupId() {
102 'child_group_id' => $this->ids
['Group']['child3'],
105 $result = $this->callAPISuccess('group_nesting', 'get', $params);
107 // expected data loaded in setUp
111 'child_group_id' => $this->ids
['Group']['child3'],
112 'parent_group_id' => $this->ids
['Group']['parent'],
116 'child_group_id' => $this->ids
['Group']['child3'],
117 'parent_group_id' => $this->ids
['Group']['child'],
121 $this->assertEquals($expected, $result['values']);
125 * Test civicrm_group_nesting_get with just one param (parent_group_id).
127 * @dataProvider versionThreeAndFour
129 public function testGetWithParentGroupId() {
131 'parent_group_id' => $this->ids
['Group']['parent'],
134 $result = $this->callAPISuccess('group_nesting', 'get', $params);
136 // expected data loaded in setUp
140 'child_group_id' => $this->ids
['Group']['child'],
141 'parent_group_id' => $this->ids
['Group']['parent'],
145 'child_group_id' => $this->ids
['Group']['child2'],
146 'parent_group_id' => $this->ids
['Group']['parent'],
150 'child_group_id' => $this->ids
['Group']['child3'],
151 'parent_group_id' => $this->ids
['Group']['parent'],
155 $this->assertEquals($expected, $result['values']);
159 * Test civicrm_group_nesting_get for no records results.
161 * Success expected. (these tests are of marginal value as are in syntax conformance,
162 * don't copy & paste.
164 * @dataProvider versionThreeAndFour
166 public function testGetEmptyResults() {
168 'parent_group_id' => $this->ids
['Group']['parent'],
169 'child_group_id' => 700,
171 $this->callAPISuccess('group_nesting', 'get', $params);
175 * Test civicrm_group_nesting_create.
179 * @dataProvider versionThreeAndFour
181 public function testCreate() {
183 'parent_group_id' => $this->ids
['Group']['parent'],
184 'child_group_id' => $this->ids
['Group']['child2'],
187 $this->callAPIAndDocument('group_nesting', 'create', $params, __FUNCTION__
, __FILE__
);
188 $this->callAPISuccessGetCount('GroupNesting', $params, 1);
192 * Test civicrm_group_nesting_remove.
194 * @dataProvider versionThreeAndFour
196 public function testDelete() {
198 'parent_group_id' => $this->ids
['Group']['parent'],
199 'child_group_id' => $this->ids
['Group']['child'],
202 $result = $this->callAPISuccess('group_nesting', 'get', $params);
203 $params = ['id' => $result['id']];
204 $this->callAPIAndDocument('group_nesting', 'delete', $params, __FUNCTION__
, __FILE__
);
205 $this->assertEquals(0, $this->callAPISuccess('group_nesting', 'getcount', $params));
209 * Test civicrm_group_nesting_remove with empty parameter array.
213 * @dataProvider versionThreeAndFour
215 public function testDeleteWithEmptyParams() {
216 $this->callAPIFailure('group_nesting', 'delete', []);