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