add a few remaining missing comment blocks (autogenerated)
[civicrm-core.git] / tests / phpunit / WebTest / Event / ParticipantCountTest.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
06a1bc01 4 | CiviCRM version 4.5 |
6a488035 5 +--------------------------------------------------------------------+
06a1bc01 6 | Copyright CiviCRM LLC (c) 2004-2014 |
6a488035
TO
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');
ed174dea 68 $this->click("xpath=//input[@class='crm-form-radio']");
6a488035
TO
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
ed174dea 86 $this->click("xpath=//input[@class='crm-form-radio']");
6a488035 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');
ed174dea 100 $this->select2("event_id", $eventTitle);
6a488035
TO
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() {
6a488035
TO
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(
d17310e4 122 'Full Conference' => array(
123 'type' => 'Text',
6a488035
TO
124 'amount' => '525.00',
125 'count' => '2',
126 ),
127 'Meal Choice' => array(
128 'type' => 'Select',
129 'options' => array(
d17310e4 130 1 => array(
131 'label' => 'Chicken',
6a488035
TO
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(
d17310e4 145 1 => array(
146 'label' => 'Yes',
6a488035
TO
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(
d17310e4 159 1 => array(
160 'label' => 'First Five',
6a488035
TO
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) {
6a488035
TO
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 }
225a8648 187 $this->clickLink('_qf_Field_next_new-bottom', '_qf_Field_next-bottom');
6a488035
TO
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.
42daf119 203 $this->webtestLogout();
6a488035
TO
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
ed174dea 216 $this->type("xpath=//input[@class='four crm-form-text required']", '1');
6a488035
TO
217
218 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
6a488035
TO
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
1eb0391e 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
6a488035
TO
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
ed174dea 251 $this->type("xpath=//input[@class='four crm-form-text required']", '2');
6a488035 252 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
6a488035
TO
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
1eb0391e 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
6a488035
TO
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
6a488035
TO
279 $this->webtestLogin();
280
281 // Find Participant
42daf119 282 $this->openCiviPage('event/search', 'reset=1', 'participant_fee_amount_low');
ed174dea 283 $this->select2("event_id", $eventTitle);
6a488035
TO
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
4cbe18b8
EM
295 /**
296 * @param $setTitle
297 * @param string $financialType
298 */
6a488035 299 function _testAddSet($setTitle, $financialType = 'Event Fee') {
42daf119 300 $this->openCiviPage('admin/price', 'reset=1&action=add', '_qf_Set_next-bottom');
6a488035
TO
301
302 // Enter Priceset fields (Title, Used For ...)
303 $this->type('title', $setTitle);
304 $this->check('extends[1]');
ed174dea 305 $this->select("css=select.crm-form-select", "label={$financialType}");
6a488035
TO
306 $this->type('help_pre', 'This is test priceset.');
307
308 $this->assertChecked('is_active', 'Verify that Is Active checkbox is set.');
225a8648 309 $this->clickLink('_qf_Set_next-bottom', '_qf_Field_next-bottom');
6a488035
TO
310 }
311
4cbe18b8
EM
312 /**
313 * @param $options
314 */
6a488035
TO
315 function _testAddMultipleChoiceOptions($options) {
316 foreach ($options as $oIndex => $oValue) {
317 $this->type("option_label_{$oIndex}", $oValue['label']);
318 $this->type("option_amount_{$oIndex}", $oValue['amount']);
319 if (array_key_exists('count', $oValue)) {
320 $this->waitForElementPresent("option_count_{$oIndex}");
321 $this->type("option_count_{$oIndex}", $oValue['count']);
322 }
323 $this->click('link=another choice');
324 }
325 $this->click('CIVICRM_QFID_1_2');
326 }
327
4cbe18b8
EM
328 /**
329 * @param $params
330 *
331 * @return string
332 */
6a488035 333 function _testAddEvent($params) {
42daf119 334 $this->openCiviPage('event/add', 'reset=1&action=add', '_qf_EventInfo_upload-bottom');
6a488035 335
6a488035
TO
336 $this->select('event_type_id', "value={$params['event_type_id']}");
337
338 // Attendee role s/b selected now.
339 $this->select('default_role_id', 'value=1');
340
341 // Enter Event Title, Summary and Description
342 $this->type('title', $params['title']);
343 $this->type('summary', 'This is a great conference. Sign up now!');
344 $this->fillRichTextField('description', 'Here is a description for this event.', 'CKEditor');
345
346 // Choose Start and End dates.
347 // Using helper webtestFillDate function.
348 $this->webtestFillDateTime('start_date', '+1 week');
349 $this->webtestFillDateTime('end_date', '+1 week 1 day 8 hours ');
350
351 $this->type('max_participants', '50');
352 $this->click('is_map');
353 $this->click('_qf_EventInfo_upload-bottom');
354
355 // Wait for Location tab form to load
356 $this->waitForPageToLoad($this->getTimeoutMsec());
357
358 // Go to Fees tab
359 $this->click('link=Fees');
360 $this->waitForElementPresent('_qf_Fee_upload-bottom');
361 $this->click('CIVICRM_QFID_1_is_monetary');
362 $this->click("xpath=//tr[@class='crm-event-manage-fee-form-block-payment_processor']/td[2]/label[text()='" . $params['payment_processor'] . "']");
d17310e4 363 $this->select('financial_type_id', 'Event Fee');
6a488035
TO
364 if (array_key_exists('price_set', $params)) {
365 $this->select('price_set_id', 'label=' . $params['price_set']);
366 }
367 if (array_key_exists('fee_level', $params)) {
368 $counter = 1;
369 foreach ($params['fee_level'] as $label => $amount) {
370 $this->type("label_{$counter}", $label);
371 $this->type("value_{$counter}", $amount);
372 $counter++;
373 }
374 }
375
376 $this->click('_qf_Fee_upload-bottom');
ed174dea 377 $this->waitForElementPresent('_qf_Fee_cancel-top');
6a488035
TO
378
379 // Go to Online Registration tab
380 $this->click('link=Online Registration');
381 $this->waitForElementPresent('_qf_Registration_upload-bottom');
382
383 $this->check('is_online_registration');
384 $this->assertChecked('is_online_registration');
385
386 $this->fillRichTextField('intro_text', 'Fill in all the fields below and click Continue.');
387
388 // enable confirmation email
389 $this->click('CIVICRM_QFID_1_is_email_confirm');
390 $this->type('confirm_from_name', 'Jane Doe');
391 $this->type('confirm_from_email', 'jane.doe@example.org');
392
393 $this->click('_qf_Registration_upload-bottom');
ed174dea 394 $this->waitForElementPresent('_qf_Registration_upload-bottom');
395 $this->waitForTextPresent("'Online Registration' information has been saved.");
6a488035
TO
396
397 // verify event input on info page
398 // start at Manage Events listing
42daf119 399 $this->openCiviPage('event/manage', 'reset=1');
6a488035
TO
400 $this->click('link=' . $params['title']);
401
402 $this->waitForPageToLoad($this->getTimeoutMsec());
403 return $this->getLocation();
404 }
405
4cbe18b8
EM
406 /**
407 * @param array $participant
408 */
d17310e4 409 function _testRegisterWithBillingInfo($participant = array()) {
6a488035
TO
410 $this->waitForElementPresent("credit_card_type");
411 $this->select('credit_card_type', 'value=Visa');
412 $this->type('credit_card_number', '4111111111111111');
413 $this->type('cvv2', '000');
414 $this->select('credit_card_exp_date[M]', 'value=1');
415 $this->select('credit_card_exp_date[Y]', 'value=2020');
416 $this->type('billing_first_name', isset($participant['first_name']) ? $participant['first_name'] : 'Jane_' . substr(sha1(rand()), 0, 5));
417 $this->type('billing_last_name', isset($participant['last_name']) ? $participant['last_name'] : 'San_' . substr(sha1(rand()), 0, 5));
418 $this->type('billing_street_address-5', '15 Main St.');
419 $this->type(' billing_city-5', 'San Jose');
420 $this->select('billing_country_id-5', 'value=1228');
421 $this->select('billing_state_province_id-5', 'value=1004');
422 $this->type('billing_postal_code-5', '94129');
423
225a8648 424 $this->clickLink('_qf_Register_upload-bottom', '_qf_Confirm_next-bottom');
6a488035
TO
425 $confirmStrings = array('Event Fee(s)', 'Billing Name and Address', 'Credit Card Information');
426 $this->assertStringsPresent($confirmStrings);
427 $this->click('_qf_Confirm_next-bottom');
428 $this->waitForPageToLoad($this->getTimeoutMsec());
429 $thankStrings = array('Thank You for Registering', 'Event Total', 'Transaction Date');
430 $this->assertStringsPresent($thankStrings);
431 }
432
4cbe18b8
EM
433 /**
434 * @param $eventParams
435 * @param $participants
436 * @param $priceFieldOptionCounts
437 */
6a488035 438 function _testPricesetDetailsCustomSearch($eventParams, $participants, $priceFieldOptionCounts) {
42daf119 439 $this->openCiviPage('contact/search/custom', 'csid=9&reset=1');
6a488035
TO
440
441 $this->select('event_id', 'label=' . $eventParams['title']);
442 $this->click('_qf_Custom_refresh-bottom');
443 $this->waitForPageToLoad($this->getTimeoutMsec());
444
445 $tableHeaders = array('Contact Id', 'Participant Id', 'Name');
446 $tableHeaders = array_merge($tableHeaders, array_keys(current($priceFieldOptionCounts)));
447
448 $tdnum = 2;
449 foreach ($tableHeaders as $header) {
ed174dea 450 $this->verifyText("xpath=//form[@id='Custom']//div[@class='crm-search-results']//table[@class='selector row-highlight']/thead/tr[1]/th[$tdnum]", $header);
6a488035
TO
451 $tdnum++;
452 }
453
454 foreach ($participants as $participantNum => $participant) {
455 $tdnum = 4;
ed174dea 456 $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']}"));
6a488035
TO
457 foreach ($priceFieldOptionCounts[$participantNum] as $priceFieldOptionCount) {
458 $tdnum++;
ed174dea 459 $this->verifyText("xpath=//form[@id='Custom']//div[@class='crm-search-results']//table[@class='selector row-highlight']/tbody/tr[{$participantNum}]/td[{$tdnum}]", preg_quote($priceFieldOptionCount));
6a488035
TO
460 }
461 }
462 }
463}
464