3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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 +--------------------------------------------------------------------+
30 require_once 'CiviTest/CiviUnitTestCase.php';
31 require_once 'CiviTest/Contact.php';
32 require_once 'CiviTest/Event.php';
33 require_once 'CiviTest/Participant.php';
34 class CRM_Event_BAO_ParticipantTest
extends CiviUnitTestCase
{
35 //@todo make BAO enotice compliant & remove the line below
36 // WARNING - NEVER COPY & PASTE $_eNoticeCompliant = FALSE
37 // new test classes should be compliant.
38 public $_eNoticeCompliant = FALSE;
41 'name' => 'Participant BAOs',
42 'description' => 'Test all Event_BAO_Participant methods.',
43 'group' => 'CiviCRM BAO Tests',
49 $this->_contactId
= Contact
::createIndividual();
50 $this->_eventId
= Event
::create($this->_contactId
);
54 * add() method (add and edit modes of participant)
61 'event_id' => $this->_eventId
,
62 'register_date' => date('Y-m-d') . " 00:00:00",
65 'source' => 'Event_' . $this->_eventId
,
66 'contact_id' => $this->_contactId
,
69 // New Participant Created
70 $participant = CRM_Event_BAO_Participant
::add($params);
72 $this->assertDBNotNull('CRM_Event_BAO_Participant', $this->_contactId
, 'id',
73 'contact_id', 'Check DB for Participant of the contact'
76 $this->assertDBCompareValue('CRM_Event_BAO_Participant', $participant->id
, 'contact_id',
77 'id', $this->_contactId
, 'Check DB for contact of the participant'
80 $params = array_merge($params, array(
81 'id' => $participant->id
,
87 $updatedParticipant = CRM_Event_BAO_Participant
::add($params);
88 $this->assertDBCompareValue('CRM_Event_BAO_Participant', $updatedParticipant->id
, 'role_id',
89 'id', 2, 'Check DB for updated role id of the participant'
92 $this->assertDBCompareValue('CRM_Event_BAO_Participant', $updatedParticipant->id
, 'status_id',
93 'id', 3, 'Check DB for updated status id of the participant'
96 Contact
::delete($this->_contactId
);
97 Event
::delete($this->_eventId
);
101 * getValues() method (fetch value of participant)
103 function testgetValuesWithValidParams() {
104 $participantId = Participant
::create($this->_contactId
, $this->_eventId
);
105 $params = array('id' => $participantId);
107 $fetchParticipant = CRM_Event_BAO_Participant
::getValues($params, $values, $ids);
108 $compareValues = $fetchParticipant[$participantId];
114 'event_id' => $this->_eventId
,
115 'register_date' => date('Y-m-d') . " 00:00:00",
118 'source' => 'Event_' . $this->_eventId
,
119 'contact_id' => $this->_contactId
,
120 'id' => $participantId,
122 'fee_amount' => NULL,
123 'registered_by_id' => NULL,
124 'discount_id' => NULL,
125 'fee_currency' => NULL,
128 foreach ($compareValues as $key => $value) {
129 if (substr($key, 0, 1) != '_' && $key != 'N') {
130 $this->assertEquals($compareValues->$key, $params[$key], 'Check for ' . $key . ' for given participant');
134 Participant
::delete($participantId);
135 Contact
::delete($this->_contactId
);
136 Event
::delete($this->_eventId
);
140 * getValues() method (checking for behavior when params are empty )
142 function testgetValuesWithoutValidParams() {
143 $params = $values = $ids = array();
144 $participantId = Participant
::create($this->_contactId
, $this->_eventId
);
145 $fetchParticipant = CRM_Event_BAO_Participant
::getValues($params, $values, $ids);
146 $this->assertNull($fetchParticipant, 'In line ' . __LINE__
);
148 Contact
::delete($this->_contactId
);
149 Event
::delete($this->_eventId
);
153 * eventFull() method (checking the event for full )
155 function testEventFull() {
156 $eventParams = array(
157 'max_participants' => 1,
158 'id' => $this->_eventId
,
160 CRM_Event_BAO_Event
::add($eventParams);
162 $participantId = Participant
::create($this->_contactId
, $this->_eventId
);
163 $eventFull = CRM_Event_BAO_Participant
::eventFull($this->_eventId
);
165 $this->assertEquals($eventFull, 'This event is full !!!', 'Checking if Event is full.');
167 Participant
::delete($participantId);
168 Contact
::delete($this->_contactId
);
169 Event
::delete($this->_eventId
);
173 * importableFields() method ( Checking the Event's Importable Fields )
175 function testimportableFields() {
176 $importableFields = CRM_Event_BAO_Participant
::importableFields();
177 $this->assertNotEquals(count($importableFields), 0, 'Checking array not to be empty.');
179 Contact
::delete($this->_contactId
);
180 Event
::delete($this->_eventId
);
184 * participantDetails() method ( Checking the Participant Details )
186 function testparticipantDetails() {
187 $participantId = Participant
::create($this->_contactId
, $this->_eventId
);
188 $params = array('name' => 'Doe, John', 'title' => 'Test Event');
190 $participantDetails = CRM_Event_BAO_Participant
::participantDetails($participantId);
192 $this->assertEquals(count($participantDetails), 3, 'Equating the array contains.');
193 $this->assertEquals($participantDetails['name'], $params['name'], 'Checking Name of Participant.');
194 $this->assertEquals($participantDetails['title'], $params['title'], 'Checking Event Title in which participant is enroled.');
196 Participant
::delete($participantId);
197 Contact
::delete($this->_contactId
);
198 Event
::delete($this->_eventId
);
202 * deleteParticipant() method ( Delete a Participant )
204 function testdeleteParticipant() {
209 'event_id' => $this->_eventId
,
210 'register_date' => date('Y-m-d') . " 00:00:00",
213 'source' => 'Event_' . $this->_eventId
,
214 'contact_id' => $this->_contactId
,
217 // New Participant Created
218 $participant = CRM_Event_BAO_Participant
::add($params);
220 $this->assertDBNotNull('CRM_Event_BAO_Participant', $this->_contactId
, 'id',
221 'contact_id', 'Check DB for Participant of the contact'
224 $this->assertDBCompareValue('CRM_Event_BAO_Participant', $participant->id
, 'contact_id',
225 'id', $this->_contactId
, 'Check DB for contact of the participant'
228 $deleteParticipant = CRM_Event_BAO_Participant
::deleteParticipant($participant->id
);
229 $this->assertDBNull('CRM_Event_BAO_Participant', $participant->id
, 'contact_id', 'id', 'Check DB for deleted Participant.');
231 Contact
::delete($this->_contactId
);
232 Event
::delete($this->_eventId
);
236 * checkDuplicate() method ( Checking for Duplicate Participant returns array of participant id)
238 function testcheckDuplicate() {
239 $duplicate = array();
241 //Creating 3 new participants
242 for ($i = 0; $i < 3; $i++
) {
243 $partiId[] = Participant
::create($this->_contactId
, $this->_eventId
);
246 $params = array('event_id' => $this->_eventId
, 'contact_id' => $this->_contactId
);
247 $checkDuplicate = CRM_Event_BAO_Participant
::checkDuplicate($params, $duplicate);
249 $this->assertEquals(count($duplicate), 3, 'Equating the array contains with duplicate array.');
251 //Checking for the duplicate participant
252 foreach ($duplicate as $key => $value) {
253 $this->assertEquals($partiId[$key], $duplicate[$key], 'Equating the contactid which is in the database.');
256 //Deleting all participant
257 for ($i = 0; $i < 3; $i++
) {
258 $partidel[] = Participant
::delete($partiId[$i]);
261 Contact
::delete($this->_contactId
);
262 Event
::delete($this->_eventId
);
266 * create() method (create and updation of participant)
268 function testCreate() {
273 'event_id' => $this->_eventId
,
274 'register_date' => date('Y-m-d') . " 00:00:00",
277 'source' => 'Event_' . $this->_eventId
,
278 'contact_id' => $this->_contactId
,
279 'note' => 'Note added for Event_' . $this->_eventId
,
282 $participant = CRM_Event_BAO_Participant
::create($params);
283 //Checking for Contact id in the participant table.
284 $pid = $this->assertDBNotNull('CRM_Event_DAO_Participant', $this->_contactId
, 'id',
285 'contact_id', 'Check DB for Participant of the contact'
288 //Checking for Activity added in the table for relative participant.
289 $this->assertDBCompareValue('CRM_Activity_DAO_Activity', $this->_contactId
, 'source_record_id',
290 'source_contact_id', $participant->id
, 'Check DB for activity added for the participant'
293 $params = array_merge($params, array(
294 'id' => $participant->id
,
297 'note' => 'Test Event in edit mode is running successfully ....',
300 $participant = CRM_Event_BAO_Participant
::create($params);
302 //Checking Edited Value of role_id in the database.
303 $this->assertDBCompareValue('CRM_Event_DAO_Participant', $participant->id
, 'role_id',
304 'id', 2, 'Check DB for updated role id of the participant'
307 //Checking Edited Value of status_id in the database.
308 $this->assertDBCompareValue('CRM_Event_DAO_Participant', $participant->id
, 'status_id',
309 'id', 3, 'Check DB for updated status id of the participant'
312 //Checking for Activity added in the table for relative participant.
313 $this->assertDBCompareValue('CRM_Activity_DAO_Activity', $this->_contactId
, 'source_record_id',
314 'source_contact_id', $participant->id
, 'Check DB for activity added for the participant'
317 //Checking for Note added in the table for relative participant.
318 $session = CRM_Core_Session
::singleton();
319 $id = $session->get('userID');
321 $id = $this->_contactId
;
324 //Deleting the Participant created by create function in this function
325 $deleteParticipant = CRM_Event_BAO_Participant
::deleteParticipant($participant->id
);
326 $this->assertDBNull('CRM_Event_DAO_Participant', $this->_contactId
, 'id',
327 'contact_id', 'Check DB for deleted participant. Should be NULL.'
330 Contact
::delete($this->_contactId
);
331 Event
::delete($this->_eventId
);
335 * exportableFields() method ( Exportable Fields for Participant)
337 function testexportableFields() {
338 $exportableFields = CRM_Event_BAO_Participant
::exportableFields();
339 $this->assertNotEquals(count($exportableFields), 0, 'Checking array not to be empty.');
341 Contact
::delete($this->_contactId
);
342 Event
::delete($this->_eventId
);
346 * fixEventLevel() method (Setting ',' values), resolveDefaults(assinging value to array) method
348 function testfixEventLevel() {
350 $paramsSet['title'] = 'Price Set';
351 $paramsSet['name'] = CRM_Utils_String
::titleToVar('Price Set');
352 $paramsSet['is_active'] = CRM_Utils_Array
::value('is_active', $params, FALSE);
353 $paramsSet['extends'] = 1;
355 $priceset = CRM_Price_BAO_PriceSet
::create($paramsSet);
357 //Checking for priceset added in the table.
358 $this->assertDBCompareValue('CRM_Price_BAO_PriceSet', $priceset->id
, 'title',
359 'id', $paramsSet['title'], 'Check DB for created priceset'
361 $paramsField = array(
362 'label' => 'Price Field',
363 'name' => CRM_Utils_String
::titleToVar('Price Field'),
364 'html_type' => 'Text',
366 'option_label' => array('1' => 'Price Field'),
367 'option_value' => array('1' => 10),
368 'option_name' => array('1' => 10),
369 'option_weight' => array('1' => 1),
370 'is_display_amounts' => 1,
372 'options_per_line' => 1,
373 'is_active' => array('1' => 1),
374 'price_set_id' => $priceset->id
,
379 $pricefield = CRM_Price_BAO_PriceField
::create($paramsField, $ids);
381 //Checking for priceset added in the table.
382 $this->assertDBCompareValue('CRM_Price_BAO_PriceField', $pricefield->id
, 'label',
383 'id', $paramsField['label'], 'Check DB for created pricefield'
386 $eventId = $this->_eventId
;
387 $participantParams = array(
391 'event_id' => $eventId,
392 'register_date' => date('Y-m-d') . " 00:00:00",
395 'source' => 'Event_' . $eventId,
396 'contact_id' => $this->_contactId
,
397 'note' => 'Note added for Event_' . $eventId,
398 'fee_level' => '\ 1Price_Field - 55\ 1',
401 $participant = CRM_Event_BAO_Participant
::add($participantParams);
403 //Checking for participant added in the table.
404 $this->assertDBCompareValue('CRM_Event_BAO_Participant', $this->_contactId
, 'id',
405 'contact_id', $participant->id
, 'Check DB for created participant'
410 $params = array('id' => $participant->id
);
412 CRM_Event_BAO_Participant
::getValues($params, $values, $ids);
413 $this->assertNotEquals(count($values), 0, 'Checking for empty array.');
415 CRM_Event_BAO_Participant
::resolveDefaults($values[$participant->id
]);
417 if ($values[$participant->id
]['fee_level']) {
418 CRM_Event_BAO_Participant
::fixEventLevel($values[$participant->id
]['fee_level']);
421 $deletePricefield = CRM_Price_BAO_PriceField
::deleteField($pricefield->id
);
422 $this->assertDBNull('CRM_Price_BAO_PriceField', $pricefield->id
, 'name',
423 'id', 'Check DB for non-existence of Price Field.'
426 $deletePriceset = CRM_Price_BAO_PriceSet
::deleteSet($priceset->id
);
427 $this->assertDBNull('CRM_Price_BAO_PriceSet', $priceset->id
, 'title',
428 'id', 'Check DB for non-existence of Price Set.'
431 Participant
::delete($participant->id
);
432 Contact
::delete($this->_contactId
);
433 Event
::delete($eventId);