3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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 require_once 'CiviTest/CiviUnitTestCase.php';
30 require_once 'CiviTest/Contact.php';
31 require_once 'CiviTest/Event.php';
32 require_once 'CiviTest/Participant.php';
35 * Class CRM_Event_BAO_ParticipantTest
37 class CRM_Event_BAO_ParticipantTest
extends CiviUnitTestCase
{
39 public function setUp() {
41 $this->_contactId
= Contact
::createIndividual();
42 $this->_eventId
= Event
::create($this->_contactId
);
46 * Add() method (add and edit modes of participant)
48 public function testAdd() {
53 'event_id' => $this->_eventId
,
54 'register_date' => date('Y-m-d') . " 00:00:00",
57 'source' => 'Event_' . $this->_eventId
,
58 'contact_id' => $this->_contactId
,
61 // New Participant Created
62 $participant = CRM_Event_BAO_Participant
::add($params);
64 $this->assertDBNotNull('CRM_Event_BAO_Participant', $this->_contactId
, 'id',
65 'contact_id', 'Check DB for Participant of the contact'
68 $this->assertDBCompareValue('CRM_Event_BAO_Participant', $participant->id
, 'contact_id',
69 'id', $this->_contactId
, 'Check DB for contact of the participant'
72 $params = array_merge($params, array(
73 'id' => $participant->id
,
79 $updatedParticipant = CRM_Event_BAO_Participant
::add($params);
80 $this->assertDBCompareValue('CRM_Event_BAO_Participant', $updatedParticipant->id
, 'role_id',
81 'id', 2, 'Check DB for updated role id of the participant'
84 $this->assertDBCompareValue('CRM_Event_BAO_Participant', $updatedParticipant->id
, 'status_id',
85 'id', 3, 'Check DB for updated status id of the participant'
88 Contact
::delete($this->_contactId
);
89 Event
::delete($this->_eventId
);
93 * GetValues() method (fetch value of participant)
95 public function testgetValuesWithValidParams() {
96 $participantId = Participant
::create($this->_contactId
, $this->_eventId
);
97 $params = array('id' => $participantId);
98 $values = $ids = array();
100 $fetchParticipant = CRM_Event_BAO_Participant
::getValues($params, $values, $ids);
101 $compareValues = $fetchParticipant[$participantId];
107 'event_id' => $this->_eventId
,
108 'register_date' => date('Y-m-d') . " 00:00:00",
111 'source' => 'Event_' . $this->_eventId
,
112 'contact_id' => $this->_contactId
,
113 'id' => $participantId,
114 'campaign_id' => NULL,
116 'fee_amount' => NULL,
117 'registered_by_id' => NULL,
118 'discount_id' => NULL,
119 'fee_currency' => NULL,
120 'discount_amount' => NULL,
125 foreach ($compareValues as $key => $value) {
126 if (substr($key, 0, 1) != '_' && $key != 'N') {
127 $this->assertEquals($compareValues->$key, $params[$key], 'Check for ' . $key . ' for given participant');
131 Participant
::delete($participantId);
132 Contact
::delete($this->_contactId
);
133 Event
::delete($this->_eventId
);
137 * GetValues() method (checking for behavior when params are empty )
139 public function testgetValuesWithoutValidParams() {
140 $params = $values = $ids = array();
141 $participantId = Participant
::create($this->_contactId
, $this->_eventId
);
142 $fetchParticipant = CRM_Event_BAO_Participant
::getValues($params, $values, $ids);
143 $this->assertNull($fetchParticipant);
145 Contact
::delete($this->_contactId
);
146 Event
::delete($this->_eventId
);
150 * EventFull() method (checking the event for full )
152 public function testEventFull() {
153 $eventParams = array(
154 'max_participants' => 1,
155 'id' => $this->_eventId
,
157 CRM_Event_BAO_Event
::add($eventParams);
159 $participantId = Participant
::create($this->_contactId
, $this->_eventId
);
160 $eventFull = CRM_Event_BAO_Participant
::eventFull($this->_eventId
);
162 $this->assertEquals($eventFull, 'This event is full.', 'Checking if Event is full.');
164 Participant
::delete($participantId);
165 Contact
::delete($this->_contactId
);
166 Event
::delete($this->_eventId
);
170 * ImportableFields() method ( Checking the Event's Importable Fields )
172 public function testimportableFields() {
173 $importableFields = CRM_Event_BAO_Participant
::importableFields();
174 $this->assertNotEquals(count($importableFields), 0, 'Checking array not to be empty.');
176 Contact
::delete($this->_contactId
);
177 Event
::delete($this->_eventId
);
181 * ParticipantDetails() method ( Checking the Participant Details )
183 public function testparticipantDetails() {
184 $participantId = Participant
::create($this->_contactId
, $this->_eventId
);
185 $params = array('name' => 'Doe, John', 'title' => 'Test Event');
187 $participantDetails = CRM_Event_BAO_Participant
::participantDetails($participantId);
189 $this->assertEquals(count($participantDetails), 3, 'Equating the array contains.');
190 $this->assertEquals($participantDetails['name'], $params['name'], 'Checking Name of Participant.');
191 $this->assertEquals($participantDetails['title'], $params['title'], 'Checking Event Title in which participant is enroled.');
193 Participant
::delete($participantId);
194 Contact
::delete($this->_contactId
);
195 Event
::delete($this->_eventId
);
199 * DeleteParticipant() method ( Delete a Participant )
201 public function testdeleteParticipant() {
206 'event_id' => $this->_eventId
,
207 'register_date' => date('Y-m-d') . " 00:00:00",
210 'source' => 'Event_' . $this->_eventId
,
211 'contact_id' => $this->_contactId
,
214 // New Participant Created
215 $participant = CRM_Event_BAO_Participant
::add($params);
217 $this->assertDBNotNull('CRM_Event_BAO_Participant', $this->_contactId
, 'id',
218 'contact_id', 'Check DB for Participant of the contact'
221 $this->assertDBCompareValue('CRM_Event_BAO_Participant', $participant->id
, 'contact_id',
222 'id', $this->_contactId
, 'Check DB for contact of the participant'
225 $deleteParticipant = CRM_Event_BAO_Participant
::deleteParticipant($participant->id
);
226 $this->assertDBNull('CRM_Event_BAO_Participant', $participant->id
, 'contact_id', 'id', 'Check DB for deleted Participant.');
228 Contact
::delete($this->_contactId
);
229 Event
::delete($this->_eventId
);
233 * CheckDuplicate() method ( Checking for Duplicate Participant returns array of participant id)
235 public function testcheckDuplicate() {
236 $duplicate = array();
238 //Creating 3 new participants
239 for ($i = 0; $i < 3; $i++
) {
240 $partiId[] = Participant
::create($this->_contactId
, $this->_eventId
);
243 $params = array('event_id' => $this->_eventId
, 'contact_id' => $this->_contactId
);
244 $checkDuplicate = CRM_Event_BAO_Participant
::checkDuplicate($params, $duplicate);
246 $this->assertEquals(count($duplicate), 3, 'Equating the array contains with duplicate array.');
248 //Checking for the duplicate participant
249 foreach ($duplicate as $key => $value) {
250 $this->assertEquals($partiId[$key], $duplicate[$key], 'Equating the contactid which is in the database.');
253 //Deleting all participant
254 for ($i = 0; $i < 3; $i++
) {
255 $partidel[] = Participant
::delete($partiId[$i]);
258 Contact
::delete($this->_contactId
);
259 Event
::delete($this->_eventId
);
263 * Create() method (create and updation of participant)
265 public function testCreate() {
270 'event_id' => $this->_eventId
,
271 'register_date' => date('Y-m-d') . " 00:00:00",
274 'source' => 'Event_' . $this->_eventId
,
275 'contact_id' => $this->_contactId
,
276 'note' => 'Note added for Event_' . $this->_eventId
,
279 $participant = CRM_Event_BAO_Participant
::create($params);
280 //Checking for Contact id in the participant table.
281 $pid = $this->assertDBNotNull('CRM_Event_DAO_Participant', $this->_contactId
, 'id',
282 'contact_id', 'Check DB for Participant of the contact'
285 //Checking for Activity added in the table for relative participant.
286 $this->assertDBCompareValue('CRM_Activity_DAO_Activity', $this->_contactId
, 'source_record_id',
287 'source_contact_id', $participant->id
, 'Check DB for activity added for the participant'
290 $params = array_merge($params, array(
291 'id' => $participant->id
,
294 'note' => 'Test Event in edit mode is running successfully ....',
297 $participant = CRM_Event_BAO_Participant
::create($params);
299 //Checking Edited Value of role_id in the database.
300 $this->assertDBCompareValue('CRM_Event_DAO_Participant', $participant->id
, 'role_id',
301 'id', 2, 'Check DB for updated role id of the participant'
304 //Checking Edited Value of status_id in the database.
305 $this->assertDBCompareValue('CRM_Event_DAO_Participant', $participant->id
, 'status_id',
306 'id', 3, 'Check DB for updated status id of the participant'
309 //Checking for Activity added in the table for relative participant.
310 $this->assertDBCompareValue('CRM_Activity_DAO_Activity', $this->_contactId
, 'source_record_id',
311 'source_contact_id', $participant->id
, 'Check DB for activity added for the participant'
314 //Checking for Note added in the table for relative participant.
315 $session = CRM_Core_Session
::singleton();
316 $id = $session->get('userID');
318 $id = $this->_contactId
;
321 //Deleting the Participant created by create function in this function
322 $deleteParticipant = CRM_Event_BAO_Participant
::deleteParticipant($participant->id
);
323 $this->assertDBNull('CRM_Event_DAO_Participant', $this->_contactId
, 'id',
324 'contact_id', 'Check DB for deleted participant. Should be NULL.'
327 Contact
::delete($this->_contactId
);
328 Event
::delete($this->_eventId
);
332 * ExportableFields() method ( Exportable Fields for Participant)
334 public function testexportableFields() {
335 $exportableFields = CRM_Event_BAO_Participant
::exportableFields();
336 $this->assertNotEquals(count($exportableFields), 0, 'Checking array not to be empty.');
338 Contact
::delete($this->_contactId
);
339 Event
::delete($this->_eventId
);
343 * FixEventLevel() method (Setting ',' values), resolveDefaults(assinging value to array) method
345 public function testfixEventLevel() {
347 $paramsSet['title'] = 'Price Set';
348 $paramsSet['name'] = CRM_Utils_String
::titleToVar('Price Set');
349 $paramsSet['is_active'] = FALSE;
350 $paramsSet['extends'] = 1;
352 $priceset = CRM_Price_BAO_PriceSet
::create($paramsSet);
354 //Checking for priceset added in the table.
355 $this->assertDBCompareValue('CRM_Price_BAO_PriceSet', $priceset->id
, 'title',
356 'id', $paramsSet['title'], 'Check DB for created priceset'
358 $paramsField = array(
359 'label' => 'Price Field',
360 'name' => CRM_Utils_String
::titleToVar('Price Field'),
361 'html_type' => 'Text',
363 'option_label' => array('1' => 'Price Field'),
364 'option_value' => array('1' => 10),
365 'option_name' => array('1' => 10),
366 'option_weight' => array('1' => 1),
367 'is_display_amounts' => 1,
369 'options_per_line' => 1,
370 'is_active' => array('1' => 1),
371 'price_set_id' => $priceset->id
,
376 $pricefield = CRM_Price_BAO_PriceField
::create($paramsField, $ids);
378 //Checking for priceset added in the table.
379 $this->assertDBCompareValue('CRM_Price_BAO_PriceField', $pricefield->id
, 'label',
380 'id', $paramsField['label'], 'Check DB for created pricefield'
383 $eventId = $this->_eventId
;
384 $participantParams = array(
388 'event_id' => $eventId,
389 'register_date' => date('Y-m-d') . " 00:00:00",
392 'source' => 'Event_' . $eventId,
393 'contact_id' => $this->_contactId
,
394 'note' => 'Note added for Event_' . $eventId,
395 'fee_level' => '\ 1Price_Field - 55\ 1',
398 $participant = CRM_Event_BAO_Participant
::add($participantParams);
400 //Checking for participant added in the table.
401 $this->assertDBCompareValue('CRM_Event_BAO_Participant', $this->_contactId
, 'id',
402 'contact_id', $participant->id
, 'Check DB for created participant'
407 $params = array('id' => $participant->id
);
409 CRM_Event_BAO_Participant
::getValues($params, $values, $ids);
410 $this->assertNotEquals(count($values), 0, 'Checking for empty array.');
412 CRM_Event_BAO_Participant
::resolveDefaults($values[$participant->id
]);
414 if ($values[$participant->id
]['fee_level']) {
415 CRM_Event_BAO_Participant
::fixEventLevel($values[$participant->id
]['fee_level']);
418 $deletePricefield = CRM_Price_BAO_PriceField
::deleteField($pricefield->id
);
419 $this->assertDBNull('CRM_Price_BAO_PriceField', $pricefield->id
, 'name',
420 'id', 'Check DB for non-existence of Price Field.'
423 $deletePriceset = CRM_Price_BAO_PriceSet
::deleteSet($priceset->id
);
424 $this->assertDBNull('CRM_Price_BAO_PriceSet', $priceset->id
, 'title',
425 'id', 'Check DB for non-existence of Price Set.'
428 Participant
::delete($participant->id
);
429 Contact
::delete($this->_contactId
);
430 Event
::delete($eventId);