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