3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
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 GroupNesting API - civicrm_group_nesting_*
34 class api_v3_GroupNestingTest
extends CiviUnitTestCase
{
37 * Sets up the fixture, for example, opens a network connection.
39 * This method is called before a test is executed.
41 protected function setUp() {
44 $this->ids
['Group'] = [];
45 $this->ids
['Group']['parent'] = $this->callAPISuccess('Group', 'create', [
46 'name' => 'Administrators',
47 'title' => 'Administrators',
49 $this->ids
['Group']['child'] = $this->callAPISuccess('Group', 'create', [
50 'name' => 'Newsletter Subscribers',
51 'title' => 'Newsletter Subscribers',
52 'parents' => $this->ids
['Group']['parent'],
54 $this->ids
['Group']['child2'] = $this->callAPISuccess('Group', 'create', [
55 'name' => 'Another Newsletter Subscribers',
56 'title' => 'Another Newsletter Subscribers',
57 'parents' => $this->ids
['Group']['parent'],
59 $this->ids
['Group']['child3'] = $this->callAPISuccess('Group', 'create', [
60 'name' => 'Super Special Newsletter Subscribers',
61 'title' => 'Super Special Newsletter Subscribers',
62 'parents' => [$this->ids
['Group']['parent'], $this->ids
['Group']['child']],
68 * Tears down the fixture.
70 * This method is called after a test is executed.
74 protected function tearDown() {
78 'civicrm_group_nesting',
89 * Test civicrm_group_nesting_get.
91 * @dataProvider versionThreeAndFour
93 public function testGet() {
95 'parent_group_id' => $this->ids
['Group']['parent'],
96 'child_group_id' => $this->ids
['Group']['child'],
99 $result = $this->callAPIAndDocument('group_nesting', 'get', $params, __FUNCTION__
, __FILE__
);
103 'child_group_id' => $this->ids
['Group']['child'],
104 'parent_group_id' => $this->ids
['Group']['parent'],
108 $this->assertEquals($expected, $result['values']);
112 * Test civicrm_group_nesting_get with just one param (child_group_id).
114 * @dataProvider versionThreeAndFour
116 public function testGetWithChildGroupId() {
118 'child_group_id' => $this->ids
['Group']['child3'],
121 $result = $this->callAPISuccess('group_nesting', 'get', $params);
123 // expected data loaded in setUp
127 'child_group_id' => $this->ids
['Group']['child3'],
128 'parent_group_id' => $this->ids
['Group']['parent'],
132 'child_group_id' => $this->ids
['Group']['child3'],
133 'parent_group_id' => $this->ids
['Group']['child'],
137 $this->assertEquals($expected, $result['values']);
141 * Test civicrm_group_nesting_get with just one param (parent_group_id).
143 * @dataProvider versionThreeAndFour
145 public function testGetWithParentGroupId() {
147 'parent_group_id' => $this->ids
['Group']['parent'],
150 $result = $this->callAPISuccess('group_nesting', 'get', $params);
152 // expected data loaded in setUp
156 'child_group_id' => $this->ids
['Group']['child'],
157 'parent_group_id' => $this->ids
['Group']['parent'],
161 'child_group_id' => $this->ids
['Group']['child2'],
162 'parent_group_id' => $this->ids
['Group']['parent'],
166 'child_group_id' => $this->ids
['Group']['child3'],
167 'parent_group_id' => $this->ids
['Group']['parent'],
171 $this->assertEquals($expected, $result['values']);
175 * Test civicrm_group_nesting_get for no records results.
177 * Success expected. (these tests are of marginal value as are in syntax conformance,
178 * don't copy & paste.
180 * @dataProvider versionThreeAndFour
182 public function testGetEmptyResults() {
184 'parent_group_id' => $this->ids
['Group']['parent'],
185 'child_group_id' => 700,
187 $this->callAPISuccess('group_nesting', 'get', $params);
191 * Test civicrm_group_nesting_create.
195 * @dataProvider versionThreeAndFour
197 public function testCreate() {
199 'parent_group_id' => $this->ids
['Group']['parent'],
200 'child_group_id' => $this->ids
['Group']['child2'],
203 $this->callAPIAndDocument('group_nesting', 'create', $params, __FUNCTION__
, __FILE__
);
204 $this->callAPISuccessGetCount('GroupNesting', $params, 1);
208 * Test civicrm_group_nesting_remove.
210 * @dataProvider versionThreeAndFour
212 public function testDelete() {
214 'parent_group_id' => $this->ids
['Group']['parent'],
215 'child_group_id' => $this->ids
['Group']['child'],
218 $result = $this->callAPISuccess('group_nesting', 'get', $params);
219 $params = ['id' => $result['id']];
220 $this->callAPIAndDocument('group_nesting', 'delete', $params, __FUNCTION__
, __FILE__
);
221 $this->assertEquals(0, $this->callAPISuccess('group_nesting', 'getcount', $params));
225 * Test civicrm_group_nesting_remove with empty parameter array.
229 * @dataProvider versionThreeAndFour
231 public function testDeleteWithEmptyParams() {
232 $this->callAPIFailure('group_nesting', 'delete', []);