Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 TO |
2 | /* |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
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 | ||
29 | require_once 'CiviTest/CiviUnitTestCase.php'; | |
30 | ||
31 | /** | |
32 | * Test class for GroupNesting API - civicrm_group_nesting_* | |
33 | * | |
34 | * @package CiviCRM | |
35 | */ | |
36 | class api_v3_GroupNestingTest extends CiviUnitTestCase { | |
37 | protected $_apiversion; | |
6a488035 TO |
38 | |
39 | /** | |
40 | * Sets up the fixture, for example, opens a network connection. | |
41 | * This method is called before a test is executed. | |
42 | * | |
43 | * @access protected | |
44 | */ | |
45 | protected function setUp() { | |
46 | $this->_apiversion = 3; | |
47 | parent::setUp(); | |
48 | ||
49 | // Insert a row in civicrm_group creating option group | |
50 | // from_email_address group | |
51 | $op = new PHPUnit_Extensions_Database_Operation_Insert(); | |
52 | $op->execute($this->_dbconn, | |
bbfd46a5 | 53 | $this->createXMLDataSet( |
6a488035 TO |
54 | dirname(__FILE__) . '/dataset/group_admins.xml' |
55 | ) | |
56 | ); | |
57 | ||
58 | // Insert a row in civicrm_group creating option group | |
59 | // from_email_address group | |
60 | $op = new PHPUnit_Extensions_Database_Operation_Insert(); | |
61 | $op->execute($this->_dbconn, | |
bbfd46a5 | 62 | $this->createXMLDataSet( |
6a488035 TO |
63 | dirname(__FILE__) . '/dataset/group_subscribers.xml' |
64 | ) | |
65 | ); | |
66 | ||
67 | // Insert a row in civicrm_group creating option group | |
68 | // from_email_address group | |
69 | $op = new PHPUnit_Extensions_Database_Operation_Insert(); | |
70 | $op->execute($this->_dbconn, | |
bbfd46a5 | 71 | $this->createXMLDataSet( |
6a488035 TO |
72 | dirname(__FILE__) . '/dataset/group_nesting.xml' |
73 | ) | |
74 | ); | |
75 | } | |
76 | ||
77 | /** | |
78 | * Tears down the fixture, for example, closes a network connection. | |
79 | * This method is called after a test is executed. | |
80 | * | |
81 | * @access protected | |
82 | */ | |
83 | protected function tearDown() { | |
84 | // Truncate the tables | |
85 | $this->quickCleanup( | |
86 | array( | |
87 | 'civicrm_group', | |
88 | 'civicrm_group_nesting', | |
89 | 'civicrm_contact', | |
90 | 'civicrm_uf_group', | |
91 | 'civicrm_uf_join', | |
92 | 'civicrm_uf_match', | |
93 | ) | |
94 | ); | |
95 | } | |
96 | ||
97 | ///////////////// civicrm_group_nesting_get methods | |
98 | ||
99 | /** | |
100 | * Test civicrm_group_nesting_get. | |
101 | */ | |
102 | public function testGet() { | |
103 | $params = array( | |
104 | 'parent_group_id' => 1, | |
105 | 'child_group_id' => 2, | |
6a488035 TO |
106 | ); |
107 | ||
f3e19c4e | 108 | $result = $this->callAPIAndDocument('group_nesting', 'get', $params, __FUNCTION__, __FILE__); |
6a488035 TO |
109 | // expected data loaded in setUp |
110 | $expected = array( | |
111 | 1 => array('id' => 1, | |
112 | 'child_group_id' => 2, | |
113 | 'parent_group_id' => 1, | |
114 | )); | |
115 | ||
116 | $this->assertEquals($expected, $result['values']); | |
117 | } | |
118 | ||
119 | /** | |
120 | * Test civicrm_group_nesting_get with just one | |
121 | * param (child_group_id). | |
122 | */ | |
123 | public function testGetWithChildGroupId() { | |
124 | $params = array( | |
f3e19c4e | 125 | 'child_group_id' => 4, ); |
6a488035 | 126 | |
f3e19c4e | 127 | $result = $this->callAPISuccess('group_nesting', 'get', $params); |
6a488035 TO |
128 | |
129 | // expected data loaded in setUp | |
130 | $expected = array( | |
131 | 3 => array('id' => 3, | |
132 | 'child_group_id' => 4, | |
133 | 'parent_group_id' => 1, | |
134 | ), | |
135 | 4 => array( | |
136 | 'id' => 4, | |
137 | 'child_group_id' => 4, | |
138 | 'parent_group_id' => 2, | |
139 | ), | |
140 | ); | |
141 | ||
142 | $this->assertEquals($expected, $result['values']); | |
143 | } | |
144 | ||
145 | /** | |
146 | * Test civicrm_group_nesting_get with just one | |
147 | * param (parent_group_id). | |
148 | */ | |
149 | public function testGetWithParentGroupId() { | |
150 | $params = array( | |
f3e19c4e | 151 | 'parent_group_id' => 1, ); |
6a488035 | 152 | |
f3e19c4e | 153 | $result = $this->callAPISuccess('group_nesting', 'get', $params); |
6a488035 TO |
154 | |
155 | // expected data loaded in setUp | |
156 | $expected = array( | |
157 | 1 => array('id' => 1, | |
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 | ); | |
f3e19c4e | 186 | $result = $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 | ||
f3e19c4e | 201 | $result = $this->callAPIAndDocument('group_nesting', 'create', $params, __FUNCTION__, __FILE__); |
6a488035 TO |
202 | |
203 | // we have 4 group nesting records in the example | |
204 | // data, expecting next number to be the id for newly created | |
205 | $id = 5; | |
6a488035 TO |
206 | $this->assertDBState('CRM_Contact_DAO_GroupNesting', $id, $params); |
207 | } | |
208 | ||
209 | /** | |
210 | * Test civicrm_group_nesting_create with empty parameter array. | |
211 | * Error expected. | |
212 | */ | |
213 | public function testCreateWithEmptyParams() { | |
f3e19c4e | 214 | $result = $this->callAPIFailure('group_nesting', 'create', array()); |
6a488035 TO |
215 | } |
216 | ||
217 | ///////////////// civicrm_group_nesting_remove methods | |
218 | ||
219 | /** | |
220 | * Test civicrm_group_nesting_remove. | |
221 | */ | |
222 | public function testDelete() { | |
223 | // groups id=1 and id=2 loaded in setUp | |
224 | $getparams = array( | |
225 | 'parent_group_id' => 1, | |
f3e19c4e | 226 | 'child_group_id' => 2, ); |
6a488035 | 227 | |
f3e19c4e | 228 | $result = $this->callAPISuccess('group_nesting', 'get', $getparams); |
229 | $params = array('id' => $result['id']); | |
230 | $result = $this->callAPIAndDocument('group_nesting', 'delete', $params, __FUNCTION__, __FILE__); | |
231 | $this->assertEquals(0, $this->callAPISuccess('group_nesting', 'getcount', $getparams)); | |
6a488035 TO |
232 | } |
233 | ||
234 | /** | |
235 | * Test civicrm_group_nesting_remove with empty parameter array. | |
236 | * Error expected. | |
237 | */ | |
238 | public function testDeleteWithEmptyParams() { | |
f3e19c4e | 239 | $result = $this->callAPIFailure('group_nesting', 'delete', array()); |
6a488035 TO |
240 | } |
241 | } | |
242 |