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