Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
2fe49090 | 4 | | CiviCRM version 5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
6b83d5bd | 6 | | Copyright CiviCRM LLC (c) 2004-2019 | |
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 | 27 | |
4cbe18b8 EM |
28 | /** |
29 | * Class CRM_Event_BAO_ParticipantTest | |
acb109b7 | 30 | * @group headless |
4cbe18b8 | 31 | */ |
6a488035 | 32 | class CRM_Event_BAO_ParticipantTest extends CiviUnitTestCase { |
6a488035 | 33 | |
00be9182 | 34 | public function setUp() { |
6a488035 | 35 | parent::setUp(); |
6ae19242 | 36 | $this->_contactId = $this->individualCreate(); |
37 | $event = $this->eventCreate(); | |
38 | $this->_eventId = $event['id']; | |
6a488035 TO |
39 | } |
40 | ||
41 | /** | |
100fef9d | 42 | * Add() method (add and edit modes of participant) |
6a488035 | 43 | */ |
00be9182 | 44 | public function testAdd() { |
6a488035 TO |
45 | $params = array( |
46 | 'send_receipt' => 1, | |
47 | 'is_test' => 0, | |
48 | 'is_pay_later' => 0, | |
49 | 'event_id' => $this->_eventId, | |
50 | 'register_date' => date('Y-m-d') . " 00:00:00", | |
51 | 'role_id' => 1, | |
52 | 'status_id' => 1, | |
53 | 'source' => 'Event_' . $this->_eventId, | |
54 | 'contact_id' => $this->_contactId, | |
55 | ); | |
56 | ||
57 | // New Participant Created | |
58 | $participant = CRM_Event_BAO_Participant::add($params); | |
59 | ||
60 | $this->assertDBNotNull('CRM_Event_BAO_Participant', $this->_contactId, 'id', | |
61 | 'contact_id', 'Check DB for Participant of the contact' | |
62 | ); | |
63 | ||
64 | $this->assertDBCompareValue('CRM_Event_BAO_Participant', $participant->id, 'contact_id', | |
65 | 'id', $this->_contactId, 'Check DB for contact of the participant' | |
66 | ); | |
67 | ||
68 | $params = array_merge($params, array( | |
92915c55 TO |
69 | 'id' => $participant->id, |
70 | 'role_id' => 2, | |
71 | 'status_id' => 3, | |
72 | )); | |
6a488035 TO |
73 | |
74 | // Participant Edited | |
75 | $updatedParticipant = CRM_Event_BAO_Participant::add($params); | |
76 | $this->assertDBCompareValue('CRM_Event_BAO_Participant', $updatedParticipant->id, 'role_id', | |
77 | 'id', 2, 'Check DB for updated role id of the participant' | |
78 | ); | |
79 | ||
80 | $this->assertDBCompareValue('CRM_Event_BAO_Participant', $updatedParticipant->id, 'status_id', | |
81 | 'id', 3, 'Check DB for updated status id of the participant' | |
82 | ); | |
83 | ||
93ac19cd | 84 | $this->contactDelete($this->_contactId); |
6ae19242 | 85 | $this->eventDelete($this->_eventId); |
6a488035 TO |
86 | } |
87 | ||
88 | /** | |
100fef9d | 89 | * GetValues() method (fetch value of participant) |
6a488035 | 90 | */ |
00be9182 | 91 | public function testgetValuesWithValidParams() { |
6ae19242 | 92 | $participantId = $this->participantCreate(array('contact_id' => $this->_contactId, 'event_id' => $this->_eventId)); |
6a488035 | 93 | $params = array('id' => $participantId); |
4b27d4ec | 94 | $values = $ids = array(); |
6a488035 TO |
95 | |
96 | $fetchParticipant = CRM_Event_BAO_Participant::getValues($params, $values, $ids); | |
97 | $compareValues = $fetchParticipant[$participantId]; | |
98 | ||
99 | $params = array( | |
100 | 'send_receipt' => 1, | |
101 | 'is_test' => 0, | |
102 | 'is_pay_later' => 0, | |
103 | 'event_id' => $this->_eventId, | |
6ae19242 | 104 | 'register_date' => '2007-02-19 00:00:00', |
6a488035 | 105 | 'role_id' => 1, |
6ae19242 | 106 | 'status_id' => 2, |
107 | 'source' => 'Wimbeldon', | |
6a488035 TO |
108 | 'contact_id' => $this->_contactId, |
109 | 'id' => $participantId, | |
4b27d4ec | 110 | 'campaign_id' => NULL, |
6a488035 TO |
111 | 'fee_level' => NULL, |
112 | 'fee_amount' => NULL, | |
113 | 'registered_by_id' => NULL, | |
114 | 'discount_id' => NULL, | |
115 | 'fee_currency' => NULL, | |
4b27d4ec E |
116 | 'discount_amount' => NULL, |
117 | 'cart_id' => NULL, | |
118 | 'must_wait' => NULL, | |
6ae19242 | 119 | 'transferred_to_contact_id' => NULL, |
6a488035 TO |
120 | ); |
121 | ||
122 | foreach ($compareValues as $key => $value) { | |
123 | if (substr($key, 0, 1) != '_' && $key != 'N') { | |
124 | $this->assertEquals($compareValues->$key, $params[$key], 'Check for ' . $key . ' for given participant'); | |
125 | } | |
126 | } | |
127 | ||
6ae19242 | 128 | $this->participantDelete($participantId); |
93ac19cd | 129 | $this->contactDelete($this->_contactId); |
6ae19242 | 130 | $this->eventDelete($this->_eventId); |
6a488035 TO |
131 | } |
132 | ||
133 | /** | |
100fef9d | 134 | * GetValues() method (checking for behavior when params are empty ) |
6a488035 | 135 | */ |
00be9182 | 136 | public function testgetValuesWithoutValidParams() { |
92915c55 | 137 | $params = $values = $ids = array(); |
6ae19242 | 138 | $this->participantCreate(array('contact_id' => $this->_contactId, 'event_id' => $this->_eventId)); |
6a488035 | 139 | $fetchParticipant = CRM_Event_BAO_Participant::getValues($params, $values, $ids); |
a15773db | 140 | $this->assertNull($fetchParticipant); |
6a488035 | 141 | |
93ac19cd | 142 | $this->contactDelete($this->_contactId); |
6ae19242 | 143 | $this->eventDelete($this->_eventId); |
6a488035 TO |
144 | } |
145 | ||
146 | /** | |
100fef9d | 147 | * EventFull() method (checking the event for full ) |
6a488035 | 148 | */ |
00be9182 | 149 | public function testEventFull() { |
6a488035 TO |
150 | $eventParams = array( |
151 | 'max_participants' => 1, | |
152 | 'id' => $this->_eventId, | |
153 | ); | |
154 | CRM_Event_BAO_Event::add($eventParams); | |
155 | ||
6ae19242 | 156 | $participantId = $this->participantCreate(array('contact_id' => $this->_contactId, 'event_id' => $this->_eventId)); |
6a488035 TO |
157 | $eventFull = CRM_Event_BAO_Participant::eventFull($this->_eventId); |
158 | ||
6ae19242 | 159 | $this->assertEquals($eventFull, 'Sorry! We are already full', 'Checking if Event is full.'); |
6a488035 | 160 | |
6ae19242 | 161 | $this->participantDelete($participantId); |
93ac19cd | 162 | $this->contactDelete($this->_contactId); |
6ae19242 | 163 | $this->eventDelete($this->_eventId); |
6a488035 TO |
164 | } |
165 | ||
166 | /** | |
100fef9d | 167 | * ImportableFields() method ( Checking the Event's Importable Fields ) |
6a488035 | 168 | */ |
00be9182 | 169 | public function testimportableFields() { |
6a488035 TO |
170 | $importableFields = CRM_Event_BAO_Participant::importableFields(); |
171 | $this->assertNotEquals(count($importableFields), 0, 'Checking array not to be empty.'); | |
172 | ||
93ac19cd | 173 | $this->contactDelete($this->_contactId); |
6ae19242 | 174 | $this->eventDelete($this->_eventId); |
6a488035 TO |
175 | } |
176 | ||
177 | /** | |
100fef9d | 178 | * ParticipantDetails() method ( Checking the Participant Details ) |
6a488035 | 179 | */ |
00be9182 | 180 | public function testparticipantDetails() { |
6ae19242 | 181 | $participant = $this->callAPISuccess('Participant', 'create', array('contact_id' => $this->_contactId, 'event_id' => $this->_eventId)); |
182 | $params = array('name' => 'Anderson, Anthony', 'title' => 'Annual CiviCRM meet'); | |
6a488035 | 183 | |
6ae19242 | 184 | $participantDetails = CRM_Event_BAO_Participant::participantDetails($participant['id']); |
6a488035 TO |
185 | |
186 | $this->assertEquals(count($participantDetails), 3, 'Equating the array contains.'); | |
187 | $this->assertEquals($participantDetails['name'], $params['name'], 'Checking Name of Participant.'); | |
188 | $this->assertEquals($participantDetails['title'], $params['title'], 'Checking Event Title in which participant is enroled.'); | |
189 | ||
6ae19242 | 190 | $this->participantDelete($participant['id']); |
93ac19cd | 191 | $this->contactDelete($this->_contactId); |
6ae19242 | 192 | $this->eventDelete($this->_eventId); |
6a488035 TO |
193 | } |
194 | ||
195 | /** | |
100fef9d | 196 | * DeleteParticipant() method ( Delete a Participant ) |
6a488035 | 197 | */ |
00be9182 | 198 | public function testdeleteParticipant() { |
6a488035 TO |
199 | $params = array( |
200 | 'send_receipt' => 1, | |
201 | 'is_test' => 0, | |
202 | 'is_pay_later' => 0, | |
203 | 'event_id' => $this->_eventId, | |
204 | 'register_date' => date('Y-m-d') . " 00:00:00", | |
205 | 'role_id' => 1, | |
206 | 'status_id' => 1, | |
207 | 'source' => 'Event_' . $this->_eventId, | |
208 | 'contact_id' => $this->_contactId, | |
209 | ); | |
210 | ||
211 | // New Participant Created | |
212 | $participant = CRM_Event_BAO_Participant::add($params); | |
213 | ||
214 | $this->assertDBNotNull('CRM_Event_BAO_Participant', $this->_contactId, 'id', | |
215 | 'contact_id', 'Check DB for Participant of the contact' | |
216 | ); | |
217 | ||
218 | $this->assertDBCompareValue('CRM_Event_BAO_Participant', $participant->id, 'contact_id', | |
219 | 'id', $this->_contactId, 'Check DB for contact of the participant' | |
220 | ); | |
221 | ||
93ac19cd | 222 | CRM_Event_BAO_Participant::deleteParticipant($participant->id); |
6a488035 TO |
223 | $this->assertDBNull('CRM_Event_BAO_Participant', $participant->id, 'contact_id', 'id', 'Check DB for deleted Participant.'); |
224 | ||
93ac19cd | 225 | $this->contactDelete($this->_contactId); |
6ae19242 | 226 | $this->eventDelete($this->_eventId); |
6a488035 TO |
227 | } |
228 | ||
229 | /** | |
100fef9d | 230 | * CheckDuplicate() method ( Checking for Duplicate Participant returns array of participant id) |
6a488035 | 231 | */ |
00be9182 | 232 | public function testcheckDuplicate() { |
6a488035 TO |
233 | $duplicate = array(); |
234 | ||
235 | //Creating 3 new participants | |
236 | for ($i = 0; $i < 3; $i++) { | |
23ead872 | 237 | $partiId[] = $this->participantCreate(array('contact_id' => $this->_contactId, 'event_id' => $this->_eventId)); |
6a488035 TO |
238 | } |
239 | ||
240 | $params = array('event_id' => $this->_eventId, 'contact_id' => $this->_contactId); | |
6ae19242 | 241 | CRM_Event_BAO_Participant::checkDuplicate($params, $duplicate); |
6a488035 TO |
242 | |
243 | $this->assertEquals(count($duplicate), 3, 'Equating the array contains with duplicate array.'); | |
244 | ||
245 | //Checking for the duplicate participant | |
246 | foreach ($duplicate as $key => $value) { | |
247 | $this->assertEquals($partiId[$key], $duplicate[$key], 'Equating the contactid which is in the database.'); | |
248 | } | |
249 | ||
250 | //Deleting all participant | |
251 | for ($i = 0; $i < 3; $i++) { | |
6ae19242 | 252 | $partidel[] = $this->participantDelete($partiId[$i]); |
6a488035 TO |
253 | } |
254 | ||
93ac19cd | 255 | $this->contactDelete($this->_contactId); |
6ae19242 | 256 | $this->eventDelete($this->_eventId); |
6a488035 TO |
257 | } |
258 | ||
259 | /** | |
100fef9d | 260 | * Create() method (create and updation of participant) |
6a488035 | 261 | */ |
00be9182 | 262 | public function testCreate() { |
6a488035 TO |
263 | $params = array( |
264 | 'send_receipt' => 1, | |
265 | 'is_test' => 0, | |
266 | 'is_pay_later' => 0, | |
267 | 'event_id' => $this->_eventId, | |
268 | 'register_date' => date('Y-m-d') . " 00:00:00", | |
269 | 'role_id' => 1, | |
270 | 'status_id' => 1, | |
271 | 'source' => 'Event_' . $this->_eventId, | |
272 | 'contact_id' => $this->_contactId, | |
273 | 'note' => 'Note added for Event_' . $this->_eventId, | |
274 | ); | |
275 | ||
276 | $participant = CRM_Event_BAO_Participant::create($params); | |
277 | //Checking for Contact id in the participant table. | |
278 | $pid = $this->assertDBNotNull('CRM_Event_DAO_Participant', $this->_contactId, 'id', | |
279 | 'contact_id', 'Check DB for Participant of the contact' | |
280 | ); | |
281 | ||
282 | //Checking for Activity added in the table for relative participant. | |
283 | $this->assertDBCompareValue('CRM_Activity_DAO_Activity', $this->_contactId, 'source_record_id', | |
284 | 'source_contact_id', $participant->id, 'Check DB for activity added for the participant' | |
285 | ); | |
286 | ||
287 | $params = array_merge($params, array( | |
288 | 'id' => $participant->id, | |
92915c55 TO |
289 | 'role_id' => 2, |
290 | 'status_id' => 3, | |
291 | 'note' => 'Test Event in edit mode is running successfully ....', | |
292 | )); | |
6a488035 TO |
293 | |
294 | $participant = CRM_Event_BAO_Participant::create($params); | |
295 | ||
296 | //Checking Edited Value of role_id in the database. | |
297 | $this->assertDBCompareValue('CRM_Event_DAO_Participant', $participant->id, 'role_id', | |
298 | 'id', 2, 'Check DB for updated role id of the participant' | |
299 | ); | |
300 | ||
301 | //Checking Edited Value of status_id in the database. | |
302 | $this->assertDBCompareValue('CRM_Event_DAO_Participant', $participant->id, 'status_id', | |
303 | 'id', 3, 'Check DB for updated status id of the participant' | |
304 | ); | |
305 | ||
306 | //Checking for Activity added in the table for relative participant. | |
307 | $this->assertDBCompareValue('CRM_Activity_DAO_Activity', $this->_contactId, 'source_record_id', | |
308 | 'source_contact_id', $participant->id, 'Check DB for activity added for the participant' | |
309 | ); | |
310 | ||
311 | //Checking for Note added in the table for relative participant. | |
312 | $session = CRM_Core_Session::singleton(); | |
313 | $id = $session->get('userID'); | |
314 | if (!$id) { | |
315 | $id = $this->_contactId; | |
316 | } | |
317 | ||
318 | //Deleting the Participant created by create function in this function | |
23ead872 | 319 | CRM_Event_BAO_Participant::deleteParticipant($participant->id); |
6a488035 TO |
320 | $this->assertDBNull('CRM_Event_DAO_Participant', $this->_contactId, 'id', |
321 | 'contact_id', 'Check DB for deleted participant. Should be NULL.' | |
322 | ); | |
323 | ||
93ac19cd | 324 | $this->contactDelete($this->_contactId); |
6ae19242 | 325 | $this->eventDelete($this->_eventId); |
6a488035 TO |
326 | } |
327 | ||
328 | /** | |
100fef9d | 329 | * ExportableFields() method ( Exportable Fields for Participant) |
6a488035 | 330 | */ |
00be9182 | 331 | public function testexportableFields() { |
6a488035 TO |
332 | $exportableFields = CRM_Event_BAO_Participant::exportableFields(); |
333 | $this->assertNotEquals(count($exportableFields), 0, 'Checking array not to be empty.'); | |
334 | ||
93ac19cd | 335 | $this->contactDelete($this->_contactId); |
6ae19242 | 336 | $this->eventDelete($this->_eventId); |
6a488035 TO |
337 | } |
338 | ||
339 | /** | |
100fef9d | 340 | * FixEventLevel() method (Setting ',' values), resolveDefaults(assinging value to array) method |
6a488035 | 341 | */ |
00be9182 | 342 | public function testfixEventLevel() { |
6a488035 TO |
343 | |
344 | $paramsSet['title'] = 'Price Set'; | |
345 | $paramsSet['name'] = CRM_Utils_String::titleToVar('Price Set'); | |
4b27d4ec | 346 | $paramsSet['is_active'] = FALSE; |
6a488035 TO |
347 | $paramsSet['extends'] = 1; |
348 | ||
9da8dc8c | 349 | $priceset = CRM_Price_BAO_PriceSet::create($paramsSet); |
6a488035 TO |
350 | |
351 | //Checking for priceset added in the table. | |
9da8dc8c | 352 | $this->assertDBCompareValue('CRM_Price_BAO_PriceSet', $priceset->id, 'title', |
6a488035 TO |
353 | 'id', $paramsSet['title'], 'Check DB for created priceset' |
354 | ); | |
355 | $paramsField = array( | |
356 | 'label' => 'Price Field', | |
357 | 'name' => CRM_Utils_String::titleToVar('Price Field'), | |
358 | 'html_type' => 'Text', | |
359 | 'price' => 10, | |
360 | 'option_label' => array('1' => 'Price Field'), | |
361 | 'option_value' => array('1' => 10), | |
362 | 'option_name' => array('1' => 10), | |
363 | 'option_weight' => array('1' => 1), | |
364 | 'is_display_amounts' => 1, | |
365 | 'weight' => 1, | |
366 | 'options_per_line' => 1, | |
367 | 'is_active' => array('1' => 1), | |
368 | 'price_set_id' => $priceset->id, | |
369 | 'is_enter_qty' => 1, | |
370 | ); | |
371 | ||
372 | $ids = array(); | |
9da8dc8c | 373 | $pricefield = CRM_Price_BAO_PriceField::create($paramsField, $ids); |
6a488035 TO |
374 | |
375 | //Checking for priceset added in the table. | |
9da8dc8c | 376 | $this->assertDBCompareValue('CRM_Price_BAO_PriceField', $pricefield->id, 'label', |
6a488035 TO |
377 | 'id', $paramsField['label'], 'Check DB for created pricefield' |
378 | ); | |
379 | ||
380 | $eventId = $this->_eventId; | |
381 | $participantParams = array( | |
382 | 'send_receipt' => 1, | |
383 | 'is_test' => 0, | |
384 | 'is_pay_later' => 0, | |
385 | 'event_id' => $eventId, | |
386 | 'register_date' => date('Y-m-d') . " 00:00:00", | |
387 | 'role_id' => 1, | |
388 | 'status_id' => 1, | |
389 | 'source' => 'Event_' . $eventId, | |
390 | 'contact_id' => $this->_contactId, | |
391 | 'note' => 'Note added for Event_' . $eventId, | |
392 | 'fee_level' => '\ 1Price_Field - 55\ 1', | |
393 | ); | |
394 | ||
395 | $participant = CRM_Event_BAO_Participant::add($participantParams); | |
396 | ||
397 | //Checking for participant added in the table. | |
398 | $this->assertDBCompareValue('CRM_Event_BAO_Participant', $this->_contactId, 'id', | |
399 | 'contact_id', $participant->id, 'Check DB for created participant' | |
400 | ); | |
401 | ||
402 | $values = array(); | |
92915c55 | 403 | $ids = array(); |
6a488035 TO |
404 | $params = array('id' => $participant->id); |
405 | ||
406 | CRM_Event_BAO_Participant::getValues($params, $values, $ids); | |
407 | $this->assertNotEquals(count($values), 0, 'Checking for empty array.'); | |
408 | ||
409 | CRM_Event_BAO_Participant::resolveDefaults($values[$participant->id]); | |
410 | ||
411 | if ($values[$participant->id]['fee_level']) { | |
412 | CRM_Event_BAO_Participant::fixEventLevel($values[$participant->id]['fee_level']); | |
413 | } | |
414 | ||
93ac19cd | 415 | CRM_Price_BAO_PriceField::deleteField($pricefield->id); |
9da8dc8c | 416 | $this->assertDBNull('CRM_Price_BAO_PriceField', $pricefield->id, 'name', |
6a488035 TO |
417 | 'id', 'Check DB for non-existence of Price Field.' |
418 | ); | |
419 | ||
93ac19cd | 420 | CRM_Price_BAO_PriceSet::deleteSet($priceset->id); |
9da8dc8c | 421 | $this->assertDBNull('CRM_Price_BAO_PriceSet', $priceset->id, 'title', |
6a488035 TO |
422 | 'id', 'Check DB for non-existence of Price Set.' |
423 | ); | |
424 | ||
6ae19242 | 425 | $this->participantDelete($participant->id); |
93ac19cd | 426 | $this->contactDelete($this->_contactId); |
6ae19242 | 427 | $this->eventDelete($eventId); |
6a488035 | 428 | } |
96025800 | 429 | |
6a488035 | 430 | } |