-
-
Notifications
You must be signed in to change notification settings - Fork 827
/
Copy pathGroupNestingTest.php
151 lines (135 loc) · 4.28 KB
/
GroupNestingTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?php
/*
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC. All rights reserved. |
| |
| This work is published under the GNU AGPLv3 license with some |
| permitted exceptions and without any warranty. For full license |
| and copyright information, see https://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
* Test class for GroupNesting API - civicrm_group_nesting_*
*
* @package CiviCRM
* @group headless
*/
class api_v3_GroupNestingTest extends CiviUnitTestCase {
/**
* Sets up the fixture, for example, opens a network connection.
*
* This method is called before a test is executed.
*/
protected function setUp(): void {
parent::setUp();
$this->ids['Group'] = [];
$this->ids['Group']['parent'] = $this->callAPISuccess('Group', 'create', [
'name' => 'Administrators',
'title' => 'Administrators',
])['id'];
$this->ids['Group']['child'] = $this->callAPISuccess('Group', 'create', [
'name' => 'Newsletter Subscribers',
'title' => 'Newsletter Subscribers',
'parents' => $this->ids['Group']['parent'],
])['id'];
$this->ids['Group']['child2'] = $this->callAPISuccess('Group', 'create', [
'name' => 'Another Newsletter Subscribers',
'title' => 'Another Newsletter Subscribers',
'parents' => $this->ids['Group']['parent'],
])['id'];
$this->ids['Group']['child3'] = $this->callAPISuccess('Group', 'create', [
'name' => 'Super Special Newsletter Subscribers',
'title' => 'Super Special Newsletter Subscribers',
'parents' => [$this->ids['Group']['parent'], $this->ids['Group']['child']],
])['id'];
}
/**
* Tears down the fixture.
*
* This method is called after a test is executed.
*
* @throws \Exception
*/
protected function tearDown(): void {
$this->quickCleanup(
[
'civicrm_group',
'civicrm_group_nesting',
'civicrm_contact',
'civicrm_uf_join',
'civicrm_uf_match',
]
);
parent::tearDown();
}
/**
* Test civicrm_group_nesting_get with just one param (child_group_id).
*
* @dataProvider versionThreeAndFour
*/
public function testGetWithChildGroupId(): void {
$params = [
'child_group_id' => $this->ids['Group']['child3'],
];
$result = $this->callAPISuccess('group_nesting', 'get', $params);
// expected data loaded in setUp
$expected = [
3 => [
'id' => 3,
'child_group_id' => $this->ids['Group']['child3'],
'parent_group_id' => $this->ids['Group']['parent'],
],
4 => [
'id' => 4,
'child_group_id' => $this->ids['Group']['child3'],
'parent_group_id' => $this->ids['Group']['child'],
],
];
$this->assertEquals($expected, $result['values']);
}
/**
* Test civicrm_group_nesting_get with just one param (parent_group_id).
*
* @dataProvider versionThreeAndFour
*/
public function testGetWithParentGroupId(): void {
$params = [
'parent_group_id' => $this->ids['Group']['parent'],
];
$result = $this->callAPISuccess('group_nesting', 'get', $params);
// expected data loaded in setUp
$expected = [
1 => [
'id' => 1,
'child_group_id' => $this->ids['Group']['child'],
'parent_group_id' => $this->ids['Group']['parent'],
],
2 => [
'id' => 2,
'child_group_id' => $this->ids['Group']['child2'],
'parent_group_id' => $this->ids['Group']['parent'],
],
3 => [
'id' => 3,
'child_group_id' => $this->ids['Group']['child3'],
'parent_group_id' => $this->ids['Group']['parent'],
],
];
$this->assertEquals($expected, $result['values']);
}
/**
* Test civicrm_group_nesting_create.
*
* @throws \Exception
*
* @dataProvider versionThreeAndFour
*/
public function testCreate(): void {
$params = [
'parent_group_id' => $this->ids['Group']['parent'],
'child_group_id' => $this->ids['Group']['child2'],
];
$this->callAPISuccess('group_nesting', 'create', $params);
$this->callAPISuccessGetCount('GroupNesting', $params, 1);
}
}