Merge pull request #2916 from NileemaJadhav/HR-13-fix
[civicrm-core.git] / tests / phpunit / WebTest / Event / ParticipantCountTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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 along with this program; if not, contact CiviCRM LLC |
21 | at info[AT]civicrm[DOT]org. If you have questions about the |
22 | GNU Affero General Public License or the licensing of CiviCRM, |
23 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
24 +--------------------------------------------------------------------+
25 */
26
27 require_once 'CiviTest/CiviSeleniumTestCase.php';
28 class WebTest_Event_ParticipantCountTest extends CiviSeleniumTestCase {
29
30 protected function setUp() {
31 parent::setUp();
32 }
33
34 function testParticipantCountWithFeelevel() {
35 // Log in using webtestLogin() method
36 $this->webtestLogin();
37
38 // We need a payment processor
39 $processorName = 'Webtest Dummy' . substr(sha1(rand()), 0, 7);
40 $this->webtestAddPaymentProcessor($processorName);
41
42 // create an event
43 $eventTitle = 'A Conference - ' . substr(sha1(rand()), 0, 7);
44 $paramsEvent = array(
45 'title' => $eventTitle,
46 'template_id' => 6,
47 'event_type_id' => 4,
48 'payment_processor' => $processorName,
49 'fee_level' => array(
50 'Member' => '250.00',
51 'Non-Member' => '325.00',
52 ),
53 );
54
55 $infoEvent = $this->_testAddEvent($paramsEvent);
56
57 // logout to register for event.
58 $this->webtestLogout();
59
60 // Register Participant 1
61 // visit event info page
62 $this->open($infoEvent);
63 $this->waitForPageToLoad($this->getTimeoutMsec());
64
65 // register for event
66 $this->click('link=Register Now');
67 $this->waitForElementPresent('_qf_Register_upload-bottom');
68 $this->click("xpath=//input[@class='crm-form-radio']");
69
70 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
71 $this->type('first_name', 'Mary');
72 $this->type('last_name', 'Jones'. substr(sha1(rand()), 0, 5));
73 $this->type('email-Primary', $email);
74
75 // fill billing details and register
76 $this->_testRegisterWithBillingInfo();
77
78 // Register Participant 2
79 // visit event info page
80 $this->open($infoEvent);
81
82 // register for event
83 $this->click('link=Register Now');
84 $this->waitForElementPresent('_qf_Register_upload-bottom');
85
86 $this->click("xpath=//input[@class='crm-form-radio']");
87 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
88 $this->type('first_name', 'Mary');
89 $this->type('last_name', 'Jones'. substr(sha1(rand()), 0, 5));
90 $this->type('email-Primary', $email);
91
92 // fill billing details and register
93 $this->_testRegisterWithBillingInfo();
94
95 // login to check participant count
96 $this->webtestLogin();
97
98 // Find Participant
99 $this->openCiviPage("event/search", "reset=1", 'participant_fee_amount_low');
100 $this->select2("event_id", $eventTitle);
101 $this->click('_qf_Search_refresh');
102 $this->waitForPageToLoad($this->getTimeoutMsec());
103
104 // verify number of registered participants
105 $this->assertStringsPresent(array('2 Result'));
106 }
107
108 function testParticipantCountWithPriceset() {
109 // Log in using webtestLogin() method
110 $this->webtestLogin();
111
112 // We need a payment processor
113 $processorName = 'Webtest Dummy' . substr(sha1(rand()), 0, 7);
114 $this->webtestAddPaymentProcessor($processorName);
115
116 // create priceset
117 $priceset = 'Price - ' . substr(sha1(rand()), 0, 7);
118 $this->_testAddSet($priceset);
119
120 // create price fields
121 $fields = array(
122 'Full Conference' => array(
123 'type' => 'Text',
124 'amount' => '525.00',
125 'count' => '2',
126 ),
127 'Meal Choice' => array(
128 'type' => 'Select',
129 'options' => array(
130 1 => array(
131 'label' => 'Chicken',
132 'amount' => '525.00',
133 'count' => '2',
134 ),
135 2 => array(
136 'label' => 'Vegetarian',
137 'amount' => '200.00',
138 'count' => '2',
139 ),
140 ),
141 ),
142 'Pre-conference Meetup?' => array(
143 'type' => 'Radio',
144 'options' => array(
145 1 => array(
146 'label' => 'Yes',
147 'amount' => '50.00',
148 'count' => '2',
149 ),
150 2 => array(
151 'label' => 'No',
152 'amount' => '0',
153 ),
154 ),
155 ),
156 'Evening Sessions' => array(
157 'type' => 'CheckBox',
158 'options' => array(
159 1 => array(
160 'label' => 'First Five',
161 'amount' => '100.00',
162 'count' => '5',
163 ),
164 2 => array(
165 'label' => 'Second Four',
166 'amount' => '50.00',
167 'count' => '4',
168 ),
169 ),
170 ),
171 );
172
173 foreach ($fields as $label => $field) {
174 $this->type('label', $label);
175 $this->select('html_type', "value={$field['type']}");
176
177 if ($field['type'] == 'Text') {
178 $this->type('price', $field['amount']);
179 //yash
180 $this->waitForElementPresent('count');
181 $this->type('count', $field['count']);
182 $this->check('is_required');
183 }
184 else {
185 $this->_testAddMultipleChoiceOptions($field['options']);
186 }
187 $this->clickLink('_qf_Field_next_new-bottom', '_qf_Field_next-bottom');
188 }
189
190 // create event.
191 $eventTitle = 'Meeting - ' . substr(sha1(rand()), 0, 7);
192 $paramsEvent = array(
193 'title' => $eventTitle,
194 'template_id' => 6,
195 'event_type_id' => 4,
196 'payment_processor' => $processorName,
197 'price_set' => $priceset,
198 );
199
200 $infoEvent = $this->_testAddEvent($paramsEvent);
201
202 // logout to register for event.
203 $this->webtestLogout();
204
205 $priceFieldOptionCounts = $participants = array();
206
207 // Register Participant 1
208 // visit event info page
209 $this->open($infoEvent);
210 $this->waitForPageToLoad($this->getTimeoutMsec());
211
212 // register for event
213 $this->click('link=Register Now');
214 $this->waitForElementPresent('_qf_Register_upload-bottom');
215
216 $this->type("xpath=//input[@class='four crm-form-text required']", '1');
217
218 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
219 $participants[1] = array(
220 'email' => $email,
221 'first_name' => 'Jane_' . substr(sha1(rand()), 0, 5),
222 'last_name' => 'San_' . substr(sha1(rand()), 0, 5),
223 );
224
225 $this->type('first_name', $participants[1]['first_name']);
226 $this->type('last_name', $participants[1]['last_name']);
227 $this->type('email-Primary', $email);
228
229 // fill billing related info and register
230 $this->_testRegisterWithBillingInfo($participants[1]);
231
232 // Options filled by 1st participants.
233 $priceFieldOptionCounts[1] = array(
234 'Full Conference' => 1,
235 'Meal Choice - Chicken' => 1,
236 'Meal Choice - Vegetarian' => 0,
237 'Pre-conference Meetup? - Yes' => 1,
238 'Pre-conference Meetup? - No' => 0,
239 'Evening Sessions - First Five' => 1,
240 'Evening Sessions - Second Four' => 0,
241 );
242
243 // Register Participant 1
244 // visit event info page
245 $this->open($infoEvent);
246
247 // register for event
248 $this->click('link=Register Now');
249 $this->waitForElementPresent('_qf_Register_upload-bottom');
250
251 $this->type("xpath=//input[@class='four crm-form-text required']", '2');
252 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
253
254 $participants[2] = array(
255 'email' => $email,
256 'first_name' => 'Jane_' . substr(sha1(rand()), 0, 5),
257 'last_name' => 'San_' . substr(sha1(rand()), 0, 5),
258 );
259
260 $this->type('first_name', $participants[2]['first_name']);
261 $this->type('last_name', $participants[2]['last_name']);
262 $this->type('email-Primary', $email);
263
264 // fill billing related info and register
265 $this->_testRegisterWithBillingInfo($participants[2]);
266
267 // Options filled by 2nd participants.
268 $priceFieldOptionCounts[2] = array(
269 'Full Conference' => 2,
270 'Meal Choice - Chicken' => 1,
271 'Meal Choice - Vegetarian' => 0,
272 'Pre-conference Meetup? - Yes' => 1,
273 'Pre-conference Meetup? - No' => 0,
274 'Evening Sessions - First Five' => 1,
275 'Evening Sessions - Second Four' => 0,
276 );
277
278 // login to check participant count
279 $this->webtestLogin();
280
281 // Find Participant
282 $this->openCiviPage('event/search', 'reset=1', 'participant_fee_amount_low');
283 $this->select2("event_id", $eventTitle);
284 $this->click('_qf_Search_refresh');
285 $this->waitForPageToLoad($this->getTimeoutMsec());
286
287 // verify number of participants records and total participant count
288 $this->assertStringsPresent(array('2 Result', 'Actual participant count : 24'));
289
290 // CRM-7953, check custom search Price Set Details for Event
291 // Participants
292 $this->_testPricesetDetailsCustomSearch($paramsEvent, $participants, $priceFieldOptionCounts);
293 }
294
295 function _testAddSet($setTitle, $financialType = 'Event Fee') {
296 $this->openCiviPage('admin/price', 'reset=1&action=add', '_qf_Set_next-bottom');
297
298 // Enter Priceset fields (Title, Used For ...)
299 $this->type('title', $setTitle);
300 $this->check('extends[1]');
301 $this->select("css=select.crm-form-select", "label={$financialType}");
302 $this->type('help_pre', 'This is test priceset.');
303
304 $this->assertChecked('is_active', 'Verify that Is Active checkbox is set.');
305 $this->clickLink('_qf_Set_next-bottom', '_qf_Field_next-bottom');
306 }
307
308 function _testAddMultipleChoiceOptions($options) {
309 foreach ($options as $oIndex => $oValue) {
310 $this->type("option_label_{$oIndex}", $oValue['label']);
311 $this->type("option_amount_{$oIndex}", $oValue['amount']);
312 if (array_key_exists('count', $oValue)) {
313 $this->waitForElementPresent("option_count_{$oIndex}");
314 $this->type("option_count_{$oIndex}", $oValue['count']);
315 }
316 $this->click('link=another choice');
317 }
318 $this->click('CIVICRM_QFID_1_2');
319 }
320
321 function _testAddEvent($params) {
322 $this->openCiviPage('event/add', 'reset=1&action=add', '_qf_EventInfo_upload-bottom');
323
324 $this->select('event_type_id', "value={$params['event_type_id']}");
325
326 // Attendee role s/b selected now.
327 $this->select('default_role_id', 'value=1');
328
329 // Enter Event Title, Summary and Description
330 $this->type('title', $params['title']);
331 $this->type('summary', 'This is a great conference. Sign up now!');
332 $this->fillRichTextField('description', 'Here is a description for this event.', 'CKEditor');
333
334 // Choose Start and End dates.
335 // Using helper webtestFillDate function.
336 $this->webtestFillDateTime('start_date', '+1 week');
337 $this->webtestFillDateTime('end_date', '+1 week 1 day 8 hours ');
338
339 $this->type('max_participants', '50');
340 $this->click('is_map');
341 $this->click('_qf_EventInfo_upload-bottom');
342
343 // Wait for Location tab form to load
344 $this->waitForPageToLoad($this->getTimeoutMsec());
345
346 // Go to Fees tab
347 $this->click('link=Fees');
348 $this->waitForElementPresent('_qf_Fee_upload-bottom');
349 $this->click('CIVICRM_QFID_1_is_monetary');
350 $this->click("xpath=//tr[@class='crm-event-manage-fee-form-block-payment_processor']/td[2]/label[text()='" . $params['payment_processor'] . "']");
351 $this->select('financial_type_id', 'Event Fee');
352 if (array_key_exists('price_set', $params)) {
353 $this->select('price_set_id', 'label=' . $params['price_set']);
354 }
355 if (array_key_exists('fee_level', $params)) {
356 $counter = 1;
357 foreach ($params['fee_level'] as $label => $amount) {
358 $this->type("label_{$counter}", $label);
359 $this->type("value_{$counter}", $amount);
360 $counter++;
361 }
362 }
363
364 $this->click('_qf_Fee_upload-bottom');
365 $this->waitForElementPresent('_qf_Fee_cancel-top');
366
367 // Go to Online Registration tab
368 $this->click('link=Online Registration');
369 $this->waitForElementPresent('_qf_Registration_upload-bottom');
370
371 $this->check('is_online_registration');
372 $this->assertChecked('is_online_registration');
373
374 $this->fillRichTextField('intro_text', 'Fill in all the fields below and click Continue.');
375
376 // enable confirmation email
377 $this->click('CIVICRM_QFID_1_is_email_confirm');
378 $this->type('confirm_from_name', 'Jane Doe');
379 $this->type('confirm_from_email', 'jane.doe@example.org');
380
381 $this->click('_qf_Registration_upload-bottom');
382 $this->waitForElementPresent('_qf_Registration_upload-bottom');
383 $this->waitForTextPresent("'Online Registration' information has been saved.");
384
385 // verify event input on info page
386 // start at Manage Events listing
387 $this->openCiviPage('event/manage', 'reset=1');
388 $this->click('link=' . $params['title']);
389
390 $this->waitForPageToLoad($this->getTimeoutMsec());
391 return $this->getLocation();
392 }
393
394 function _testRegisterWithBillingInfo($participant = array()) {
395 $this->waitForElementPresent("credit_card_type");
396 $this->select('credit_card_type', 'value=Visa');
397 $this->type('credit_card_number', '4111111111111111');
398 $this->type('cvv2', '000');
399 $this->select('credit_card_exp_date[M]', 'value=1');
400 $this->select('credit_card_exp_date[Y]', 'value=2020');
401 $this->type('billing_first_name', isset($participant['first_name']) ? $participant['first_name'] : 'Jane_' . substr(sha1(rand()), 0, 5));
402 $this->type('billing_last_name', isset($participant['last_name']) ? $participant['last_name'] : 'San_' . substr(sha1(rand()), 0, 5));
403 $this->type('billing_street_address-5', '15 Main St.');
404 $this->type(' billing_city-5', 'San Jose');
405 $this->select('billing_country_id-5', 'value=1228');
406 $this->select('billing_state_province_id-5', 'value=1004');
407 $this->type('billing_postal_code-5', '94129');
408
409 $this->clickLink('_qf_Register_upload-bottom', '_qf_Confirm_next-bottom');
410 $confirmStrings = array('Event Fee(s)', 'Billing Name and Address', 'Credit Card Information');
411 $this->assertStringsPresent($confirmStrings);
412 $this->click('_qf_Confirm_next-bottom');
413 $this->waitForPageToLoad($this->getTimeoutMsec());
414 $thankStrings = array('Thank You for Registering', 'Event Total', 'Transaction Date');
415 $this->assertStringsPresent($thankStrings);
416 }
417
418 function _testPricesetDetailsCustomSearch($eventParams, $participants, $priceFieldOptionCounts) {
419 $this->openCiviPage('contact/search/custom', 'csid=9&reset=1');
420
421 $this->select('event_id', 'label=' . $eventParams['title']);
422 $this->click('_qf_Custom_refresh-bottom');
423 $this->waitForPageToLoad($this->getTimeoutMsec());
424
425 $tableHeaders = array('Contact Id', 'Participant Id', 'Name');
426 $tableHeaders = array_merge($tableHeaders, array_keys(current($priceFieldOptionCounts)));
427
428 $tdnum = 2;
429 foreach ($tableHeaders as $header) {
430 $this->verifyText("xpath=//form[@id='Custom']//div[@class='crm-search-results']//table[@class='selector row-highlight']/thead/tr[1]/th[$tdnum]", $header);
431 $tdnum++;
432 }
433
434 foreach ($participants as $participantNum => $participant) {
435 $tdnum = 4;
436 $this->verifyText("xpath=//form[@id='Custom']//div[@class='crm-search-results']//table[@class='selector row-highlight']/tbody/tr[{$participantNum}]/td[{$tdnum}]", preg_quote("{$participant['first_name']} {$participant['last_name']}"));
437 foreach ($priceFieldOptionCounts[$participantNum] as $priceFieldOptionCount) {
438 $tdnum++;
439 $this->verifyText("xpath=//form[@id='Custom']//div[@class='crm-search-results']//table[@class='selector row-highlight']/tbody/tr[{$participantNum}]/td[{$tdnum}]", preg_quote($priceFieldOptionCount));
440 }
441 }
442 }
443 }
444