Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 TO |
2 | /* |
3 | +--------------------------------------------------------------------+ | |
81621fee | 4 | | CiviCRM version 4.7 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
8c9251b3 | 6 | | Copyright CiviCRM LLC (c) 2004-2018 | |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 | 27 | |
6a488035 TO |
28 | /** |
29 | * Test class for GroupNesting API - civicrm_group_nesting_* | |
30 | * | |
6c6e6187 | 31 | * @package CiviCRM |
acb109b7 | 32 | * @group headless |
6a488035 TO |
33 | */ |
34 | class api_v3_GroupNestingTest extends CiviUnitTestCase { | |
35 | protected $_apiversion; | |
6a488035 TO |
36 | |
37 | /** | |
38 | * Sets up the fixture, for example, opens a network connection. | |
39 | * This method is called before a test is executed. | |
6a488035 TO |
40 | */ |
41 | protected function setUp() { | |
42 | $this->_apiversion = 3; | |
43 | parent::setUp(); | |
44 | ||
45 | // Insert a row in civicrm_group creating option group | |
46 | // from_email_address group | |
47 | $op = new PHPUnit_Extensions_Database_Operation_Insert(); | |
48 | $op->execute($this->_dbconn, | |
bbfd46a5 | 49 | $this->createXMLDataSet( |
6a488035 TO |
50 | dirname(__FILE__) . '/dataset/group_admins.xml' |
51 | ) | |
52 | ); | |
53 | ||
54 | // Insert a row in civicrm_group creating option group | |
55 | // from_email_address group | |
56 | $op = new PHPUnit_Extensions_Database_Operation_Insert(); | |
57 | $op->execute($this->_dbconn, | |
bbfd46a5 | 58 | $this->createXMLDataSet( |
6a488035 TO |
59 | dirname(__FILE__) . '/dataset/group_subscribers.xml' |
60 | ) | |
61 | ); | |
62 | ||
63 | // Insert a row in civicrm_group creating option group | |
64 | // from_email_address group | |
65 | $op = new PHPUnit_Extensions_Database_Operation_Insert(); | |
66 | $op->execute($this->_dbconn, | |
bbfd46a5 | 67 | $this->createXMLDataSet( |
6a488035 TO |
68 | dirname(__FILE__) . '/dataset/group_nesting.xml' |
69 | ) | |
70 | ); | |
71 | } | |
72 | ||
73 | /** | |
74 | * Tears down the fixture, for example, closes a network connection. | |
75 | * This method is called after a test is executed. | |
6a488035 TO |
76 | */ |
77 | protected function tearDown() { | |
78 | // Truncate the tables | |
79 | $this->quickCleanup( | |
80 | array( | |
81 | 'civicrm_group', | |
82 | 'civicrm_group_nesting', | |
83 | 'civicrm_contact', | |
84 | 'civicrm_uf_group', | |
85 | 'civicrm_uf_join', | |
86 | 'civicrm_uf_match', | |
87 | ) | |
88 | ); | |
89 | } | |
90 | ||
91 | ///////////////// civicrm_group_nesting_get methods | |
92 | ||
93 | /** | |
94 | * Test civicrm_group_nesting_get. | |
95 | */ | |
96 | public function testGet() { | |
97 | $params = array( | |
98 | 'parent_group_id' => 1, | |
99 | 'child_group_id' => 2, | |
6a488035 TO |
100 | ); |
101 | ||
f3e19c4e | 102 | $result = $this->callAPIAndDocument('group_nesting', 'get', $params, __FUNCTION__, __FILE__); |
6a488035 TO |
103 | // expected data loaded in setUp |
104 | $expected = array( | |
6c6e6187 | 105 | 1 => array( |
92915c55 | 106 | 'id' => 1, |
6a488035 TO |
107 | 'child_group_id' => 2, |
108 | 'parent_group_id' => 1, | |
8d7a9d07 | 109 | ), |
92915c55 | 110 | ); |
6a488035 TO |
111 | |
112 | $this->assertEquals($expected, $result['values']); | |
113 | } | |
114 | ||
115 | /** | |
116 | * Test civicrm_group_nesting_get with just one | |
117 | * param (child_group_id). | |
118 | */ | |
119 | public function testGetWithChildGroupId() { | |
120 | $params = array( | |
92915c55 TO |
121 | 'child_group_id' => 4, |
122 | ); | |
6a488035 | 123 | |
f3e19c4e | 124 | $result = $this->callAPISuccess('group_nesting', 'get', $params); |
6a488035 TO |
125 | |
126 | // expected data loaded in setUp | |
127 | $expected = array( | |
6c6e6187 | 128 | 3 => array( |
92915c55 | 129 | 'id' => 3, |
6a488035 TO |
130 | 'child_group_id' => 4, |
131 | 'parent_group_id' => 1, | |
132 | ), | |
133 | 4 => array( | |
134 | 'id' => 4, | |
135 | 'child_group_id' => 4, | |
136 | 'parent_group_id' => 2, | |
137 | ), | |
138 | ); | |
139 | ||
140 | $this->assertEquals($expected, $result['values']); | |
141 | } | |
142 | ||
143 | /** | |
144 | * Test civicrm_group_nesting_get with just one | |
145 | * param (parent_group_id). | |
146 | */ | |
147 | public function testGetWithParentGroupId() { | |
148 | $params = array( | |
92915c55 TO |
149 | 'parent_group_id' => 1, |
150 | ); | |
6a488035 | 151 | |
f3e19c4e | 152 | $result = $this->callAPISuccess('group_nesting', 'get', $params); |
6a488035 TO |
153 | |
154 | // expected data loaded in setUp | |
155 | $expected = array( | |
6c6e6187 | 156 | 1 => array( |
92915c55 | 157 | 'id' => 1, |
6a488035 TO |
158 | 'child_group_id' => 2, |
159 | 'parent_group_id' => 1, | |
160 | ), | |
161 | 2 => array( | |
162 | 'id' => 2, | |
163 | 'child_group_id' => 3, | |
164 | 'parent_group_id' => 1, | |
165 | ), | |
166 | 3 => array( | |
167 | 'id' => 3, | |
168 | 'child_group_id' => 4, | |
169 | 'parent_group_id' => 1, | |
170 | ), | |
171 | ); | |
172 | ||
173 | $this->assertEquals($expected, $result['values']); | |
174 | } | |
175 | ||
176 | /** | |
177 | * Test civicrm_group_nesting_get for no records results. | |
f3e19c4e | 178 | * Success expected. (these tests are of marginal value as are in syntax conformance, |
179 | * don't copy & paste | |
6a488035 TO |
180 | */ |
181 | public function testGetEmptyResults() { | |
6a488035 TO |
182 | $params = array( |
183 | 'parent_group_id' => 1, | |
184 | 'child_group_id' => 700, | |
185 | ); | |
4b31f991 | 186 | $this->callAPISuccess('group_nesting', 'get', $params); |
6a488035 TO |
187 | } |
188 | ||
189 | ///////////////// civicrm_group_nesting_create methods | |
190 | ||
191 | /** | |
192 | * Test civicrm_group_nesting_create. | |
193 | */ | |
194 | public function testCreate() { | |
195 | // groups id=1 and id=2 loaded in setUp | |
196 | $params = array( | |
197 | 'parent_group_id' => 1, | |
198 | 'child_group_id' => 3, | |
6a488035 TO |
199 | ); |
200 | ||
4b31f991 | 201 | $this->callAPIAndDocument('group_nesting', 'create', $params, __FUNCTION__, __FILE__); |
202 | $this->callAPISuccessGetCount('GroupNesting', $params, 1); | |
6a488035 TO |
203 | } |
204 | ||
6a488035 TO |
205 | /** |
206 | * Test civicrm_group_nesting_remove. | |
207 | */ | |
208 | public function testDelete() { | |
209 | // groups id=1 and id=2 loaded in setUp | |
210 | $getparams = array( | |
211 | 'parent_group_id' => 1, | |
92915c55 TO |
212 | 'child_group_id' => 2, |
213 | ); | |
6a488035 | 214 | |
f3e19c4e | 215 | $result = $this->callAPISuccess('group_nesting', 'get', $getparams); |
216 | $params = array('id' => $result['id']); | |
4b31f991 | 217 | $this->callAPIAndDocument('group_nesting', 'delete', $params, __FUNCTION__, __FILE__); |
f3e19c4e | 218 | $this->assertEquals(0, $this->callAPISuccess('group_nesting', 'getcount', $getparams)); |
6a488035 TO |
219 | } |
220 | ||
221 | /** | |
222 | * Test civicrm_group_nesting_remove with empty parameter array. | |
4b31f991 | 223 | * |
6a488035 TO |
224 | * Error expected. |
225 | */ | |
226 | public function testDeleteWithEmptyParams() { | |
4b31f991 | 227 | $this->callAPIFailure('group_nesting', 'delete', array()); |
6a488035 | 228 | } |
96025800 | 229 | |
6a488035 | 230 | } |