3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
29 * Class CRM_Event_BAO_ParticipantTest
32 class CRM_Event_BAO_ParticipantTest
extends CiviUnitTestCase
{
34 public function setUp() {
36 $this->_contactId
= $this->individualCreate();
37 $event = $this->eventCreate();
38 $this->_eventId
= $event['id'];
42 * Add() method (add and edit modes of participant)
44 public function testAdd() {
49 'event_id' => $this->_eventId
,
50 'register_date' => date('Y-m-d') . " 00:00:00",
53 'source' => 'Event_' . $this->_eventId
,
54 'contact_id' => $this->_contactId
,
57 // New Participant Created
58 $participant = CRM_Event_BAO_Participant
::add($params);
60 $this->assertDBNotNull('CRM_Event_BAO_Participant', $this->_contactId
, 'id',
61 'contact_id', 'Check DB for Participant of the contact'
64 $this->assertDBCompareValue('CRM_Event_BAO_Participant', $participant->id
, 'contact_id',
65 'id', $this->_contactId
, 'Check DB for contact of the participant'
68 $params = array_merge($params, array(
69 'id' => $participant->id
,
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'
80 $this->assertDBCompareValue('CRM_Event_BAO_Participant', $updatedParticipant->id
, 'status_id',
81 'id', 3, 'Check DB for updated status id of the participant'
84 $this->contactDelete($this->_contactId
);
85 $this->eventDelete($this->_eventId
);
89 * GetValues() method (fetch value of participant)
91 public function testgetValuesWithValidParams() {
92 $participantId = $this->participantCreate(array('contact_id' => $this->_contactId
, 'event_id' => $this->_eventId
));
93 $params = array('id' => $participantId);
94 $values = $ids = array();
96 $fetchParticipant = CRM_Event_BAO_Participant
::getValues($params, $values, $ids);
97 $compareValues = $fetchParticipant[$participantId];
103 'event_id' => $this->_eventId
,
104 'register_date' => '2007-02-19 00:00:00',
107 'source' => 'Wimbeldon',
108 'contact_id' => $this->_contactId
,
109 'id' => $participantId,
110 'campaign_id' => NULL,
112 'fee_amount' => NULL,
113 'registered_by_id' => NULL,
114 'discount_id' => NULL,
115 'fee_currency' => NULL,
116 'discount_amount' => NULL,
119 'transferred_to_contact_id' => NULL,
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');
128 $this->participantDelete($participantId);
129 $this->contactDelete($this->_contactId
);
130 $this->eventDelete($this->_eventId
);
134 * GetValues() method (checking for behavior when params are empty )
136 public function testgetValuesWithoutValidParams() {
137 $params = $values = $ids = array();
138 $this->participantCreate(array('contact_id' => $this->_contactId
, 'event_id' => $this->_eventId
));
139 $fetchParticipant = CRM_Event_BAO_Participant
::getValues($params, $values, $ids);
140 $this->assertNull($fetchParticipant);
142 $this->contactDelete($this->_contactId
);
143 $this->eventDelete($this->_eventId
);
147 * EventFull() method (checking the event for full )
149 public function testEventFull() {
150 $eventParams = array(
151 'max_participants' => 1,
152 'id' => $this->_eventId
,
154 CRM_Event_BAO_Event
::add($eventParams);
156 $participantId = $this->participantCreate(array('contact_id' => $this->_contactId
, 'event_id' => $this->_eventId
));
157 $eventFull = CRM_Event_BAO_Participant
::eventFull($this->_eventId
);
159 $this->assertEquals($eventFull, 'Sorry! We are already full', 'Checking if Event is full.');
161 $this->participantDelete($participantId);
162 $this->contactDelete($this->_contactId
);
163 $this->eventDelete($this->_eventId
);
167 * ImportableFields() method ( Checking the Event's Importable Fields )
169 public function testimportableFields() {
170 $importableFields = CRM_Event_BAO_Participant
::importableFields();
171 $this->assertNotEquals(count($importableFields), 0, 'Checking array not to be empty.');
173 $this->contactDelete($this->_contactId
);
174 $this->eventDelete($this->_eventId
);
178 * ParticipantDetails() method ( Checking the Participant Details )
180 public function testparticipantDetails() {
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');
184 $participantDetails = CRM_Event_BAO_Participant
::participantDetails($participant['id']);
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.');
190 $this->participantDelete($participant['id']);
191 $this->contactDelete($this->_contactId
);
192 $this->eventDelete($this->_eventId
);
196 * DeleteParticipant() method ( Delete a Participant )
198 public function testdeleteParticipant() {
203 'event_id' => $this->_eventId
,
204 'register_date' => date('Y-m-d') . " 00:00:00",
207 'source' => 'Event_' . $this->_eventId
,
208 'contact_id' => $this->_contactId
,
211 // New Participant Created
212 $participant = CRM_Event_BAO_Participant
::add($params);
214 $this->assertDBNotNull('CRM_Event_BAO_Participant', $this->_contactId
, 'id',
215 'contact_id', 'Check DB for Participant of the contact'
218 $this->assertDBCompareValue('CRM_Event_BAO_Participant', $participant->id
, 'contact_id',
219 'id', $this->_contactId
, 'Check DB for contact of the participant'
222 CRM_Event_BAO_Participant
::deleteParticipant($participant->id
);
223 $this->assertDBNull('CRM_Event_BAO_Participant', $participant->id
, 'contact_id', 'id', 'Check DB for deleted Participant.');
225 $this->contactDelete($this->_contactId
);
226 $this->eventDelete($this->_eventId
);
230 * CheckDuplicate() method ( Checking for Duplicate Participant returns array of participant id)
232 public function testcheckDuplicate() {
233 $duplicate = array();
235 //Creating 3 new participants
236 for ($i = 0; $i < 3; $i++
) {
237 $partiId[] = $this->participantCreate(array('contact_id' => $this->_contactId
, 'event_id' => $this->_eventId
));
240 $params = array('event_id' => $this->_eventId
, 'contact_id' => $this->_contactId
);
241 CRM_Event_BAO_Participant
::checkDuplicate($params, $duplicate);
243 $this->assertEquals(count($duplicate), 3, 'Equating the array contains with duplicate array.');
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.');
250 //Deleting all participant
251 for ($i = 0; $i < 3; $i++
) {
252 $partidel[] = $this->participantDelete($partiId[$i]);
255 $this->contactDelete($this->_contactId
);
256 $this->eventDelete($this->_eventId
);
260 * Create() method (create and updation of participant)
262 public function testCreate() {
267 'event_id' => $this->_eventId
,
268 'register_date' => date('Y-m-d') . " 00:00:00",
271 'source' => 'Event_' . $this->_eventId
,
272 'contact_id' => $this->_contactId
,
273 'note' => 'Note added for Event_' . $this->_eventId
,
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'
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'
287 $params = array_merge($params, array(
288 'id' => $participant->id
,
291 'note' => 'Test Event in edit mode is running successfully ....',
294 $participant = CRM_Event_BAO_Participant
::create($params);
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'
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'
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'
311 //Checking for Note added in the table for relative participant.
312 $session = CRM_Core_Session
::singleton();
313 $id = $session->get('userID');
315 $id = $this->_contactId
;
318 //Deleting the Participant created by create function in this function
319 CRM_Event_BAO_Participant
::deleteParticipant($participant->id
);
320 $this->assertDBNull('CRM_Event_DAO_Participant', $this->_contactId
, 'id',
321 'contact_id', 'Check DB for deleted participant. Should be NULL.'
324 $this->contactDelete($this->_contactId
);
325 $this->eventDelete($this->_eventId
);
329 * ExportableFields() method ( Exportable Fields for Participant)
331 public function testexportableFields() {
332 $exportableFields = CRM_Event_BAO_Participant
::exportableFields();
333 $this->assertNotEquals(count($exportableFields), 0, 'Checking array not to be empty.');
335 $this->contactDelete($this->_contactId
);
336 $this->eventDelete($this->_eventId
);
340 * FixEventLevel() method (Setting ',' values), resolveDefaults(assinging value to array) method
342 public function testfixEventLevel() {
344 $paramsSet['title'] = 'Price Set';
345 $paramsSet['name'] = CRM_Utils_String
::titleToVar('Price Set');
346 $paramsSet['is_active'] = FALSE;
347 $paramsSet['extends'] = 1;
349 $priceset = CRM_Price_BAO_PriceSet
::create($paramsSet);
351 //Checking for priceset added in the table.
352 $this->assertDBCompareValue('CRM_Price_BAO_PriceSet', $priceset->id
, 'title',
353 'id', $paramsSet['title'], 'Check DB for created priceset'
355 $paramsField = array(
356 'label' => 'Price Field',
357 'name' => CRM_Utils_String
::titleToVar('Price Field'),
358 'html_type' => 'Text',
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,
366 'options_per_line' => 1,
367 'is_active' => array('1' => 1),
368 'price_set_id' => $priceset->id
,
373 $pricefield = CRM_Price_BAO_PriceField
::create($paramsField, $ids);
375 //Checking for priceset added in the table.
376 $this->assertDBCompareValue('CRM_Price_BAO_PriceField', $pricefield->id
, 'label',
377 'id', $paramsField['label'], 'Check DB for created pricefield'
380 $eventId = $this->_eventId
;
381 $participantParams = array(
385 'event_id' => $eventId,
386 'register_date' => date('Y-m-d') . " 00:00:00",
389 'source' => 'Event_' . $eventId,
390 'contact_id' => $this->_contactId
,
391 'note' => 'Note added for Event_' . $eventId,
392 'fee_level' => '\ 1Price_Field - 55\ 1',
395 $participant = CRM_Event_BAO_Participant
::add($participantParams);
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'
404 $params = array('id' => $participant->id
);
406 CRM_Event_BAO_Participant
::getValues($params, $values, $ids);
407 $this->assertNotEquals(count($values), 0, 'Checking for empty array.');
409 CRM_Event_BAO_Participant
::resolveDefaults($values[$participant->id
]);
411 if ($values[$participant->id
]['fee_level']) {
412 CRM_Event_BAO_Participant
::fixEventLevel($values[$participant->id
]['fee_level']);
415 CRM_Price_BAO_PriceField
::deleteField($pricefield->id
);
416 $this->assertDBNull('CRM_Price_BAO_PriceField', $pricefield->id
, 'name',
417 'id', 'Check DB for non-existence of Price Field.'
420 CRM_Price_BAO_PriceSet
::deleteSet($priceset->id
);
421 $this->assertDBNull('CRM_Price_BAO_PriceSet', $priceset->id
, 'title',
422 'id', 'Check DB for non-existence of Price Set.'
425 $this->participantDelete($participant->id
);
426 $this->contactDelete($this->_contactId
);
427 $this->eventDelete($eventId);