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