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
33 class CRM_Event_BAO_ParticipantTest
extends CiviUnitTestCase
{
35 public function setUp() {
37 $this->_contactId
= $this->individualCreate();
38 $event = $this->eventCreate();
39 $this->_eventId
= $event['id'];
43 * Add() method (add and edit modes of participant)
45 public function testAdd() {
50 'event_id' => $this->_eventId
,
51 'register_date' => date('Y-m-d') . " 00:00:00",
54 'source' => 'Event_' . $this->_eventId
,
55 'contact_id' => $this->_contactId
,
58 // New Participant Created
59 $participant = CRM_Event_BAO_Participant
::add($params);
61 $this->assertDBNotNull('CRM_Event_BAO_Participant', $this->_contactId
, 'id',
62 'contact_id', 'Check DB for Participant of the contact'
65 $this->assertDBCompareValue('CRM_Event_BAO_Participant', $participant->id
, 'contact_id',
66 'id', $this->_contactId
, 'Check DB for contact of the participant'
69 $params = array_merge($params, [
70 'id' => $participant->id
,
76 $updatedParticipant = CRM_Event_BAO_Participant
::add($params);
77 $this->assertDBCompareValue('CRM_Event_BAO_Participant', $updatedParticipant->id
, 'role_id',
78 'id', 2, 'Check DB for updated role id of the participant'
81 $this->assertDBCompareValue('CRM_Event_BAO_Participant', $updatedParticipant->id
, 'status_id',
82 'id', 3, 'Check DB for updated status id of the participant'
85 $this->contactDelete($this->_contactId
);
86 $this->eventDelete($this->_eventId
);
90 * GetValues() method (fetch value of participant)
92 public function testgetValuesWithValidParams() {
93 $participantId = $this->participantCreate(['contact_id' => $this->_contactId
, 'event_id' => $this->_eventId
]);
94 $params = ['id' => $participantId];
97 $fetchParticipant = CRM_Event_BAO_Participant
::getValues($params, $values, $ids);
98 $compareValues = $fetchParticipant[$participantId];
104 'event_id' => $this->_eventId
,
105 'register_date' => '2007-02-19 00:00:00',
108 'source' => 'Wimbeldon',
109 'contact_id' => $this->_contactId
,
110 'id' => $participantId,
111 'campaign_id' => NULL,
113 'fee_amount' => NULL,
114 'registered_by_id' => NULL,
115 'discount_id' => NULL,
116 'fee_currency' => NULL,
117 'discount_amount' => NULL,
120 'transferred_to_contact_id' => NULL,
123 foreach ($compareValues as $key => $value) {
124 if (substr($key, 0, 1) != '_' && $key != 'N') {
125 $this->assertEquals($compareValues->$key, $params[$key], 'Check for ' . $key . ' for given participant');
129 $this->participantDelete($participantId);
130 $this->contactDelete($this->_contactId
);
131 $this->eventDelete($this->_eventId
);
135 * GetValues() method (checking for behavior when params are empty )
137 public function testgetValuesWithoutValidParams() {
138 $params = $values = $ids = [];
139 $this->participantCreate(['contact_id' => $this->_contactId
, 'event_id' => $this->_eventId
]);
140 $fetchParticipant = CRM_Event_BAO_Participant
::getValues($params, $values, $ids);
141 $this->assertNull($fetchParticipant);
143 $this->contactDelete($this->_contactId
);
144 $this->eventDelete($this->_eventId
);
148 * EventFull() method (checking the event for full )
150 public function testEventFull() {
152 'max_participants' => 1,
153 'id' => $this->_eventId
,
155 CRM_Event_BAO_Event
::add($eventParams);
157 $participantId = $this->participantCreate(['contact_id' => $this->_contactId
, 'event_id' => $this->_eventId
]);
158 $eventFull = CRM_Event_BAO_Participant
::eventFull($this->_eventId
);
160 $this->assertEquals($eventFull, 'Sorry! We are already full', 'Checking if Event is full.');
162 $this->participantDelete($participantId);
163 $this->contactDelete($this->_contactId
);
164 $this->eventDelete($this->_eventId
);
168 * ImportableFields() method ( Checking the Event's Importable Fields )
170 public function testimportableFields() {
171 $importableFields = CRM_Event_BAO_Participant
::importableFields();
172 $this->assertNotEquals(count($importableFields), 0, 'Checking array not to be empty.');
174 $this->contactDelete($this->_contactId
);
175 $this->eventDelete($this->_eventId
);
179 * ParticipantDetails() method ( Checking the Participant Details )
181 public function testparticipantDetails() {
182 $participant = $this->callAPISuccess('Participant', 'create', ['contact_id' => $this->_contactId
, 'event_id' => $this->_eventId
]);
183 $params = ['name' => 'Anderson, Anthony', 'title' => 'Annual CiviCRM meet'];
185 $participantDetails = CRM_Event_BAO_Participant
::participantDetails($participant['id']);
187 $this->assertEquals(count($participantDetails), 3, 'Equating the array contains.');
188 $this->assertEquals($participantDetails['name'], $params['name'], 'Checking Name of Participant.');
189 $this->assertEquals($participantDetails['title'], $params['title'], 'Checking Event Title in which participant is enroled.');
191 $this->participantDelete($participant['id']);
192 $this->contactDelete($this->_contactId
);
193 $this->eventDelete($this->_eventId
);
197 * DeleteParticipant() method ( Delete a Participant )
199 public function testdeleteParticipant() {
204 'event_id' => $this->_eventId
,
205 'register_date' => date('Y-m-d') . " 00:00:00",
208 'source' => 'Event_' . $this->_eventId
,
209 'contact_id' => $this->_contactId
,
212 // New Participant Created
213 $participant = CRM_Event_BAO_Participant
::add($params);
215 $this->assertDBNotNull('CRM_Event_BAO_Participant', $this->_contactId
, 'id',
216 'contact_id', 'Check DB for Participant of the contact'
219 $this->assertDBCompareValue('CRM_Event_BAO_Participant', $participant->id
, 'contact_id',
220 'id', $this->_contactId
, 'Check DB for contact of the participant'
223 CRM_Event_BAO_Participant
::deleteParticipant($participant->id
);
224 $this->assertDBNull('CRM_Event_BAO_Participant', $participant->id
, 'contact_id', 'id', 'Check DB for deleted Participant.');
226 $this->contactDelete($this->_contactId
);
227 $this->eventDelete($this->_eventId
);
231 * CheckDuplicate() method ( Checking for Duplicate Participant returns array of participant id)
233 public function testcheckDuplicate() {
236 //Creating 3 new participants
237 for ($i = 0; $i < 3; $i++
) {
238 $partiId[] = $this->participantCreate(['contact_id' => $this->_contactId
, 'event_id' => $this->_eventId
]);
241 $params = ['event_id' => $this->_eventId
, 'contact_id' => $this->_contactId
];
242 CRM_Event_BAO_Participant
::checkDuplicate($params, $duplicate);
244 $this->assertEquals(count($duplicate), 3, 'Equating the array contains with duplicate array.');
246 //Checking for the duplicate participant
247 foreach ($duplicate as $key => $value) {
248 $this->assertEquals($partiId[$key], $duplicate[$key], 'Equating the contactid which is in the database.');
251 //Deleting all participant
252 for ($i = 0; $i < 3; $i++
) {
253 $partidel[] = $this->participantDelete($partiId[$i]);
256 $this->contactDelete($this->_contactId
);
257 $this->eventDelete($this->_eventId
);
261 * Create() method (create and updation of participant)
263 public function testCreate() {
268 'event_id' => $this->_eventId
,
269 'register_date' => date('Y-m-d') . " 00:00:00",
272 'source' => 'Event_' . $this->_eventId
,
273 'contact_id' => $this->_contactId
,
274 'note' => 'Note added for Event_' . $this->_eventId
,
277 $participant = CRM_Event_BAO_Participant
::create($params);
278 //Checking for Contact id in the participant table.
279 $pid = $this->assertDBNotNull('CRM_Event_DAO_Participant', $this->_contactId
, 'id',
280 'contact_id', 'Check DB for Participant of the contact'
283 //Checking for Activity added in the table for relative participant.
284 $this->assertDBCompareValue('CRM_Activity_DAO_Activity', $this->_contactId
, 'source_record_id',
285 'source_contact_id', $participant->id
, 'Check DB for activity added for the participant'
288 $params = array_merge($params, [
289 'id' => $participant->id
,
292 'note' => 'Test Event in edit mode is running successfully ....',
295 $participant = CRM_Event_BAO_Participant
::create($params);
297 //Checking Edited Value of role_id in the database.
298 $this->assertDBCompareValue('CRM_Event_DAO_Participant', $participant->id
, 'role_id',
299 'id', 2, 'Check DB for updated role id of the participant'
302 //Checking Edited Value of status_id in the database.
303 $this->assertDBCompareValue('CRM_Event_DAO_Participant', $participant->id
, 'status_id',
304 'id', 3, 'Check DB for updated status id of the participant'
307 //Checking for Activity added in the table for relative participant.
308 $this->assertDBCompareValue('CRM_Activity_DAO_Activity', $this->_contactId
, 'source_record_id',
309 'source_contact_id', $participant->id
, 'Check DB for activity added for the participant'
312 //Checking for Note added in the table for relative participant.
313 $session = CRM_Core_Session
::singleton();
314 $id = $session->get('userID');
316 $id = $this->_contactId
;
319 //Deleting the Participant created by create function in this function
320 CRM_Event_BAO_Participant
::deleteParticipant($participant->id
);
321 $this->assertDBNull('CRM_Event_DAO_Participant', $this->_contactId
, 'id',
322 'contact_id', 'Check DB for deleted participant. Should be NULL.'
325 $this->contactDelete($this->_contactId
);
326 $this->eventDelete($this->_eventId
);
330 * ExportableFields() method ( Exportable Fields for Participant)
332 public function testexportableFields() {
333 $exportableFields = CRM_Event_BAO_Participant
::exportableFields();
334 $this->assertNotEquals(count($exportableFields), 0, 'Checking array not to be empty.');
336 $this->contactDelete($this->_contactId
);
337 $this->eventDelete($this->_eventId
);
341 * FixEventLevel() method (Setting ',' values), resolveDefaults(assinging value to array) method
343 public function testfixEventLevel() {
345 $paramsSet['title'] = 'Price Set';
346 $paramsSet['name'] = CRM_Utils_String
::titleToVar('Price Set');
347 $paramsSet['is_active'] = FALSE;
348 $paramsSet['extends'] = 1;
350 $priceset = CRM_Price_BAO_PriceSet
::create($paramsSet);
352 //Checking for priceset added in the table.
353 $this->assertDBCompareValue('CRM_Price_BAO_PriceSet', $priceset->id
, 'title',
354 'id', $paramsSet['title'], 'Check DB for created priceset'
357 'label' => 'Price Field',
358 'name' => CRM_Utils_String
::titleToVar('Price Field'),
359 'html_type' => 'Text',
361 'option_label' => ['1' => 'Price Field'],
362 'option_value' => ['1' => 10],
363 'option_name' => ['1' => 10],
364 'option_weight' => ['1' => 1],
365 'is_display_amounts' => 1,
367 'options_per_line' => 1,
368 'is_active' => ['1' => 1],
369 'price_set_id' => $priceset->id
,
374 $pricefield = CRM_Price_BAO_PriceField
::create($paramsField, $ids);
376 //Checking for priceset added in the table.
377 $this->assertDBCompareValue('CRM_Price_BAO_PriceField', $pricefield->id
, 'label',
378 'id', $paramsField['label'], 'Check DB for created pricefield'
381 $eventId = $this->_eventId
;
382 $participantParams = [
386 'event_id' => $eventId,
387 'register_date' => date('Y-m-d') . " 00:00:00",
390 'source' => 'Event_' . $eventId,
391 'contact_id' => $this->_contactId
,
392 'note' => 'Note added for Event_' . $eventId,
393 'fee_level' => '\ 1Price_Field - 55\ 1',
396 $participant = CRM_Event_BAO_Participant
::add($participantParams);
398 //Checking for participant added in the table.
399 $this->assertDBCompareValue('CRM_Event_BAO_Participant', $this->_contactId
, 'id',
400 'contact_id', $participant->id
, 'Check DB for created participant'
405 $params = ['id' => $participant->id
];
407 CRM_Event_BAO_Participant
::getValues($params, $values, $ids);
408 $this->assertNotEquals(count($values), 0, 'Checking for empty array.');
410 CRM_Event_BAO_Participant
::resolveDefaults($values[$participant->id
]);
412 if ($values[$participant->id
]['fee_level']) {
413 CRM_Event_BAO_Participant
::fixEventLevel($values[$participant->id
]['fee_level']);
416 CRM_Price_BAO_PriceField
::deleteField($pricefield->id
);
417 $this->assertDBNull('CRM_Price_BAO_PriceField', $pricefield->id
, 'name',
418 'id', 'Check DB for non-existence of Price Field.'
421 CRM_Price_BAO_PriceSet
::deleteSet($priceset->id
);
422 $this->assertDBNull('CRM_Price_BAO_PriceSet', $priceset->id
, 'title',
423 'id', 'Check DB for non-existence of Price Set.'
426 $this->participantDelete($participant->id
);
427 $this->contactDelete($this->_contactId
);
428 $this->eventDelete($eventId);