Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
06a1bc01 | 4 | | CiviCRM version 4.5 | |
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 | require_once 'CiviTest/CiviUnitTestCase.php'; | |
29 | ||
30 | /** | |
31 | * Test class for Batch API - civicrm_participant_* | |
32 | * | |
33 | * @package CiviCRM_APIv3 | |
34 | */ | |
35 | require_once 'CRM/Utils/DeprecatedUtils.php'; | |
36 | require_once 'CiviTest/CiviUnitTestCase.php'; | |
4cbe18b8 EM |
37 | |
38 | /** | |
39 | * Class api_v3_ParticipantTest | |
40 | */ | |
6a488035 TO |
41 | class api_v3_ParticipantTest extends CiviUnitTestCase { |
42 | ||
43 | protected $_apiversion; | |
44 | protected $_entity; | |
45 | protected $_contactID; | |
46 | protected $_contactID2; | |
47 | protected $_createdParticipants; | |
48 | protected $_participantID; | |
49 | protected $_eventID; | |
50 | protected $_individualId; | |
51 | protected $_params; | |
6a488035 | 52 | |
4cbe18b8 EM |
53 | /** |
54 | * @return array | |
55 | */ | |
6a488035 TO |
56 | function get_info() { |
57 | return array( | |
58 | 'name' => 'Participant Create', | |
59 | 'description' => 'Test all Participant Create API methods.', | |
60 | 'group' => 'CiviCRM API Tests', | |
61 | ); | |
62 | } | |
63 | ||
64 | function setUp() { | |
65 | $this->_apiversion = 3; | |
66 | parent::setUp(); | |
67 | $this->_entity = 'participant'; | |
68 | $event = $this->eventCreate(NULL); | |
69 | $this->_eventID = $event['id']; | |
70 | ||
e4d5f1e2 | 71 | $this->_contactID = $this->individualCreate(); |
6a488035 TO |
72 | |
73 | $this->_createdParticipants = array(); | |
e4d5f1e2 | 74 | $this->_individualId = $this->individualCreate(); |
6a488035 | 75 | |
9fbee5b6 | 76 | $this->_participantID = $this->participantCreate(array('contact_id' => $this->_contactID, 'event_id' => $this->_eventID)); |
e4d5f1e2 | 77 | $this->_contactID2 = $this->individualCreate(); |
afd404ea | 78 | $this->_participantID2 = $this->participantCreate(array('contact_id' => $this->_contactID2, 'event_id' => $this->_eventID)); |
79 | $this->_participantID3 = $this->participantCreate(array('contact_id' => $this->_contactID2, 'event_id' => $this->_eventID)); | |
6a488035 TO |
80 | $this->_params = array( |
81 | 'contact_id' => $this->_contactID, | |
82 | 'event_id' => $this->_eventID, | |
83 | 'status_id' => 1, | |
84 | 'role_id' => 1, | |
85 | // to ensure it matches later on | |
86 | 'register_date' => '2007-07-21 00:00:00', | |
87 | 'source' => 'Online Event Registration: API Testing', | |
6a488035 TO |
88 | ); |
89 | } | |
90 | ||
91 | function tearDown() { | |
92 | $this->eventDelete($this->_eventID); | |
93 | $tablesToTruncate = array( | |
94 | 'civicrm_custom_group', 'civicrm_custom_field', 'civicrm_contact', 'civicrm_participant' | |
95 | ); | |
96 | // true tells quickCleanup to drop any tables that might have been created in the test | |
97 | $this->quickCleanup($tablesToTruncate, TRUE); | |
98 | } | |
99 | ||
100 | /** | |
101 | * check with complete array + custom field | |
102 | * Note that the test is written on purpose without any | |
103 | * variables specific to participant so it can be replicated into other entities | |
104 | * and / or moved to the automated test suite | |
105 | */ | |
106 | function testCreateWithCustom() { | |
107 | $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, __FILE__); | |
108 | ||
109 | $params = $this->_params; | |
110 | $params['custom_' . $ids['custom_field_id']] = "custom string"; | |
111 | ||
afd404ea | 112 | $result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__); |
113 | ||
6a488035 | 114 | $this->assertEquals($result['id'], $result['values'][$result['id']]['id']); |
6a488035 | 115 | |
afd404ea | 116 | $check = $this->callAPISuccess($this->_entity, 'get', array('id' => $result['id'])); |
6a488035 TO |
117 | $this->assertEquals("custom string", $check['values'][$check['id']]['custom_' . $ids['custom_field_id']], ' in line ' . __LINE__); |
118 | ||
119 | $this->customFieldDelete($ids['custom_field_id']); | |
120 | $this->customGroupDelete($ids['custom_group_id']); | |
121 | } | |
122 | ||
123 | ||
124 | ///////////////// civicrm_participant_get methods | |
125 | ||
126 | /** | |
127 | * check with wrong params type | |
128 | */ | |
129 | function testGetWrongParamsType() { | |
130 | $params = 'a string'; | |
d0e1eff2 | 131 | $result = $this->callAPIFailure('participant', 'get', $params); |
6a488035 TO |
132 | } |
133 | ||
134 | /** | |
135 | * Test civicrm_participant_get with empty params | |
136 | */ | |
137 | function testGetEmptyParams() { | |
d0e1eff2 | 138 | $this->callAPISuccess('participant', 'get', array()); |
6a488035 TO |
139 | } |
140 | ||
141 | /** | |
142 | * check with participant_id | |
143 | */ | |
144 | function testGetParticipantIdOnly() { | |
145 | $params = array( | |
146 | 'participant_id' => $this->_participantID, | |
6a488035 TO |
147 | 'return' => array( |
148 | 'participant_id', | |
149 | 'event_id', | |
150 | 'participant_register_date', | |
151 | 'participant_source', | |
152 | ) | |
153 | ); | |
afd404ea | 154 | $result = $this->callAPISuccess('participant', 'get', $params); |
6a488035 TO |
155 | $this->assertAPISuccess($result, " in line " . __LINE__); |
156 | $this->assertEquals($result['values'][$this->_participantID]['event_id'], $this->_eventID, "in line " . __LINE__); | |
157 | $this->assertEquals($result['values'][$this->_participantID]['participant_register_date'], '2007-02-19 00:00:00', "in line " . __LINE__); | |
158 | $this->assertEquals($result['values'][$this->_participantID]['participant_source'], 'Wimbeldon', "in line " . __LINE__); | |
159 | $params = array( | |
160 | 'id' => $this->_participantID, | |
6a488035 TO |
161 | 'return' => 'id,participant_register_date,event_id', |
162 | ||
163 | ); | |
afd404ea | 164 | $result = $this->callAPISuccess('participant', 'get', $params); |
6a488035 TO |
165 | $this->assertEquals($result['values'][$this->_participantID]['event_id'], $this->_eventID); |
166 | $this->assertEquals($result['values'][$this->_participantID]['participant_register_date'], '2007-02-19 00:00:00'); | |
167 | ||
168 | } | |
169 | ||
170 | /** | |
171 | * check with params id | |
172 | */ | |
173 | function testGetParamsAsIdOnly() { | |
174 | $params = array( | |
175 | 'id' => $this->_participantID, | |
6a488035 | 176 | ); |
afd404ea | 177 | $result = $this->callAPIAndDocument('participant', 'get', $params, __FUNCTION__, __FILE__); |
6a488035 TO |
178 | $this->assertEquals($result['values'][$this->_participantID]['event_id'], $this->_eventID); |
179 | $this->assertEquals($result['values'][$this->_participantID]['participant_register_date'], '2007-02-19 00:00:00'); | |
180 | $this->assertEquals($result['values'][$this->_participantID]['participant_source'], 'Wimbeldon'); | |
181 | $this->assertEquals($result['id'], $result['values'][$this->_participantID]['id']); | |
182 | } | |
183 | ||
184 | /** | |
185 | * check with params id | |
186 | */ | |
187 | function testGetNestedEventGet() { | |
188 | //create a second event & add participant to it. | |
189 | $event = $this->eventCreate(NULL); | |
afd404ea | 190 | $this->callAPISuccess('participant', 'create', array('event_id' => $event['id'], 'contact_id' => $this->_contactID)); |
6a488035 TO |
191 | |
192 | ||
193 | $description = "use nested get to get an event"; | |
194 | $subfile = "NestedEventGet"; | |
195 | $params = array( | |
196 | 'id' => $this->_participantID, | |
6a488035 TO |
197 | 'api.event.get' => 1, |
198 | ); | |
afd404ea | 199 | $result = $this->callAPIAndDocument('participant', 'get', $params, __FUNCTION__, __FILE__, $description, $subfile); |
6a488035 TO |
200 | $this->assertEquals($result['values'][$this->_participantID]['event_id'], $this->_eventID); |
201 | $this->assertEquals($result['values'][$this->_participantID]['participant_register_date'], '2007-02-19 00:00:00'); | |
202 | $this->assertEquals($result['values'][$this->_participantID]['participant_source'], 'Wimbeldon'); | |
203 | $this->assertEquals($this->_eventID, $result['values'][$this->_participantID]['api.event.get']['id']); | |
204 | } | |
205 | /* | |
206 | * Check Participant Get respects return properties | |
207 | */ | |
208 | function testGetWithReturnProperties() { | |
209 | $params = array( | |
afd404ea | 210 | 'contact_id' => $this->_contactID, 'return.status_id' => 1, |
6a488035 TO |
211 | 'return.participant_status_id' => 1, |
212 | 'options' => array('limit' => 1) | |
213 | ); | |
afd404ea | 214 | $result = $this->callAPISuccess('participant', 'get', $params); |
6a488035 TO |
215 | $this->assertArrayHasKey('participant_status_id', $result['values'][$result['id']]); |
216 | } | |
217 | ||
218 | /** | |
219 | * check with contact_id | |
220 | */ | |
221 | function testGetContactIdOnly() { | |
222 | $params = array( | |
afd404ea | 223 | 'contact_id' => $this->_contactID, ); |
224 | $participant = $this->callAPISuccess('participant', 'get', $params); | |
6a488035 TO |
225 | |
226 | $this->assertEquals($this->_participantID, $participant['id'], | |
227 | "In line " . __LINE__ | |
228 | ); | |
229 | $this->assertEquals($this->_eventID, $participant['values'][$participant['id']]['event_id'], | |
230 | "In line " . __LINE__ | |
231 | ); | |
232 | $this->assertEquals('2007-02-19 00:00:00', $participant['values'][$participant['id']]['participant_register_date'], | |
233 | "In line " . __LINE__ | |
234 | ); | |
235 | $this->assertEquals('Wimbeldon', $participant['values'][$participant['id']]['participant_source'], | |
236 | "In line " . __LINE__ | |
237 | ); | |
238 | $this->assertEquals($participant['id'], $participant['values'][$participant['id']]['id'], | |
239 | "In line " . __LINE__ | |
240 | ); | |
241 | } | |
242 | ||
243 | /** | |
244 | * check with event_id | |
245 | * fetch first record | |
246 | */ | |
247 | function testGetMultiMatchReturnFirst() { | |
248 | $params = array( | |
249 | 'event_id' => $this->_eventID, | |
afd404ea | 250 | 'rowCount' => 1, ); |
6a488035 | 251 | |
afd404ea | 252 | $participant = $this->callAPISuccess('participant', 'get', $params); |
6a488035 TO |
253 | $this->assertNotNull($participant['id']); |
254 | } | |
255 | ||
256 | /** | |
257 | * check with event_id | |
258 | * in v3 this should return all participants | |
259 | */ | |
260 | function testGetMultiMatchNoReturnFirst() { | |
261 | $params = array( | |
262 | 'event_id' => $this->_eventID, | |
6a488035 | 263 | ); |
afd404ea | 264 | $participant = $this->callAPISuccess('participant', 'get', $params); |
6a488035 TO |
265 | $this->assertNotNull($participant['count'], 3); |
266 | } | |
267 | ||
268 | ///////////////// civicrm_participant_get methods | |
269 | ||
6a488035 TO |
270 | /** |
271 | * Test civicrm_participant_get with empty params | |
272 | * In this case all the participant records are returned. | |
273 | */ | |
274 | function testSearchEmptyParams() { | |
afd404ea | 275 | $result = $this->callAPISuccess('participant', 'get', array()); |
6a488035 TO |
276 | // expecting 3 participant records |
277 | $this->assertEquals($result['count'], 3); | |
278 | } | |
279 | ||
280 | /** | |
281 | * check with participant_id | |
282 | */ | |
283 | function testSearchParticipantIdOnly() { | |
284 | $params = array( | |
285 | 'participant_id' => $this->_participantID, | |
6a488035 | 286 | ); |
afd404ea | 287 | $participant = $this->callAPISuccess('participant', 'get', $params); |
6a488035 TO |
288 | $this->assertEquals($participant['values'][$this->_participantID]['event_id'], $this->_eventID); |
289 | $this->assertEquals($participant['values'][$this->_participantID]['participant_register_date'], '2007-02-19 00:00:00'); | |
290 | $this->assertEquals($participant['values'][$this->_participantID]['participant_source'], 'Wimbeldon'); | |
291 | } | |
292 | ||
293 | /** | |
294 | * check with contact_id | |
295 | */ | |
296 | function testSearchContactIdOnly() { | |
297 | // Should get 2 participant records for this contact. | |
298 | $params = array( | |
299 | 'contact_id' => $this->_contactID2, | |
6a488035 | 300 | ); |
afd404ea | 301 | $participant = $this->callAPISuccess('participant', 'get', $params); |
6a488035 TO |
302 | |
303 | $this->assertEquals($participant['count'], 2); | |
304 | } | |
305 | ||
306 | /** | |
307 | * check with event_id | |
308 | */ | |
309 | function testSearchByEvent() { | |
310 | // Should get >= 3 participant records for this event. Also testing that last_name and event_title are returned. | |
311 | $params = array( | |
312 | 'event_id' => $this->_eventID, | |
313 | 'return.last_name' => 1, | |
314 | 'return.event_title' => 1, | |
6a488035 | 315 | ); |
afd404ea | 316 | $participant = $this->callAPISuccess('participant', 'get', $params); |
6a488035 TO |
317 | if ($participant['count'] < 3) { |
318 | $this->fail("Event search returned less than expected miniumum of 3 records."); | |
319 | } | |
320 | ||
321 | $this->assertEquals($participant['values'][$this->_participantID]['last_name'], 'Anderson'); | |
322 | $this->assertEquals($participant['values'][$this->_participantID]['event_title'], 'Annual CiviCRM meet'); | |
323 | } | |
324 | ||
325 | /** | |
326 | * check with event_id | |
327 | * fetch with limit | |
328 | */ | |
329 | function testSearchByEventWithLimit() { | |
330 | // Should 2 participant records since we're passing rowCount = 2. | |
331 | $params = array( | |
332 | 'event_id' => $this->_eventID, | |
333 | 'rowCount' => 2, | |
6a488035 | 334 | ); |
afd404ea | 335 | $participant = $this->callAPISuccess('participant', 'get', $params); |
6a488035 TO |
336 | |
337 | $this->assertEquals($participant['count'], 2, 'in line ' . __LINE__); | |
338 | } | |
339 | ||
340 | ///////////////// civicrm_participant_create methods | |
341 | ||
6a488035 TO |
342 | /** |
343 | * Test civicrm_participant_create with empty params | |
344 | */ | |
345 | function testCreateEmptyParams() { | |
346 | $params = array(); | |
d0e1eff2 | 347 | $result = $this->callAPIFailure('participant', 'create', $params); |
6a488035 TO |
348 | } |
349 | ||
350 | /** | |
351 | * check with event_id | |
352 | */ | |
353 | function testCreateMissingContactID() { | |
354 | $params = array( | |
355 | 'event_id' => $this->_eventID, | |
6a488035 | 356 | ); |
afd404ea | 357 | $participant = $this->callAPIFailure('participant', 'create', $params); |
6a488035 TO |
358 | } |
359 | ||
360 | /** | |
361 | * check with contact_id | |
362 | * without event_id | |
363 | */ | |
364 | function testCreateMissingEventID() { | |
365 | $params = array( | |
366 | 'contact_id' => $this->_contactID, | |
6a488035 | 367 | ); |
afd404ea | 368 | $participant = $this->callAPIFailure('participant', 'create', $params); |
6a488035 TO |
369 | } |
370 | ||
371 | /** | |
372 | * check with contact_id & event_id | |
373 | */ | |
374 | function testCreateEventIdOnly() { | |
375 | $params = array( | |
376 | 'contact_id' => $this->_contactID, | |
377 | 'event_id' => $this->_eventID, | |
6a488035 | 378 | ); |
afd404ea | 379 | $participant = $this->callAPISuccess('participant', 'create', $params); |
380 | $this->getAndCheck($params, $participant['id'], 'participant'); | |
6a488035 TO |
381 | } |
382 | ||
383 | /** | |
384 | * check with complete array | |
385 | */ | |
386 | function testCreateAllParams() { | |
387 | $params = $this->_params; | |
388 | ||
afd404ea | 389 | $participant = $this->callAPISuccess('participant', 'create', $params); |
6a488035 | 390 | $this->_participantID = $participant['id']; |
afd404ea | 391 | // assertDBState compares expected values in $match to actual values in the DB |
392 | $this->assertDBState('CRM_Event_DAO_Participant', $participant['id'], $params); | |
6a488035 TO |
393 | } |
394 | /* | |
395 | * Test to check if receive date is being changed per CRM-9763 | |
396 | */ | |
397 | function testCreateUpdateReceiveDate() { | |
afd404ea | 398 | $participant = $this->callAPISuccess('participant', 'create', $this->_params); |
6a488035 | 399 | $update = array( |
afd404ea | 400 | 'id' => $participant['id'], |
6a488035 TO |
401 | 'status_id' => 2, |
402 | ); | |
afd404ea | 403 | $this->callAPISuccess('participant', 'create', $update); |
6a488035 TO |
404 | $this->getAndCheck(array_merge($this->_params, $update), $participant['id'], 'participant'); |
405 | } | |
406 | /* | |
407 | * Test to check if participant fee level is being changed per CRM-9781 | |
408 | */ | |
409 | function testCreateUpdateParticipantFeeLevel() { | |
410 | $myParams = $this->_params + array('participant_fee_level' => CRM_Core_DAO::VALUE_SEPARATOR . "fee" . CRM_Core_DAO::VALUE_SEPARATOR); | |
afd404ea | 411 | $participant = $this->callAPISuccess('participant', 'create', $myParams); |
6a488035 | 412 | $update = array( |
6ead217b | 413 | 'id' => $participant['id'], |
6a488035 TO |
414 | 'status_id' => 2, |
415 | ); | |
6ead217b E |
416 | $update = $this->callAPISuccess('participant', 'create', $update); |
417 | ||
418 | $this->assertEquals($participant['values'][$participant['id']]['fee_level'], | |
419 | $update['values'][$participant['id']]['fee_level'] | |
6a488035 TO |
420 | ); |
421 | ||
afd404ea | 422 | $this->callAPISuccess('participant', 'delete', array('id' => $participant['id'])); |
6a488035 | 423 | } |
3233fd0f JV |
424 | |
425 | /** | |
426 | * Test the line items for participant fee with multiple price field values. | |
427 | */ | |
428 | function testCreateParticipantLineItems() { | |
429 | // Create a price set for this event. | |
430 | ||
431 | $priceset = $this->callAPISuccess('PriceSet', 'create', array( | |
432 | 'name' => 'my_price_set', | |
433 | 'title' => 'My Price Set', | |
434 | 'is_active' => 1, | |
435 | 'extends' => 1, | |
436 | 'financial_type_id' => 4, | |
437 | // 'entity' => array('civicrm_event' => array($this->_eventID)), | |
438 | )); | |
439 | ||
440 | // Add the price set to the event with another API call. | |
441 | // I tried to do this at once, but it did not work. | |
442 | ||
443 | $priceset = $this->callAPISuccess('PriceSet', 'create', array( | |
444 | 'entity_table' => 'civicrm_event', | |
445 | 'entity_id' => $this->_eventID, | |
446 | 'id' => $priceset['id'], | |
447 | )); | |
448 | ||
449 | $pricefield = $this->callAPISuccess('PriceField', 'create', array( | |
450 | 'price_set_id' => $priceset['id'], | |
451 | 'name' => 'mypricefield', | |
452 | 'label' => 'My Price Field', | |
453 | 'html_type' => 'Text', | |
454 | 'is_enter_qty' => 1, | |
455 | 'is_display_amounts' => 1, | |
456 | 'is_active' => 1, | |
457 | )); | |
458 | ||
459 | $pfv1 = $this->callAPISuccess('PriceFieldValue', 'create', array( | |
460 | 'price_field_id' => $pricefield['id'], | |
461 | 'name' => 'pricefieldvalue1', | |
462 | 'label' => 'pricefieldvalue1', | |
463 | 'amount' => 20, | |
464 | 'is_active' => 1, | |
465 | 'financial_type_id' => 4, | |
466 | )); | |
467 | ||
468 | $pfv2 = $this->callAPISuccess('PriceFieldValue', 'create', array( | |
469 | 'price_field_id' => $pricefield['id'], | |
470 | 'name' => 'pricefieldvalue2', | |
471 | 'label' => 'pricefieldvalue2', | |
472 | 'amount' => 5, | |
473 | 'is_active' => 1, | |
474 | 'financial_type_id' => 4, | |
475 | )); | |
476 | ||
477 | // pay 2 times price field value 1, and 2 times price field value 2. | |
478 | $myParams = $this->_params + array('participant_fee_level' => CRM_Core_DAO::VALUE_SEPARATOR . "pricefieldvalue1 - 2" . CRM_Core_DAO::VALUE_SEPARATOR . "pricefieldvalue2 - 2" . CRM_Core_DAO::VALUE_SEPARATOR); | |
479 | $participant = $this->callAPISuccess('participant', 'create', $myParams); | |
480 | ||
481 | // expect 2 line items. | |
482 | $lineItems = $this->callAPISuccess('LineItem', 'get', array( | |
483 | 'entity_id' => $participant['id'], | |
484 | 'entity_table' => 'civicrm_participant', | |
485 | )); | |
486 | ||
487 | $this->assertEquals(2, $lineItems['count']); | |
488 | ||
489 | // Check quantity, label and unit price of lines. | |
490 | // TODO: These assertions depend on the order of the line items, which is | |
491 | // technically incorrect. | |
d4df7755 JV |
492 | |
493 | $lineItem = array_pop($lineItems['values']); | |
494 | $this->assertEquals(2, $lineItem['qty']); | |
495 | $this->assertEquals(5, $lineItem['unit_price']); | |
496 | $this->assertEquals('pricefieldvalue2', $lineItem['label']); | |
497 | ||
498 | $lineItem = array_pop($lineItems['values']); | |
499 | $this->assertEquals(2, $lineItem['qty']); | |
500 | $this->assertEquals(20, $lineItem['unit_price']); | |
501 | $this->assertEquals('pricefieldvalue1', $lineItem['label']); | |
3233fd0f JV |
502 | |
503 | // Cleanup | |
504 | $this->callAPISuccess('participant', 'delete', array('id' => $participant['id'])); | |
505 | ||
506 | // TODO: I think the price set should be removed, but I don't know how | |
507 | // to decouple it properly from the event. For the moment, I'll just comment | |
508 | // out the lines below. | |
509 | ||
510 | /* | |
511 | $this->callAPISuccess('PriceFieldValue', 'delete', array('id' => $pfv1['id'])); | |
512 | $this->callAPISuccess('PriceFieldValue', 'delete', array('id' => $pfv2['id'])); | |
513 | $this->callAPISuccess('PriceField', 'delete', array('id' => $pricefield['id'])); | |
514 | $this->callAPISuccess('PriceSet', 'delete', array('id' => $priceset['id'])); | |
515 | */ | |
516 | } | |
517 | ||
afd404ea | 518 | /** |
519 | * check with complete array | |
520 | */ | |
521 | function testUpdate() { | |
6ead217b E |
522 | $participantId = $this->participantCreate(array( |
523 | 'contactID' => $this->_individualId, | |
524 | 'eventID' => $this->_eventID | |
525 | )); | |
afd404ea | 526 | $params = array( |
527 | 'id' => $participantId, | |
528 | 'contact_id' => $this->_individualId, | |
529 | 'event_id' => $this->_eventID, | |
530 | 'status_id' => 3, | |
531 | 'role_id' => 3, | |
532 | 'register_date' => '2006-01-21', | |
533 | 'source' => 'US Open', | |
afd404ea | 534 | ); |
535 | $participant = $this->callAPISuccess('participant', 'create', $params); | |
536 | $this->getAndCheck($params, $participant['id'], 'participant'); | |
537 | $result = $this->participantDelete($params['id']); | |
538 | } | |
539 | ||
540 | /** | |
541 | * Test to check if participant fee level is being changed per CRM-9781 | |
542 | * Try again without a custom separater to check that one isn't added | |
543 | * (get & check won't accept an array) | |
544 | */ | |
6a488035 TO |
545 | function testUpdateCreateParticipantFeeLevelNoSeparator() { |
546 | ||
547 | $myParams = $this->_params + array('participant_fee_level' => "fee"); | |
afd404ea | 548 | $participant = $this->callAPISuccess('participant', 'create', $myParams); |
6a488035 TO |
549 | $this->assertAPISuccess($participant); |
550 | $update = array( | |
afd404ea | 551 | 'id' => $participant['id'], |
6a488035 TO |
552 | 'status_id' => 2, |
553 | ); | |
afd404ea | 554 | $this->callAPISuccess('participant', 'create', $update); |
6a488035 TO |
555 | $this->assertEquals($participant['values'][$participant['id']]['fee_level'], |
556 | $myParams['participant_fee_level'] | |
557 | ); | |
558 | $this->getAndCheck($update, $participant['id'], 'participant'); | |
559 | } | |
560 | ///////////////// civicrm_participant_update methods | |
561 | ||
562 | /** | |
563 | * Test civicrm_participant_update with wrong params type | |
564 | */ | |
565 | function testUpdateWrongParamsType() { | |
566 | $params = 'a string'; | |
d0e1eff2 | 567 | $result = $this->callAPIFailure('participant', 'create', $params); |
6a488035 TO |
568 | $this->assertEquals('Input variable `params` is not an array', $result['error_message'], 'In line ' . __LINE__); |
569 | } | |
570 | ||
571 | /** | |
572 | * check with empty array | |
573 | */ | |
574 | function testUpdateEmptyParams() { | |
afd404ea | 575 | $params = array(); |
d0e1eff2 | 576 | $participant = $this->callAPIFailure('participant', 'create', $params); |
6a488035 TO |
577 | $this->assertEquals($participant['error_message'], 'Mandatory key(s) missing from params array: event_id, contact_id'); |
578 | } | |
579 | ||
580 | /** | |
581 | * check without event_id | |
582 | */ | |
583 | function testUpdateWithoutEventId() { | |
afd404ea | 584 | $participantId = $this->participantCreate(array('contactID' => $this->_individualId, 'eventID' => $this->_eventID)); |
6a488035 TO |
585 | $params = array( |
586 | 'contact_id' => $this->_individualId, | |
587 | 'status_id' => 3, | |
588 | 'role_id' => 3, | |
589 | 'register_date' => '2006-01-21', | |
590 | 'source' => 'US Open', | |
afd404ea | 591 | 'event_level' => 'Donation', ); |
d0e1eff2 | 592 | $participant = $this->callAPIFailure('participant', 'create', $params); |
6a488035 TO |
593 | $this->assertEquals($participant['error_message'], 'Mandatory key(s) missing from params array: event_id'); |
594 | // Cleanup created participant records. | |
595 | $result = $this->participantDelete($participantId); | |
596 | } | |
597 | ||
598 | /** | |
599 | * check with Invalid participantId | |
600 | */ | |
601 | function testUpdateWithWrongParticipantId() { | |
602 | $params = array( | |
603 | 'id' => 1234, | |
604 | 'status_id' => 3, | |
605 | 'role_id' => 3, | |
606 | 'register_date' => '2006-01-21', | |
607 | 'source' => 'US Open', | |
afd404ea | 608 | 'event_level' => 'Donation', ); |
d0e1eff2 | 609 | $participant = $this->callAPIFailure('Participant', 'update', $params); |
6a488035 TO |
610 | } |
611 | ||
612 | /** | |
613 | * check with Invalid ContactId | |
614 | */ | |
615 | function testUpdateWithWrongContactId() { | |
616 | $participantId = $this->participantCreate(array( | |
617 | 'contactID' => $this->_individualId, | |
618 | 'eventID' => $this->_eventID, | |
619 | ), $this->_apiversion); | |
620 | $params = array( | |
621 | 'id' => $participantId, | |
622 | 'contact_id' => 12345, | |
623 | 'status_id' => 3, | |
624 | 'role_id' => 3, | |
625 | 'register_date' => '2006-01-21', | |
626 | 'source' => 'US Open', | |
afd404ea | 627 | 'event_level' => 'Donation', ); |
d0e1eff2 | 628 | $participant = $this->callAPIFailure('participant', 'create', $params); |
6a488035 TO |
629 | $result = $this->participantDelete($participantId); |
630 | } | |
631 | ||
6a488035 TO |
632 | ///////////////// civicrm_participant_delete methods |
633 | ||
634 | /** | |
635 | * Test civicrm_participant_delete with wrong params type | |
636 | */ | |
637 | function testDeleteWrongParamsType() { | |
638 | $params = 'a string'; | |
d0e1eff2 | 639 | $result = $this->callAPIFailure('participant', 'delete', $params); |
6a488035 TO |
640 | } |
641 | ||
642 | /** | |
643 | * Test civicrm_participant_delete with empty params | |
644 | */ | |
645 | function testDeleteEmptyParams() { | |
646 | $params = array(); | |
d0e1eff2 | 647 | $result = $this->callAPIFailure('participant', 'delete', $params); |
6a488035 TO |
648 | } |
649 | ||
650 | /** | |
651 | * check with participant_id | |
652 | */ | |
653 | function testParticipantDelete() { | |
654 | $params = array( | |
afd404ea | 655 | 'id' => $this->_participantID, ); |
656 | $participant = $this->callAPISuccess('participant', 'delete', $params); | |
6a488035 TO |
657 | $this->assertAPISuccess($participant); |
658 | $this->assertDBState('CRM_Event_DAO_Participant', $this->_participantID, NULL, TRUE); | |
659 | } | |
660 | ||
661 | /** | |
662 | * check without participant_id | |
663 | * and with event_id | |
664 | * This should return an error because required param is missing.. | |
665 | */ | |
666 | function testParticipantDeleteMissingID() { | |
667 | $params = array( | |
afd404ea | 668 | 'event_id' => $this->_eventID, ); |
d0e1eff2 | 669 | $participant = $this->callAPIFailure('participant', 'delete', $params); |
6a488035 TO |
670 | $this->assertNotNull($participant['error_message']); |
671 | } | |
672 | /* | |
673 | * delete with a get - a 'criteria delete' | |
674 | */ | |
675 | function testNestedDelete() { | |
676 | $description = "Criteria delete by nesting a GET & a DELETE"; | |
677 | $subfile = "NestedDelete"; | |
afd404ea | 678 | $participants = $this->callAPISuccess('Participant', 'Get', array()); |
6a488035 | 679 | $this->assertEquals($participants['count'], 3); |
afd404ea | 680 | $params = array('contact_id' => $this->_contactID2, 'api.participant.delete' => 1); |
681 | $participants = $this->callAPIAndDocument('Participant', 'Get', $params, __FUNCTION__, __FILE__, $description, $subfile, 'Get'); | |
81e1a644 | 682 | $check = $this->callAPISuccess('participant', 'getcount', array()); |
683 | $this->assertEquals(1, $check,"only one participant should be left. line " . __LINE__); | |
6a488035 TO |
684 | } |
685 | /* | |
686 | * Test creation of a participant with an associated contribution | |
687 | */ | |
688 | function testCreateParticipantWithPayment() { | |
6a488035 TO |
689 | $description = "single function to create contact w partipation & contribution. Note that in the |
690 | case of 'contribution' the 'create' is implied (api.contribution.create)"; | |
691 | $subfile = "CreateParticipantPayment"; | |
692 | $params = array( | |
693 | 'contact_type' => 'Individual', | |
81e1a644 | 694 | 'display_name' => 'dlobo', |
695 | 'api.participant' => array( | |
6a488035 TO |
696 | 'event_id' => $this->_eventID, |
697 | 'status_id' => 1, | |
698 | 'role_id' => 1, | |
699 | 'format.only_id' => 1, | |
700 | ), | |
701 | 'api.contribution.create' => array( | |
702 | 'financial_type_id' => 1, | |
703 | 'total_amount' => 100, | |
704 | 'format.only_id' => 1, | |
705 | ), | |
706 | 'api.participant_payment.create' => array( | |
707 | 'contribution_id' => '$value.api.contribution.create', | |
708 | 'participant_id' => '$value.api.participant', | |
709 | ), | |
710 | ); | |
711 | ||
afd404ea | 712 | $result = $this->callAPIAndDocument('contact', 'create', $params, __FUNCTION__, __FILE__, $description, $subfile); |
6a488035 | 713 | $this->assertEquals(1, $result['values'][$result['id']]['api.participant_payment.create']['count']); |
afd404ea | 714 | $this->callAPISuccess('contact', 'delete', array('id' => $result['id'])); |
6a488035 | 715 | } |
6a488035 TO |
716 | } |
717 |