Import from SVN (r45945, r596)
[civicrm-core.git] / tests / phpunit / WebTest / Event / ParticipantCountTest.php
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
28 require_once 'CiviTest/CiviSeleniumTestCase.php';
29 class WebTest_Event_ParticipantCountTest extends CiviSeleniumTestCase {
30
31 protected function setUp() {
32 parent::setUp();
33 }
34
35 function testParticipantCountWithFeelevel() {
36 $this->open($this->sboxPath);
37
38 // Log in using webtestLogin() method
39 $this->webtestLogin();
40
41 // We need a payment processor
42 $processorName = 'Webtest Dummy' . substr(sha1(rand()), 0, 7);
43 $this->webtestAddPaymentProcessor($processorName);
44
45 // create an event
46 $eventTitle = 'A Conference - ' . substr(sha1(rand()), 0, 7);
47 $paramsEvent = array(
48 'title' => $eventTitle,
49 'template_id' => 6,
50 'event_type_id' => 4,
51 'payment_processor' => $processorName,
52 'fee_level' => array(
53 'Member' => '250.00',
54 'Non-Member' => '325.00',
55 ),
56 );
57
58 $infoEvent = $this->_testAddEvent($paramsEvent);
59
60 // logout to register for event.
61 $this->open($this->sboxPath . 'civicrm/logout?reset=1');
62 $this->waitForPageToLoad($this->getTimeoutMsec());
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='form-radio']");
73
74 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
75 $this->type('email-Primary', $email);
76
77 // fill billing details and register
78 $this->_testRegisterWithBillingInfo();
79
80 // Register Participant 2
81 // visit event info page
82 $this->open($infoEvent);
83
84 // register for event
85 $this->click('link=Register Now');
86 $this->waitForElementPresent('_qf_Register_upload-bottom');
87
88 $this->click("xpath=//input[@class='form-radio']");
89 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
90 $this->type('email-Primary', $email);
91
92 // fill billing details and register
93 $this->_testRegisterWithBillingInfo();
94
95 // login to check participant count
96 $this->open($this->sboxPath);
97 $this->webtestLogin();
98
99 // Find Participant
100 $this->open($this->sboxPath . 'civicrm/event/search?reset=1');
101 $this->waitForElementPresent('participant_fee_amount_low');
102 $this->click("event_name");
103 $this->type("event_name", $eventTitle);
104 $this->typeKeys("event_name", $eventTitle);
105 $this->waitForElementPresent("css=div.ac_results-inner li");
106 $this->click("css=div.ac_results-inner li");
107 $this->click('_qf_Search_refresh');
108 $this->waitForPageToLoad($this->getTimeoutMsec());
109
110 // verify number of registered participants
111 $this->assertStringsPresent(array('2 Result'));
112 }
113
114 function testParticipantCountWithPriceset() {
115 $this->open($this->sboxPath);
116
117 // Log in using webtestLogin() method
118 $this->webtestLogin();
119
120 // We need a payment processor
121 $processorName = 'Webtest Dummy' . substr(sha1(rand()), 0, 7);
122 $this->webtestAddPaymentProcessor($processorName);
123
124 // create priceset
125 $priceset = 'Price - ' . substr(sha1(rand()), 0, 7);
126 $this->_testAddSet($priceset);
127
128 // create price fields
129 $fields = array(
130 'Full Conference' => array('type' => 'Text',
131 'amount' => '525.00',
132 'count' => '2',
133 ),
134 'Meal Choice' => array(
135 'type' => 'Select',
136 'options' => array(
137 1 => array('label' => 'Chicken',
138 'amount' => '525.00',
139 'count' => '2',
140 ),
141 2 => array(
142 'label' => 'Vegetarian',
143 'amount' => '200.00',
144 'count' => '2',
145 ),
146 ),
147 ),
148 'Pre-conference Meetup?' => array(
149 'type' => 'Radio',
150 'options' => array(
151 1 => array('label' => 'Yes',
152 'amount' => '50.00',
153 'count' => '2',
154 ),
155 2 => array(
156 'label' => 'No',
157 'amount' => '0',
158 ),
159 ),
160 ),
161 'Evening Sessions' => array(
162 'type' => 'CheckBox',
163 'options' => array(
164 1 => array('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
179 $this->type('label', $label);
180 $this->select('html_type', "value={$field['type']}");
181
182 if ($field['type'] == 'Text') {
183 $this->type('price', $field['amount']);
184 //yash
185 $this->waitForElementPresent('count');
186 $this->type('count', $field['count']);
187 $this->check('is_required');
188 }
189 else {
190 $this->_testAddMultipleChoiceOptions($field['options']);
191 }
192 $this->click('_qf_Field_next_new-bottom');
193 $this->waitForPageToLoad($this->getTimeoutMsec());
194 $this->waitForElementPresent('_qf_Field_next-bottom');
195 }
196
197 // create event.
198 $eventTitle = 'Meeting - ' . substr(sha1(rand()), 0, 7);
199 $paramsEvent = array(
200 'title' => $eventTitle,
201 'template_id' => 6,
202 'event_type_id' => 4,
203 'payment_processor' => $processorName,
204 'price_set' => $priceset,
205 );
206
207 $infoEvent = $this->_testAddEvent($paramsEvent);
208
209 // logout to register for event.
210 $this->open($this->sboxPath . 'civicrm/logout?reset=1');
211 $this->waitForPageToLoad($this->getTimeoutMsec());
212
213 $priceFieldOptionCounts = $participants = array();
214
215 // Register Participant 1
216 // visit event info page
217 $this->open($infoEvent);
218 $this->waitForPageToLoad($this->getTimeoutMsec());
219
220 // register for event
221 $this->click('link=Register Now');
222 $this->waitForElementPresent('_qf_Register_upload-bottom');
223
224 $this->type("xpath=//input[@class='form-text four required']", '1');
225
226 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
227 $this->type('email-Primary', $email);
228
229 $participants[1] = array(
230 'email' => $email,
231 'first_name' => 'Jane_' . substr(sha1(rand()), 0, 5),
232 'last_name' => 'San_' . substr(sha1(rand()), 0, 5),
233 );
234
235 // fill billing related info and register
236 $this->_testRegisterWithBillingInfo($participants[1]);
237
238 // Options filled by 1st participants.
239 $priceFieldOptionCounts[1] = array(
240 'Full Conference' => 1,
241 'Meal Choice - Chicken' => 1,
242 'Meal Choice - Vegetarian' => 0,
243 'Pre-conference Meetup? - Yes' => 1,
244 'Pre-conference Meetup? - No' => 0,
245 'Evening Sessions - First Five' => 1,
246 'Evening Sessions - Second Four' => 0,
247 );
248
249 // Register Participant 1
250 // visit event info page
251 $this->open($infoEvent);
252
253 // register for event
254 $this->click('link=Register Now');
255 $this->waitForElementPresent('_qf_Register_upload-bottom');
256
257 $this->type("xpath=//input[@class='form-text four required']", '2');
258 $email = 'jane_' . substr(sha1(rand()), 0, 5) . '@example.org';
259 $this->type('email-Primary', $email);
260
261 $participants[2] = array(
262 'email' => $email,
263 'first_name' => 'Jane_' . substr(sha1(rand()), 0, 5),
264 'last_name' => 'San_' . substr(sha1(rand()), 0, 5),
265 );
266
267 // fill billing related info and register
268 $this->_testRegisterWithBillingInfo($participants[2]);
269
270 // Options filled by 2nd participants.
271 $priceFieldOptionCounts[2] = array(
272 'Full Conference' => 2,
273 'Meal Choice - Chicken' => 1,
274 'Meal Choice - Vegetarian' => 0,
275 'Pre-conference Meetup? - Yes' => 1,
276 'Pre-conference Meetup? - No' => 0,
277 'Evening Sessions - First Five' => 1,
278 'Evening Sessions - Second Four' => 0,
279 );
280
281 // login to check participant count
282 $this->open($this->sboxPath);
283 $this->webtestLogin();
284
285 // Find Participant
286 $this->open($this->sboxPath . 'civicrm/event/search?reset=1');
287 $this->waitForElementPresent('participant_fee_amount_low');
288 $this->click("event_name");
289 $this->type("event_name", $eventTitle);
290 $this->typeKeys("event_name", $eventTitle);
291 $this->waitForElementPresent("css=div.ac_results-inner li");
292 $this->click("css=div.ac_results-inner li");
293 $this->click('_qf_Search_refresh');
294 $this->waitForPageToLoad($this->getTimeoutMsec());
295
296 // verify number of participants records and total participant count
297 $this->assertStringsPresent(array('2 Result', 'Actual participant count : 24'));
298
299 // CRM-7953, check custom search Price Set Details for Event
300 // Participants
301 $this->_testPricesetDetailsCustomSearch($paramsEvent, $participants, $priceFieldOptionCounts);
302 }
303
304 function _testAddSet($setTitle, $financialType = 'Event Fee') {
305 $this->open($this->sboxPath . 'civicrm/admin/price?reset=1&action=add');
306 $this->waitForPageToLoad($this->getTimeoutMsec());
307 $this->waitForElementPresent('_qf_Set_next-bottom');
308
309 // Enter Priceset fields (Title, Used For ...)
310 $this->type('title', $setTitle);
311 $this->check('extends[1]');
312 $this->select("css=select.form-select", "label={$financialType}");
313 $this->type('help_pre', 'This is test priceset.');
314
315 $this->assertChecked('is_active', 'Verify that Is Active checkbox is set.');
316 $this->click('_qf_Set_next-bottom');
317
318 $this->waitForPageToLoad($this->getTimeoutMsec());
319 $this->waitForElementPresent('_qf_Field_next-bottom');
320 }
321
322 function _testAddMultipleChoiceOptions($options) {
323 foreach ($options as $oIndex => $oValue) {
324 $this->type("option_label_{$oIndex}", $oValue['label']);
325 $this->type("option_amount_{$oIndex}", $oValue['amount']);
326 if (array_key_exists('count', $oValue)) {
327 $this->waitForElementPresent("option_count_{$oIndex}");
328 $this->type("option_count_{$oIndex}", $oValue['count']);
329 }
330 $this->click('link=another choice');
331 }
332 $this->click('CIVICRM_QFID_1_2');
333 }
334
335 function _testAddEvent($params) {
336 $this->open($this->sboxPath . 'civicrm/event/add?reset=1&action=add');
337
338 $this->waitForElementPresent('_qf_EventInfo_upload-bottom');
339
340 // Let's start filling the form with values.
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->waitForPageToLoad($this->getTimeoutMsec());
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->fillRichTextField('intro_text', 'Fill in all the fields below and click Continue.');
392
393 // enable confirmation email
394 $this->click('CIVICRM_QFID_1_is_email_confirm');
395 $this->type('confirm_from_name', 'Jane Doe');
396 $this->type('confirm_from_email', 'jane.doe@example.org');
397
398 $this->click('_qf_Registration_upload-bottom');
399 $this->waitForPageToLoad($this->getTimeoutMsec());
400 $this->waitForTextPresent("'Registration' information has been saved.");
401
402 // verify event input on info page
403 // start at Manage Events listing
404 $this->open($this->sboxPath . 'civicrm/event/manage?reset=1');
405 $this->click('link=' . $params['title']);
406
407 $this->waitForPageToLoad($this->getTimeoutMsec());
408 return $this->getLocation();
409 }
410
411 function _testRegisterWithBillingInfo($participant = array(
412 )) {
413 $this->waitForElementPresent("credit_card_type");
414 $this->select('credit_card_type', 'value=Visa');
415 $this->type('credit_card_number', '4111111111111111');
416 $this->type('cvv2', '000');
417 $this->select('credit_card_exp_date[M]', 'value=1');
418 $this->select('credit_card_exp_date[Y]', 'value=2020');
419 $this->type('billing_first_name', isset($participant['first_name']) ? $participant['first_name'] : 'Jane_' . substr(sha1(rand()), 0, 5));
420 $this->type('billing_last_name', isset($participant['last_name']) ? $participant['last_name'] : 'San_' . substr(sha1(rand()), 0, 5));
421 $this->type('billing_street_address-5', '15 Main St.');
422 $this->type(' billing_city-5', 'San Jose');
423 $this->select('billing_country_id-5', 'value=1228');
424 $this->select('billing_state_province_id-5', 'value=1004');
425 $this->type('billing_postal_code-5', '94129');
426
427 $this->click('_qf_Register_upload-bottom');
428 $this->waitForPageToLoad($this->getTimeoutMsec());
429 $this->waitForElementPresent('_qf_Confirm_next-bottom');
430 $confirmStrings = array('Event Fee(s)', 'Billing Name and Address', 'Credit Card Information');
431 $this->assertStringsPresent($confirmStrings);
432 $this->click('_qf_Confirm_next-bottom');
433 $this->waitForPageToLoad($this->getTimeoutMsec());
434 $thankStrings = array('Thank You for Registering', 'Event Total', 'Transaction Date');
435 $this->assertStringsPresent($thankStrings);
436 }
437
438 function _testPricesetDetailsCustomSearch($eventParams, $participants, $priceFieldOptionCounts) {
439 $this->open($this->sboxPath . 'civicrm/contact/search/custom?csid=9&reset=1');
440 $this->waitForPageToLoad($this->getTimeoutMsec());
441
442 $this->select('event_id', 'label=' . $eventParams['title']);
443 $this->click('_qf_Custom_refresh-bottom');
444 $this->waitForPageToLoad($this->getTimeoutMsec());
445
446 $tableHeaders = array('Contact Id', 'Participant Id', 'Name');
447 $tableHeaders = array_merge($tableHeaders, array_keys(current($priceFieldOptionCounts)));
448
449 $tdnum = 2;
450 foreach ($tableHeaders as $header) {
451 $this->verifyText("xpath=//form[@id='Custom']//div[@class='crm-search-results']//table[@class='selector']/thead/tr[1]/th[$tdnum]", $header);
452 $tdnum++;
453 }
454
455 foreach ($participants as $participantNum => $participant) {
456 $tdnum = 4;
457 $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']}"));
458 foreach ($priceFieldOptionCounts[$participantNum] as $priceFieldOptionCount) {
459 $tdnum++;
460 $this->verifyText("xpath=//form[@id='Custom']//div[@class='crm-search-results']//table[@class='selector']/tbody/tr[{$participantNum}]/td[{$tdnum}]", preg_quote($priceFieldOptionCount));
461 }
462 }
463 }
464 }
465