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'; | |
e9479dcf EM |
30 | |
31 | /** | |
32 | * Class api_v3_EventTest | |
33 | */ | |
6a488035 TO |
34 | class api_v3_EventTest extends CiviUnitTestCase { |
35 | protected $_params; | |
36 | protected $_apiversion; | |
430ae6dd | 37 | protected $_entity; |
b7c9bc4c | 38 | |
00be9182 | 39 | public function setUp() { |
6a488035 TO |
40 | parent::setUp(); |
41 | $this->_apiversion = 3; | |
92915c55 TO |
42 | $this->_entity = 'event'; |
43 | $this->_params = array( | |
6a488035 TO |
44 | array( |
45 | 'title' => 'Annual CiviCRM meet', | |
46 | 'summary' => 'If you have any CiviCRM realted issues or want to track where CiviCRM is heading, Sign up now', | |
47 | 'description' => 'This event is intended to give brief idea about progess of CiviCRM and giving solutions to common user issues', | |
48 | 'event_type_id' => 1, | |
49 | 'is_public' => 1, | |
50 | 'start_date' => 20081021, | |
51 | 'end_date' => 20081023, | |
52 | 'is_online_registration' => 1, | |
53 | 'registration_start_date' => 20080601, | |
54 | 'registration_end_date' => '2008-10-15', | |
55 | 'max_participants' => 100, | |
56 | 'event_full_text' => 'Sorry! We are already full', | |
57 | 'is_monetary' => 0, | |
58 | 'is_active' => 1, | |
59 | 'is_show_location' => 0, | |
6a488035 TO |
60 | ), |
61 | array( | |
62 | 'title' => 'Annual CiviCRM meet 2', | |
63 | 'summary' => 'If you have any CiviCRM realted issues or want to track where CiviCRM is heading, Sign up now', | |
64 | 'description' => 'This event is intended to give brief idea about progess of CiviCRM and giving solutions to common user issues', | |
65 | 'event_type_id' => 1, | |
66 | 'is_public' => 1, | |
67 | 'start_date' => 20101021, | |
68 | 'end_date' => 20101023, | |
69 | 'is_online_registration' => 1, | |
70 | 'registration_start_date' => 20100601, | |
71 | 'registration_end_date' => '2010-10-15', | |
72 | 'max_participants' => 100, | |
73 | 'event_full_text' => 'Sorry! We are already full', | |
74 | 'is_monetory' => 0, | |
75 | 'is_active' => 1, | |
76 | 'is_show_location' => 0, | |
6a488035 TO |
77 | ), |
78 | ); | |
79 | ||
80 | $params = array( | |
81 | array( | |
82 | 'title' => 'Annual CiviCRM meet', | |
83 | 'event_type_id' => 1, | |
92915c55 TO |
84 | 'start_date' => 20081021, |
85 | ), | |
6a488035 TO |
86 | array( |
87 | 'title' => 'Annual CiviCRM meet 2', | |
88 | 'event_type_id' => 1, | |
92915c55 TO |
89 | 'start_date' => 20101021, |
90 | ), | |
6a488035 TO |
91 | ); |
92 | ||
93 | $this->events = array(); | |
94 | $this->eventIds = array(); | |
95 | foreach ($params as $event) { | |
92915c55 TO |
96 | $result = $this->callAPISuccess('Event', 'Create', $event); |
97 | $this->_events[] = $result; | |
6a488035 TO |
98 | $this->_eventIds[] = $result['id']; |
99 | } | |
100 | } | |
101 | ||
00be9182 | 102 | public function tearDown() { |
6a488035 TO |
103 | foreach ($this->eventIds as $eventId) { |
104 | $this->eventDelete($eventId); | |
105 | } | |
6a488035 TO |
106 | $tablesToTruncate = array( |
107 | 'civicrm_participant', | |
108 | 'civicrm_event', | |
109 | ); | |
110 | $this->quickCleanup($tablesToTruncate, TRUE); | |
111 | } | |
112 | ||
113 | ///////////////// civicrm_event_get methods | |
6a488035 | 114 | |
00be9182 | 115 | public function testGetEventById() { |
6a488035 | 116 | $params = array( |
92915c55 TO |
117 | 'id' => $this->_events[1]['id'], |
118 | ); | |
ca985406 | 119 | $result = $this->callAPISuccess('event', 'get', $params); |
6a488035 TO |
120 | $this->assertEquals($result['values'][$this->_eventIds[1]]['event_title'], 'Annual CiviCRM meet 2'); |
121 | } | |
122 | ||
00be9182 | 123 | public function testGetEventByEventTitle() { |
6a488035 TO |
124 | |
125 | $params = array( | |
126 | 'event_title' => 'Annual CiviCRM meet', | |
226ede24 | 127 | 'sequential' => TRUE, |
6a488035 TO |
128 | ); |
129 | ||
226ede24 | 130 | $result = $this->callAPIAndDocument('event', 'get', $params, __FUNCTION__, __FILE__); |
6a488035 | 131 | $this->assertEquals(1, $result['count']); |
226ede24 | 132 | $this->assertEquals($result['values'][0]['id'], $this->_eventIds[0]); |
6a488035 TO |
133 | } |
134 | ||
00be9182 | 135 | public function testGetEventByWrongTitle() { |
6a488035 | 136 | $params = array( |
92915c55 TO |
137 | 'title' => 'No event with that title', |
138 | ); | |
ca985406 | 139 | $result = $this->callAPISuccess('Event', 'Get', $params); |
6a488035 TO |
140 | $this->assertEquals(0, $result['count']); |
141 | } | |
92915c55 | 142 | |
00be9182 | 143 | public function testGetEventByIdSort() { |
b6708aeb | 144 | $params = array( |
6a488035 | 145 | 'return.sort' => 'id ASC', |
92915c55 TO |
146 | 'return.max_results' => 1, |
147 | ); | |
ca985406 | 148 | $result = $this->callAPISuccess('Event', 'Get', $params); |
6a488035 TO |
149 | $this->assertEquals(1, $result['id'], ' in line ' . __LINE__); |
150 | $params = array( | |
151 | 'options' => array( | |
152 | 'sort' => 'id DESC', | |
153 | 'limit' => 1, | |
92915c55 TO |
154 | ), |
155 | ); | |
6a488035 | 156 | |
ca985406 | 157 | $result = $this->callAPISuccess('Event', 'Get', $params); |
6a488035 TO |
158 | $this->assertAPISuccess($result, ' in line ' . __LINE__); |
159 | $this->assertEquals(2, $result['id'], ' in line ' . __LINE__); | |
160 | $params = array( | |
161 | 'options' => array( | |
162 | 'sort' => 'id ASC', | |
163 | 'limit' => 1, | |
92915c55 TO |
164 | ), |
165 | ); | |
ca985406 | 166 | $result = $this->callAPISuccess('Event', 'Get', $params); |
6a488035 TO |
167 | $this->assertEquals(1, $result['id'], ' in line ' . __LINE__); |
168 | ||
6a488035 TO |
169 | } |
170 | /* | |
171 | * Getting the id back of an event. | |
172 | * Does not work yet, bug in API | |
173 | */ | |
174 | ||
175 | /* | |
00be9182 | 176 | public function testGetIdOfEventByEventTitle() { |
ca985406 | 177 | $params = array( 'title' => 'Annual CiviCRM meet', |
6a488035 TO |
178 | 'return' => 'id' |
179 | ); | |
180 | ||
ca985406 | 181 | $result = $this->callAPISuccess('Event', 'Get', $params); |
6a488035 TO |
182 | } |
183 | */ | |
184 | ||
185 | ||
c490a46a CW |
186 | /** |
187 | * Test 'is.Current' option. Existing event is 'old' so only current should be returned | |
188 | */ | |
00be9182 | 189 | public function testGetIsCurrent() { |
6a488035 | 190 | $params = array( |
6a488035 TO |
191 | 'isCurrent' => 1, |
192 | ); | |
6c6e6187 | 193 | $currentEventParams = array( |
92915c55 | 194 | 'start_date' => date('Y-m-d', strtotime('+ 1 day')), |
6a488035 TO |
195 | 'end_date' => date('Y-m-d', strtotime('+ 1 week')), |
196 | ); | |
197 | $currentEventParams = array_merge($this->_params[1], $currentEventParams); | |
92915c55 TO |
198 | $currentEvent = $this->callAPISuccess('Event', 'Create', $currentEventParams); |
199 | $description = "demonstrates use of is.Current option"; | |
200 | $subfile = "IsCurrentOption"; | |
201 | $result = $this->callAPIAndDocument('Event', 'Get', $params, __FUNCTION__, __FILE__, $description, $subfile); | |
9f1b81e0 | 202 | $allEvents = $this->callAPISuccess('Event', 'Get', array()); |
203 | $this->callAPISuccess('Event', 'Delete', array('id' => $currentEvent['id'])); | |
6a488035 TO |
204 | $this->assertEquals(1, $result['count'], 'confirm only one event found in line ' . __LINE__); |
205 | $this->assertEquals(3, $allEvents['count'], 'confirm three events exist (ie. two not found) ' . __LINE__); | |
206 | $this->assertEquals($currentEvent['id'], $result['id'], ''); | |
207 | } | |
c490a46a CW |
208 | |
209 | /** | |
210 | * There has been a schema change & the api needs to buffer developers from it | |
211 | */ | |
00be9182 | 212 | public function testGetPaymentProcessorId() { |
6a488035 TO |
213 | $params = $this->_params[0]; |
214 | $params['payment_processor_id'] = 1; | |
6c6e6187 | 215 | $params['sequential'] = 1; |
ca985406 | 216 | $result = $this->callAPISuccess('event', 'create', $params); |
481a74f4 | 217 | $this->assertEquals(1, $result['values'][0]['payment_processor'][0], "handing of payment processor compatibility"); |
ca985406 | 218 | $result = $this->callAPISuccess('event', 'get', $params); |
6c6e6187 | 219 | $this->assertEquals($result['values'][0]['payment_processor_id'], 1, "handing get payment processor compatibility"); |
6a488035 TO |
220 | } |
221 | ||
00be9182 | 222 | public function testInvalidData() { |
6a488035 | 223 | $params = $this->_params[0]; |
6c6e6187 TO |
224 | $params['sequential'] = 1; |
225 | $params['loc_block_id'] = 100; | |
d0e1eff2 | 226 | $result = $this->callAPIFailure('event', 'create', $params); |
6a488035 TO |
227 | |
228 | } | |
229 | ||
c490a46a CW |
230 | /** |
231 | * Test 'is.Current' option. Existing event is 'old' so only current should be returned | |
232 | */ | |
00be9182 | 233 | public function testGetSingleReturnIsFull() { |
6a488035 TO |
234 | $contactID = $this->individualCreate(); |
235 | $params = array( | |
6c6e6187 | 236 | 'id' => $this->_eventIds[0], |
92915c55 | 237 | 'max_participants' => 1, |
6a488035 | 238 | ); |
ca985406 | 239 | $result = $this->callAPISuccess('Event', 'Create', $params); |
6a488035 TO |
240 | |
241 | $getEventParams = array( | |
6c6e6187 | 242 | 'id' => $this->_eventIds[0], |
92915c55 | 243 | 'return.is_full' => 1, |
6a488035 TO |
244 | ); |
245 | ||
ca985406 | 246 | $currentEvent = $this->callAPISuccess('Event', 'getsingle', $getEventParams); |
92915c55 TO |
247 | $description = "demonstrates use of return is_full "; |
248 | $subfile = "IsFullOption"; | |
6a488035 TO |
249 | $this->assertEquals(0, $currentEvent['is_full'], ' is full is set in line ' . __LINE__); |
250 | $this->assertEquals(1, $currentEvent['available_places'], 'available places is set in line ' . __LINE__); | |
92915c55 TO |
251 | $participant = $this->callAPISuccess('Participant', 'create', array( |
252 | 'participant_status' => 1, | |
253 | 'role_id' => 1, | |
254 | 'contact_id' => $contactID, | |
255 | 'event_id' => $this->_eventIds[0] | |
256 | )); | |
ca985406 | 257 | $currentEvent = $this->callAPIAndDocument('Event', 'getsingle', $getEventParams, __FUNCTION__, __FILE__, $description, $subfile, 'getsingle'); |
6a488035 TO |
258 | $this->assertEquals(1, $currentEvent['is_full'], ' is full is set in line ' . __LINE__); |
259 | $this->assertEquals(0, $currentEvent['available_places'], 'available places is set in line ' . __LINE__); | |
260 | ||
261 | $this->contactDelete($contactID); | |
262 | } | |
92915c55 | 263 | |
6a488035 TO |
264 | /* |
265 | * Legacy support for Contribution Type ID. We need to ensure this is supported | |
266 | * as an alias for financial_type_id | |
267 | */ | |
00be9182 | 268 | public function testCreateGetEventLegacyContributionTypeID() { |
6a488035 | 269 | $contributionTypeArray = array('contribution_type_id' => 3); |
9b873358 | 270 | if (isset($this->_params[0]['financial_type_id'])) { |
6a488035 TO |
271 | //in case someone edits $this->_params & invalidates this test :-) |
272 | unset($this->_params[0]['financial_type_id']); | |
273 | } | |
ca985406 | 274 | $result = $this->callAPISuccess('event', 'create', $this->_params[0] + $contributionTypeArray); |
275 | $getresult = $this->callAPISuccess('event', 'get', array() + $contributionTypeArray); | |
ef0bc919 | 276 | $this->assertEquals($getresult['values'][$getresult['id']]['contribution_type_id'], 3); |
6a488035 | 277 | $this->assertEquals($result['id'], $getresult['id']); |
ca985406 | 278 | $this->callAPISuccess('event', 'delete', array('id' => $result['id'])); |
6a488035 TO |
279 | } |
280 | ///////////////// civicrm_event_create methods | |
281 | ||
282 | /** | |
100fef9d | 283 | * Check with complete array + custom field |
6a488035 TO |
284 | * Note that the test is written on purpose without any |
285 | * variables specific to participant so it can be replicated into other entities | |
286 | * and / or moved to the automated test suite | |
287 | */ | |
00be9182 | 288 | public function testCreateWithCustom() { |
6a488035 TO |
289 | $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__); |
290 | ||
291 | $params = $this->_params[0]; | |
292 | $params['custom_' . $ids['custom_field_id']] = "custom string"; | |
293 | ||
226ede24 | 294 | $result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__); |
6a488035 | 295 | |
92915c55 TO |
296 | $check = $this->callAPISuccess($this->_entity, 'get', array( |
297 | 'return.custom_' . $ids['custom_field_id'] => 1, | |
298 | 'id' => $result['id'] | |
299 | )); | |
6a488035 TO |
300 | $this->assertEquals("custom string", $check['values'][$check['id']]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__); |
301 | ||
302 | $this->customFieldDelete($ids['custom_field_id']); | |
303 | $this->customGroupDelete($ids['custom_group_id']); | |
ca985406 | 304 | $this->callAPISuccess($this->_entity, 'Delete', array('id' => $result['id'])); |
6a488035 TO |
305 | } |
306 | ||
b2cdd843 EM |
307 | /** |
308 | * Test that an event with a price set can be created | |
309 | */ | |
00be9182 | 310 | public function testCreatePaidEvent() { |
b2cdd843 EM |
311 | //@todo alter API so that an integer is converted to an array |
312 | $priceSetParams = array('price_set_id' => (array) 1, 'is_monetary' => 1); | |
313 | $result = $this->callAPISuccess('Event', 'Create', array_merge($this->_params[0], $priceSetParams)); | |
314 | $event = $this->callAPISuccess('Event', 'getsingle', array('id' => $result['id'], 'return' => 'price_set_id')); | |
315 | $this->assertArrayKeyExists('price_set_id', $event); | |
316 | } | |
317 | ||
00be9182 | 318 | public function testCreateEventParamsNotArray() { |
6a488035 | 319 | $params = NULL; |
d0e1eff2 | 320 | $result = $this->callAPIFailure('event', 'create', $params); |
6a488035 TO |
321 | } |
322 | ||
00be9182 | 323 | public function testCreateEventEmptyParams() { |
6a488035 | 324 | $params = array(); |
d0e1eff2 | 325 | $result = $this->callAPIFailure('event', 'create', $params); |
6a488035 TO |
326 | } |
327 | ||
00be9182 | 328 | public function testCreateEventParamsWithoutTitle() { |
6a488035 | 329 | unset($this->_params['title']); |
ca985406 | 330 | $result = $this->callAPIFailure('event', 'create', $this->_params); |
791c263c | 331 | $this->assertAPIFailure($result); |
6a488035 TO |
332 | } |
333 | ||
00be9182 | 334 | public function testCreateEventParamsWithoutEventTypeId() { |
6a488035 | 335 | unset($this->_params['event_type_id']); |
ca985406 | 336 | $result = $this->callAPIFailure('event', 'create', $this->_params); |
6a488035 TO |
337 | } |
338 | ||
00be9182 | 339 | public function testCreateEventParamsWithoutStartDate() { |
6a488035 | 340 | unset($this->_params['start_date']); |
ca985406 | 341 | $result = $this->callAPIFailure('event', 'create', $this->_params); |
6a488035 TO |
342 | } |
343 | ||
00be9182 | 344 | public function testCreateEventSuccess() { |
ca985406 | 345 | $result = $this->callAPIAndDocument('Event', 'Create', $this->_params[0], __FUNCTION__, __FILE__); |
6a488035 | 346 | $this->assertArrayHasKey('id', $result['values'][$result['id']], 'In line ' . __LINE__); |
ca985406 | 347 | $result = $this->callAPISuccess($this->_entity, 'Get', array('id' => $result['id'])); |
348 | $this->callAPISuccess($this->_entity, 'Delete', array('id' => $result['id'])); | |
6a488035 TO |
349 | $this->assertEquals('2008-10-21 00:00:00', $result['values'][$result['id']]['start_date'], 'start date is not set in line ' . __LINE__); |
350 | $this->assertEquals('2008-10-23 00:00:00', $result['values'][$result['id']]['end_date'], 'end date is not set in line ' . __LINE__); | |
351 | $this->assertEquals('2008-06-01 00:00:00', $result['values'][$result['id']]['registration_start_date'], 'start date is not set in line ' . __LINE__); | |
352 | $this->assertEquals('2008-10-15 00:00:00', $result['values'][$result['id']]['registration_end_date'], 'end date is not set in line ' . __LINE__); | |
6a488035 | 353 | } |
c490a46a CW |
354 | |
355 | /** | |
356 | * Test that passing in Unique field names works | |
357 | */ | |
00be9182 | 358 | public function testCreateEventSuccessUniqueFieldNames() { |
6a488035 TO |
359 | $this->_params[0]['event_start_date'] = $this->_params[0]['start_date']; |
360 | unset($this->_params[1]['start_date']); | |
361 | $this->_params[0]['event_title'] = $this->_params[0]['title']; | |
362 | unset($this->_params[0]['title']); | |
ca985406 | 363 | $result = $this->callAPISuccess('Event', 'Create', $this->_params[0]); |
6a488035 TO |
364 | $this->assertAPISuccess($result, 'In line ' . __LINE__); |
365 | $this->assertArrayHasKey('id', $result['values'][$result['id']], 'In line ' . __LINE__); | |
ca985406 | 366 | $result = $this->callAPISuccess($this->_entity, 'Get', array('id' => $result['id'])); |
367 | $this->callAPISuccess($this->_entity, 'Delete', array('id' => $result['id'])); | |
6a488035 TO |
368 | |
369 | $this->assertEquals('2008-10-21 00:00:00', $result['values'][$result['id']]['start_date'], 'start date is not set in line ' . __LINE__); | |
370 | $this->assertEquals('2008-10-23 00:00:00', $result['values'][$result['id']]['end_date'], 'end date is not set in line ' . __LINE__); | |
371 | $this->assertEquals('2008-06-01 00:00:00', $result['values'][$result['id']]['registration_start_date'], 'start date is not set in line ' . __LINE__); | |
372 | $this->assertEquals('2008-10-15 00:00:00', $result['values'][$result['id']]['registration_end_date'], 'end date is not set in line ' . __LINE__); | |
373 | $this->assertEquals($this->_params[0]['event_title'], $result['values'][$result['id']]['title'], 'end date is not set in line ' . __LINE__); | |
6a488035 TO |
374 | } |
375 | ||
00be9182 | 376 | public function testUpdateEvent() { |
ca985406 | 377 | $result = $this->callAPISuccess('event', 'create', $this->_params[1]); |
6a488035 | 378 | |
6a488035 | 379 | $params = array( |
6c6e6187 | 380 | 'id' => $result['id'], |
92915c55 | 381 | 'max_participants' => 150, |
6a488035 | 382 | ); |
ca985406 | 383 | $this->callAPISuccess('Event', 'Create', $params); |
fb32de45 | 384 | $updated = $this->callAPISuccess('Event', 'Get', $params, __FUNCTION__, __FILE__); |
6a488035 TO |
385 | $this->assertEquals(150, $updated['values'][$result['id']]['max_participants']); |
386 | $this->assertEquals('Annual CiviCRM meet 2', $updated['values'][$result['id']]['title']); | |
ca985406 | 387 | $this->callAPISuccess($this->_entity, 'Delete', array('id' => $result['id'])); |
6a488035 TO |
388 | } |
389 | ||
6a488035 | 390 | |
00be9182 | 391 | public function testDeleteEmptyParams() { |
ca985406 | 392 | $result = $this->callAPIFailure('Event', 'Delete', array()); |
6a488035 TO |
393 | } |
394 | ||
00be9182 | 395 | public function testDelete() { |
6a488035 TO |
396 | $params = array( |
397 | 'id' => $this->_eventIds[0], | |
6a488035 | 398 | ); |
ca985406 | 399 | $result = $this->callAPIAndDocument('Event', 'Delete', $params, __FUNCTION__, __FILE__); |
6a488035 | 400 | } |
ca985406 | 401 | |
402 | /** | |
100fef9d | 403 | * Check event_id still supported for delete |
ca985406 | 404 | */ |
00be9182 | 405 | public function testDeleteWithEventId() { |
6a488035 | 406 | $params = array( |
92915c55 TO |
407 | 'event_id' => $this->_eventIds[0], |
408 | ); | |
ca985406 | 409 | $result = $this->callAPISuccess('Event', 'Delete', $params); |
6a488035 TO |
410 | $this->assertAPISuccess($result, 'in line ' . __LINE__); |
411 | } | |
c490a46a CW |
412 | |
413 | /** | |
414 | * Trying to delete an event with participants should return error | |
415 | */ | |
00be9182 | 416 | public function testDeleteWithExistingParticipant() { |
e4d5f1e2 | 417 | $contactID = $this->individualCreate(); |
6a488035 TO |
418 | $participantID = $this->participantCreate( |
419 | array( | |
420 | 'contactID' => $contactID, | |
421 | 'eventID' => $this->_eventIds[0], | |
422 | ) | |
423 | ); | |
ca985406 | 424 | $result = $this->callAPISuccess('Event', 'Delete', array('id' => $this->_eventIds[0])); |
6a488035 TO |
425 | } |
426 | ||
00be9182 | 427 | public function testDeleteWithWrongEventId() { |
ca985406 | 428 | $params = array('event_id' => $this->_eventIds[0]); |
429 | $result = $this->callAPISuccess('Event', 'Delete', $params); | |
6a488035 TO |
430 | // try to delete again - there's no such event anymore |
431 | $params = array('event_id' => $this->_eventIds[0]); | |
d0e1eff2 | 432 | $result = $this->callAPIFailure('Event', 'Delete', $params); |
6a488035 TO |
433 | } |
434 | ||
435 | ///////////////// civicrm_event_search methods | |
436 | ||
437 | /** | |
438 | * Test civicrm_event_search with wrong params type | |
439 | */ | |
00be9182 | 440 | public function testSearchWrongParamsType() { |
6a488035 | 441 | $params = 'a string'; |
d0e1eff2 | 442 | $result = $this->callAPIFailure('event', 'get', $params); |
6a488035 TO |
443 | } |
444 | ||
445 | /** | |
446 | * Test civicrm_event_search with empty params | |
447 | */ | |
00be9182 | 448 | public function testSearchEmptyParams() { |
ca985406 | 449 | $event = $this->callAPISuccess('event', 'create', $this->_params[1]); |
6a488035 | 450 | |
92915c55 TO |
451 | $getparams = array( |
452 | 'sequential' => 1, | |
6a488035 | 453 | ); |
ca985406 | 454 | $result = $this->callAPISuccess('event', 'get', $getparams); |
6a488035 TO |
455 | $this->assertEquals($result['count'], 3, 'In line ' . __LINE__); |
456 | $res = $result['values'][0]; | |
457 | $this->assertArrayKeyExists('title', $res, 'In line ' . __LINE__); | |
458 | $this->assertEquals($res['event_type_id'], $this->_params[1]['event_type_id'], 'In line ' . __LINE__); | |
459 | } | |
460 | ||
461 | /** | |
462 | * Test civicrm_event_search. Success expected. | |
463 | */ | |
00be9182 | 464 | public function testSearch() { |
6a488035 TO |
465 | $params = array( |
466 | 'event_type_id' => 1, | |
467 | 'return.title' => 1, | |
468 | 'return.id' => 1, | |
92915c55 TO |
469 | 'return.start_date' => 1, |
470 | ); | |
ca985406 | 471 | $result = $this->callAPISuccess('event', 'get', $params); |
6a488035 TO |
472 | |
473 | $this->assertEquals($result['values'][$this->_eventIds[0]]['id'], $this->_eventIds[0], 'In line ' . __LINE__); | |
474 | $this->assertEquals($result['values'][$this->_eventIds[0]]['title'], 'Annual CiviCRM meet', 'In line ' . __LINE__); | |
475 | } | |
476 | ||
477 | /** | |
478 | * Test civicrm_event_search. Success expected. | |
479 | * return.offset and return.max_results test (CRM-5266) | |
480 | */ | |
00be9182 | 481 | public function testSearchWithOffsetAndMaxResults() { |
6a488035 TO |
482 | $maxEvents = 5; |
483 | $events = array(); | |
484 | while ($maxEvents > 0) { | |
6c6e6187 | 485 | $params = array( |
92915c55 | 486 | 'title' => 'Test Event' . $maxEvents, |
6a488035 TO |
487 | 'event_type_id' => 2, |
488 | 'start_date' => 20081021, | |
489 | ); | |
490 | ||
ca985406 | 491 | $events[$maxEvents] = $this->callAPISuccess('event', 'create', $params); |
6a488035 TO |
492 | $maxEvents--; |
493 | } | |
6c6e6187 | 494 | $params = array( |
92915c55 | 495 | 'event_type_id' => 2, |
6a488035 TO |
496 | 'return.id' => 1, |
497 | 'return.title' => 1, | |
498 | 'return.offset' => 2, | |
499 | 'return.max_results' => 2, | |
500 | ); | |
ca985406 | 501 | $result = $this->callAPISuccess('event', 'get', $params); |
6a488035 TO |
502 | $this->assertAPISuccess($result); |
503 | $this->assertEquals(2, $result['count'], ' 2 results returned In line ' . __LINE__); | |
504 | } | |
505 | ||
00be9182 | 506 | public function testEventCreationPermissions() { |
6a488035 | 507 | $params = array( |
6c6e6187 | 508 | 'event_type_id' => 1, |
92915c55 TO |
509 | 'start_date' => '2010-10-03', |
510 | 'title' => 'le cake is a tie', | |
511 | 'check_permissions' => TRUE, | |
512 | ); | |
6a488035 TO |
513 | $config = &CRM_Core_Config::singleton(); |
514 | $config->userPermissionClass->permissions = array('access CiviCRM'); | |
d0e1eff2 | 515 | $result = $this->callAPIFailure('event', 'create', $params); |
60ec9f43 | 516 | $this->assertEquals('API permission check failed for event/create call; insufficient permission: require access CiviCRM and access CiviEvent and edit all events', $result['error_message'], 'lacking permissions should not be enough to create an event'); |
6a488035 TO |
517 | |
518 | $config->userPermissionClass->permissions = array('access CiviEvent', 'edit all events', 'access CiviCRM'); | |
ca985406 | 519 | $result = $this->callAPISuccess('event', 'create', $params); |
6a488035 TO |
520 | } |
521 | ||
00be9182 | 522 | public function testgetfields() { |
9657ccf2 | 523 | $description = "demonstrate use of getfields to interrogate api"; |
ca985406 | 524 | $params = array('action' => 'create'); |
525 | $result = $this->callAPISuccess('event', 'getfields', $params); | |
6a488035 TO |
526 | $this->assertEquals(1, $result['values']['title']['api.required'], 'in line ' . __LINE__); |
527 | } | |
c490a46a CW |
528 | |
529 | /** | |
100fef9d | 530 | * Test api_action param also works |
c490a46a | 531 | */ |
00be9182 | 532 | public function testgetfieldsRest() { |
9657ccf2 | 533 | $description = "demonstrate use of getfields to interrogate api"; |
ca985406 | 534 | $params = array('api_action' => 'create'); |
535 | $result = $this->callAPISuccess('event', 'getfields', $params); | |
6a488035 TO |
536 | $this->assertEquals(1, $result['values']['title']['api.required'], 'in line ' . __LINE__); |
537 | } | |
92915c55 | 538 | |
00be9182 | 539 | public function testgetfieldsGet() { |
9657ccf2 | 540 | $description = "demonstrate use of getfields to interrogate api"; |
ca985406 | 541 | $params = array('action' => 'get'); |
542 | $result = $this->callAPISuccess('event', 'getfields', $params); | |
6a488035 TO |
543 | $this->assertEquals('title', $result['values']['event_title']['name'], 'in line ' . __LINE__); |
544 | } | |
92915c55 | 545 | |
00be9182 | 546 | public function testgetfieldsDelete() { |
9657ccf2 | 547 | $description = "demonstrate use of getfields to interrogate api"; |
ca985406 | 548 | $params = array('action' => 'delete'); |
549 | $result = $this->callAPISuccess('event', 'getfields', $params); | |
6a488035 TO |
550 | $this->assertEquals(1, $result['values']['id']['api.required']); |
551 | } | |
552 | } |