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