Start migrating to use clickLink 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 }
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
216 $this->type("xpath=//input[@class='form-text four required']", '1');
217
218 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
219 $this->type('email-Primary', $email);
220
221 $participants[1] = array(
222 'email' => $email,
223 'first_name' => 'Jane_' . substr(sha1(rand()), 0, 5),
224 'last_name' => 'San_' . substr(sha1(rand()), 0, 5),
225 );
226
227 // fill billing related info and register
228 $this->_testRegisterWithBillingInfo($participants[1]);
229
230 // Options filled by 1st participants.
231 $priceFieldOptionCounts[1] = array(
232 'Full Conference' => 1,
233 'Meal Choice - Chicken' => 1,
234 'Meal Choice - Vegetarian' => 0,
235 'Pre-conference Meetup? - Yes' => 1,
236 'Pre-conference Meetup? - No' => 0,
237 'Evening Sessions - First Five' => 1,
238 'Evening Sessions - Second Four' => 0,
239 );
240
241 // Register Participant 1
242 // visit event info page
243 $this->open($infoEvent);
244
245 // register for event
246 $this->click('link=Register Now');
247 $this->waitForElementPresent('_qf_Register_upload-bottom');
248
249 $this->type("xpath=//input[@class='form-text four required']", '2');
250 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
251 $this->type('email-Primary', $email);
252
253 $participants[2] = array(
254 'email' => $email,
255 'first_name' => 'Jane_' . substr(sha1(rand()), 0, 5),
256 'last_name' => 'San_' . substr(sha1(rand()), 0, 5),
257 );
258
259 // fill billing related info and register
260 $this->_testRegisterWithBillingInfo($participants[2]);
261
262 // Options filled by 2nd participants.
263 $priceFieldOptionCounts[2] = array(
264 'Full Conference' => 2,
265 'Meal Choice - Chicken' => 1,
266 'Meal Choice - Vegetarian' => 0,
267 'Pre-conference Meetup? - Yes' => 1,
268 'Pre-conference Meetup? - No' => 0,
269 'Evening Sessions - First Five' => 1,
270 'Evening Sessions - Second Four' => 0,
271 );
272
273 // login to check participant count
6a488035
TO
274 $this->webtestLogin();
275
276 // Find Participant
42daf119 277 $this->openCiviPage('event/search', 'reset=1', 'participant_fee_amount_low');
6a488035
TO
278 $this->click("event_name");
279 $this->type("event_name", $eventTitle);
280 $this->typeKeys("event_name", $eventTitle);
281 $this->waitForElementPresent("css=div.ac_results-inner li");
282 $this->click("css=div.ac_results-inner li");
283 $this->click('_qf_Search_refresh');
284 $this->waitForPageToLoad($this->getTimeoutMsec());
285
286 // verify number of participants records and total participant count
287 $this->assertStringsPresent(array('2 Result', 'Actual participant count : 24'));
288
289 // CRM-7953, check custom search Price Set Details for Event
290 // Participants
291 $this->_testPricesetDetailsCustomSearch($paramsEvent, $participants, $priceFieldOptionCounts);
292 }
293
294 function _testAddSet($setTitle, $financialType = 'Event Fee') {
42daf119 295 $this->openCiviPage('admin/price', 'reset=1&action=add', '_qf_Set_next-bottom');
6a488035
TO
296
297 // Enter Priceset fields (Title, Used For ...)
298 $this->type('title', $setTitle);
299 $this->check('extends[1]');
300 $this->select("css=select.form-select", "label={$financialType}");
301 $this->type('help_pre', 'This is test priceset.');
302
303 $this->assertChecked('is_active', 'Verify that Is Active checkbox is set.');
225a8648 304 $this->clickLink('_qf_Set_next-bottom', '_qf_Field_next-bottom');
6a488035
TO
305 }
306
307 function _testAddMultipleChoiceOptions($options) {
308 foreach ($options as $oIndex => $oValue) {
309 $this->type("option_label_{$oIndex}", $oValue['label']);
310 $this->type("option_amount_{$oIndex}", $oValue['amount']);
311 if (array_key_exists('count', $oValue)) {
312 $this->waitForElementPresent("option_count_{$oIndex}");
313 $this->type("option_count_{$oIndex}", $oValue['count']);
314 }
315 $this->click('link=another choice');
316 }
317 $this->click('CIVICRM_QFID_1_2');
318 }
319
320 function _testAddEvent($params) {
42daf119 321 $this->openCiviPage('event/add', 'reset=1&action=add', '_qf_EventInfo_upload-bottom');
6a488035 322
6a488035
TO
323 $this->select('event_type_id', "value={$params['event_type_id']}");
324
325 // Attendee role s/b selected now.
326 $this->select('default_role_id', 'value=1');
327
328 // Enter Event Title, Summary and Description
329 $this->type('title', $params['title']);
330 $this->type('summary', 'This is a great conference. Sign up now!');
331 $this->fillRichTextField('description', 'Here is a description for this event.', 'CKEditor');
332
333 // Choose Start and End dates.
334 // Using helper webtestFillDate function.
335 $this->webtestFillDateTime('start_date', '+1 week');
336 $this->webtestFillDateTime('end_date', '+1 week 1 day 8 hours ');
337
338 $this->type('max_participants', '50');
339 $this->click('is_map');
340 $this->click('_qf_EventInfo_upload-bottom');
341
342 // Wait for Location tab form to load
343 $this->waitForPageToLoad($this->getTimeoutMsec());
344
345 // Go to Fees tab
346 $this->click('link=Fees');
347 $this->waitForElementPresent('_qf_Fee_upload-bottom');
348 $this->click('CIVICRM_QFID_1_is_monetary');
349 $this->click("xpath=//tr[@class='crm-event-manage-fee-form-block-payment_processor']/td[2]/label[text()='" . $params['payment_processor'] . "']");
350 $this->select('financial_type_id','Event Fee');
351 if (array_key_exists('price_set', $params)) {
352 $this->select('price_set_id', 'label=' . $params['price_set']);
353 }
354 if (array_key_exists('fee_level', $params)) {
355 $counter = 1;
356 foreach ($params['fee_level'] as $label => $amount) {
357 $this->type("label_{$counter}", $label);
358 $this->type("value_{$counter}", $amount);
359 $counter++;
360 }
361 }
362
363 $this->click('_qf_Fee_upload-bottom');
364 $this->waitForPageToLoad($this->getTimeoutMsec());
365
366 // Go to Online Registration tab
367 $this->click('link=Online Registration');
368 $this->waitForElementPresent('_qf_Registration_upload-bottom');
369
370 $this->check('is_online_registration');
371 $this->assertChecked('is_online_registration');
372
373 $this->fillRichTextField('intro_text', 'Fill in all the fields below and click Continue.');
374
375 // enable confirmation email
376 $this->click('CIVICRM_QFID_1_is_email_confirm');
377 $this->type('confirm_from_name', 'Jane Doe');
378 $this->type('confirm_from_email', 'jane.doe@example.org');
379
380 $this->click('_qf_Registration_upload-bottom');
381 $this->waitForPageToLoad($this->getTimeoutMsec());
382 $this->waitForTextPresent("'Registration' information has been saved.");
383
384 // verify event input on info page
385 // start at Manage Events listing
42daf119 386 $this->openCiviPage('event/manage', 'reset=1');
6a488035
TO
387 $this->click('link=' . $params['title']);
388
389 $this->waitForPageToLoad($this->getTimeoutMsec());
390 return $this->getLocation();
391 }
392
393 function _testRegisterWithBillingInfo($participant = array(
394 )) {
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
225a8648 409 $this->clickLink('_qf_Register_upload-bottom', '_qf_Confirm_next-bottom');
6a488035
TO
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) {
42daf119 419 $this->openCiviPage('contact/search/custom', 'csid=9&reset=1');
6a488035
TO
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']/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']/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']/tbody/tr[{$participantNum}]/td[{$tdnum}]", preg_quote($priceFieldOptionCount));
440 }
441 }
442 }
443}
444