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