Merge pull request #2991 from colemanw/master
[civicrm-core.git] / tests / phpunit / WebTest / Event / MultipleEventRegistrationbyCartTest.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_MultipleEventRegistrationbyCartTest extends CiviSeleniumTestCase {
76e86fd8 29
6a488035
TO
30 protected function setUp() {
31 parent::setUp();
32 }
76e86fd8 33
d17310e4 34 // this functionality is broken hence skipping the test
35 function skiptestAuthenticatedMultipleEvent() {
76e86fd8 36
6a488035
TO
37 // Log in using webtestLogin() method
38 $this->webtestLogin();
76e86fd8 39
6a488035 40 //Enable shopping cart style
071a6d2e 41 $this->openCiviPage("admin/setting/preferences/event", "reset=1");
6a488035
TO
42 $this->check("enable_cart");
43 $this->click("_qf_Event_next-top");
44 $this->waitForPageToLoad($this->getTimeoutMsec());
76e86fd8 45
6a488035
TO
46 // We need a payment processor
47 $processorName = "Webtest Dummy" . substr(sha1(rand()), 0, 7);
48 $this->webtestAddPaymentProcessor($processorName);
76e86fd8 49
6a488035 50 //event 1
42daf119 51
071a6d2e 52 $this->openCiviPage("event/add", "reset=1&action=add");
76e86fd8 53
6a488035
TO
54 $eventTitle1 = 'My Conference1 - ' . substr(sha1(rand()), 0, 7);
55 $eventDescription1 = "Here is a description for this conference 1.";
56 $this->_testAddEventInfo($eventTitle1, $eventDescription1);
76e86fd8 57
6a488035
TO
58 $streetAddress1 = "100 Main Street";
59 $this->_testAddLocation($streetAddress1);
76e86fd8 60
6a488035 61 $this->_testAddFees(FALSE, FALSE, $processorName);
76e86fd8 62
6a488035
TO
63 // intro text for registration page
64 $registerIntro = "Fill in all the fields below and click Continue.";
65 $multipleRegistrations = TRUE;
66 $this->_testAddOnlineRegistration($registerIntro, $multipleRegistrations);
76e86fd8 67
6a488035
TO
68 $eventInfoStrings1 = array($eventTitle1, $eventDescription1, $streetAddress1);
69 $this->_AddEventToCart($eventTitle1, $eventInfoStrings1);
76e86fd8 70
6a488035 71 //event 2
42daf119 72
071a6d2e 73 $this->openCiviPage("event/add", "reset=1&action=add");
76e86fd8 74
6a488035
TO
75 $eventTitle2 = 'My Conference2 - ' . substr(sha1(rand()), 0, 7);
76 $eventDescription2 = "Here is a description for this conference 2.";
77 $this->_testAddEventInfo($eventTitle2, $eventDescription2);
76e86fd8 78
6a488035
TO
79 $streetAddress2 = "101 Main Street";
80 $this->_testAddLocation($streetAddress2);
76e86fd8 81
6a488035 82 $this->_testAddFees(FALSE, FALSE, $processorName);
76e86fd8 83
6a488035
TO
84 // intro text for registration page
85 $registerIntro = "Fill in all the fields below and click Continue.";
86 $multipleRegistrations = TRUE;
87 $this->_testAddOnlineRegistration($registerIntro, $multipleRegistrations);
76e86fd8 88
6a488035
TO
89 $eventInfoStrings2 = array($eventTitle2, $eventDescription2, $streetAddress2);
90 $this->_AddEventToCart($eventTitle2, $eventInfoStrings2);
76e86fd8 91
6a488035 92 //event 3
42daf119 93
071a6d2e 94 $this->openCiviPage("event/add", "reset=1&action=add");
76e86fd8 95
6a488035
TO
96 $eventTitle3 = 'My Conference3 - ' . substr(sha1(rand()), 0, 7);
97 $eventDescription3 = "Here is a description for this conference 3.";
98 $this->_testAddEventInfo($eventTitle3, $eventDescription3);
76e86fd8 99
6a488035
TO
100 $streetAddress3 = "102 Main Street";
101 $this->_testAddLocation($streetAddress3);
76e86fd8 102
6a488035 103 $this->_testAddFees(FALSE, FALSE, $processorName);
76e86fd8 104
6a488035
TO
105 // intro text for registration page
106 $registerIntro = "Fill in all the fields below and click Continue.";
107 $multipleRegistrations = TRUE;
108 $this->_testAddOnlineRegistration($registerIntro, $multipleRegistrations);
76e86fd8 109
6a488035
TO
110 $eventInfoStrings3 = array($eventTitle3, $eventDescription3, $streetAddress3);
111 $this->_AddEventToCart($eventTitle3, $eventInfoStrings3);
76e86fd8 112
6a488035
TO
113 //Checkout
114 $value = $this->_testCheckOut();
76e86fd8 115
6a488035 116 //three event names
f0a9a781 117 $events = array(
118 1 => $eventTitle1,
119 2 => $eventTitle2,
120 3 => $eventTitle3,
121 );
76e86fd8
CW
122 //check the existence of the contacts who were registered and the one who did the contribution
123
f0a9a781 124 $this->_checkContributionsandEventRegistration($value[0], $value[1], $events);
6a488035 125 }
76e86fd8 126
d17310e4 127 // this functionality is broken hence skipping the test
128 function skiptestAnonymousMultipleEvent() {
f0a9a781 129 // This is the path where our testing install resides.
6a488035
TO
130 // The rest of URL is defined in CiviSeleniumTestCase base class, in
131 // class attributes.
76e86fd8 132
6a488035
TO
133 // Log in using webtestLogin() method
134 $this->webtestLogin();
76e86fd8 135
6a488035
TO
136 // We need a payment processor
137 $processorName = "Webtest Dummy" . substr(sha1(rand()), 0, 7);
138 $this->webtestAddPaymentProcessor($processorName);
76e86fd8 139
6a488035 140 //event 1
42daf119 141
071a6d2e 142 $this->openCiviPage("event/add", "reset=1&action=add");
76e86fd8 143
6a488035
TO
144 $eventTitle1 = 'My Conference1 - ' . substr(sha1(rand()), 0, 7);
145 $eventDescription1 = "Here is a description for this conference 1.";
146 $this->_testAddEventInfo($eventTitle1, $eventDescription1);
76e86fd8 147
6a488035
TO
148 $streetAddress1 = "100 Main Street";
149 $this->_testAddLocation($streetAddress1);
76e86fd8 150
6a488035 151 $this->_testAddFees(FALSE, FALSE, $processorName);
76e86fd8 152
6a488035
TO
153 // intro text for registration page
154 $registerIntro = "Fill in all the fields below and click Continue.";
155 $multipleRegistrations = TRUE;
156 $this->_testAddOnlineRegistration($registerIntro, $multipleRegistrations);
76e86fd8 157
6a488035
TO
158 $eventInfoStrings1 = array($eventTitle1, $eventDescription1, $streetAddress1);
159 $registerUrl1 = $this->_testVerifyEventInfo($eventTitle1, $eventInfoStrings1);
160
161 //event 2
42daf119 162
071a6d2e 163 $this->openCiviPage("event/add", "reset=1&action=add");
76e86fd8 164
6a488035
TO
165 $eventTitle2 = 'My Conference2 - ' . substr(sha1(rand()), 0, 7);
166 $eventDescription2 = "Here is a description for this conference 2.";
167 $this->_testAddEventInfo($eventTitle2, $eventDescription2);
76e86fd8 168
6a488035
TO
169 $streetAddress2 = "101 Main Street";
170 $this->_testAddLocation($streetAddress2);
76e86fd8 171
6a488035 172 $this->_testAddFees(FALSE, FALSE, $processorName);
76e86fd8 173
6a488035
TO
174 // intro text for registration page
175 $registerIntro = "Fill in all the fields below and click Continue.";
176 $multipleRegistrations = TRUE;
177 $this->_testAddOnlineRegistration($registerIntro, $multipleRegistrations);
76e86fd8 178
6a488035
TO
179 $eventInfoStrings2 = array($eventTitle2, $eventDescription2, $streetAddress2);
180 $registerUrl2 = $this->_testVerifyEventInfo($eventTitle2, $eventInfoStrings2);
181
182 //event 3
42daf119 183
071a6d2e 184 $this->openCiviPage("event/add", "reset=1&action=add");
76e86fd8 185
6a488035
TO
186 $eventTitle3 = 'My Conference3 - ' . substr(sha1(rand()), 0, 7);
187 $eventDescription3 = "Here is a description for this conference 3.";
188 $this->_testAddEventInfo($eventTitle3, $eventDescription3);
76e86fd8 189
6a488035
TO
190 $streetAddress3 = "102 Main Street";
191 $this->_testAddLocation($streetAddress3);
76e86fd8 192
6a488035 193 $this->_testAddFees(FALSE, FALSE, $processorName);
76e86fd8 194
6a488035
TO
195 // intro text for registration page
196 $registerIntro = "Fill in all the fields below and click Continue.";
197 $multipleRegistrations = TRUE;
198 $this->_testAddOnlineRegistration($registerIntro, $multipleRegistrations);
76e86fd8 199
6a488035
TO
200 $eventInfoStrings3 = array($eventTitle3, $eventDescription3, $streetAddress3);
201 $registerUrl3 = $this->_testVerifyEventInfo($eventTitle3, $eventInfoStrings3);
202
203 //Enable shopping cart style
071a6d2e 204 $this->openCiviPage("admin/setting/preferences/event", "reset=1");
6a488035
TO
205 $this->check("enable_cart");
206 $this->click("_qf_Event_next-top");
207
208 $numberRegistrations = 1;
209 $anonymous = TRUE;
210 $this->_testOnlineRegistration($registerUrl1, $numberRegistrations, $anonymous);
211 $this->_testOnlineRegistration($registerUrl2, $numberRegistrations, $anonymous);
212 $this->_testOnlineRegistration($registerUrl3, $numberRegistrations, $anonymous);
213 //Checkout
214 $value = $this->_testCheckOut();
215 // Log in using webtestLogin() method
216 $this->webtestLogin();
217
071a6d2e
CW
218 $this->openCiviPage("dashboard", "reset=1");
219
6a488035 220 //three event names
f0a9a781 221 $events = array(
222 1 => $eventTitle1,
223 2 => $eventTitle2,
224 3 => $eventTitle3,
225 );
76e86fd8
CW
226 //check the existence of the contacts who were registered and the one who did the contribution
227
f0a9a781 228 $this->_checkContributionsandEventRegistration($value[0], $value[1], $events);
6a488035 229 }
76e86fd8 230
6a488035 231 function _testAddEventInfo($eventTitle, $eventDescription) {
6a488035
TO
232 $this->waitForElementPresent("_qf_EventInfo_upload-bottom");
233
6a488035
TO
234 $this->select("event_type_id", "value=1");
235
236 // Attendee role s/b selected now.
237 $this->select("default_role_id", "value=1");
238
239 // Enter Event Title, Summary and Description
240 $this->type("title", $eventTitle);
241 $this->type("summary", "This is a great conference. Sign up now!");
242
243 // Type description in ckEditor (fieldname, text to type, editor)
244 $this->fillRichTextField("description", $eventDescription, 'CKEditor');
245
246 // Choose Start and End dates.
247 // Using helper webtestFillDate function.
248 $this->webtestFillDateTime("start_date", "+1 week");
249 $this->webtestFillDateTime("end_date", "+1 week 1 day 8 hours ");
250
251 $this->type("max_participants", "50");
252 $this->click("is_map");
253 $this->click("_qf_EventInfo_upload-bottom");
254 }
255
256 function _testAddLocation($streetAddress) {
257 // Wait for Location tab form to load
258 $this->waitForPageToLoad($this->getTimeoutMsec());
259 $this->waitForElementPresent("_qf_Location_upload-bottom");
76e86fd8 260
6a488035
TO
261 $this->type("address_1_street_address", $streetAddress);
262 $this->type("address_1_city", "San Francisco");
263 $this->type("address_1_postal_code", "94117");
264 $this->select("address_1_state_province_id", "value=1004");
265 $this->type("email_1_email", "info@civicrm.org");
266
267 $this->click("_qf_Location_upload-bottom");
268
269 // Wait for "saved" status msg
270 $this->waitForPageToLoad($this->getTimeoutMsec());
271 $this->waitForTextPresent("'Location' information has been saved.");
272 }
273
274 function _testAddFees($discount = FALSE, $priceSet = FALSE, $processorName = "PP Pro") {
275 // Go to Fees tab
276 $this->click("link=Fees");
277 $this->waitForElementPresent("_qf_Fee_upload-bottom");
278 $this->click("CIVICRM_QFID_1_is_monetary");
279 $this->click("xpath=//tr[@class='crm-event-manage-fee-form-block-payment_processor']/td[2]/label[text()='$processorName']");
f0a9a781 280 $this->select('financial_type_id', 'Event Fee');
6a488035
TO
281 if ($priceSet) {
282 // get one - TBD
283 }
284 else {
285 $this->type("label_1", "Member");
286 $this->type("value_1", "250.00");
287 $this->type("label_2", "Non-member");
288 $this->type("value_2", "325.00");
289 $this->click("CIVICRM_QFID_2_6");
290 }
291
292 if ($discount) {
293 // enter early bird discount fees
294 $this->click("is_discount");
295 $this->waitForElementPresent("discount_name_1");
296 $this->type("discount_name_1", "Early-bird" . substr(sha1(rand()), 0, 7));
297 $this->webtestFillDate("discount_start_date_1", "-1 week");
298 $this->webtestFillDate("discount_end_date_1", "+2 week");
225a8648 299 $this->clickLink("_qf_Fee_submit", "discounted_value_2_1");
f0a9a781 300 $this->type("discounted_value_1_1", "225.00");
301 $this->type("discounted_value_2_1", "300.00");
6a488035
TO
302 $this->click("xpath=//fieldset[@id='discount']/fieldset/table/tbody/tr[2]/td[3]/input");
303 }
304
305 $this->click("_qf_Fee_upload-bottom");
306
307 // Wait for "saved" status msg
308 $this->waitForPageToLoad($this->getTimeoutMsec());
309 $this->waitForTextPresent("'Fee' information has been saved.");
310 }
311
312 function _testAddOnlineRegistration($registerIntro, $multipleRegistrations = FALSE) {
313 // Go to Online Registration tab
314 $this->click("link=Online Registration");
315 $this->waitForElementPresent("_qf_Registration_upload-bottom");
316
317 $this->check("is_online_registration");
318 $this->assertChecked("is_online_registration");
319 if ($multipleRegistrations) {
320 $this->check("is_multiple_registrations");
321 $this->assertChecked("is_multiple_registrations");
322 }
323
324 $this->fillRichTextField("intro_text", $registerIntro);
325
326 // enable confirmation email
327 $this->click("CIVICRM_QFID_1_is_email_confirm");
328 $this->type("confirm_from_name", "Jane Doe");
329 $this->type("confirm_from_email", "jane.doe@example.org");
330
331 $this->click("_qf_Registration_upload-bottom");
332 $this->waitForPageToLoad($this->getTimeoutMsec());
333 $this->waitForTextPresent("'Registration' information has been saved.");
334 }
335
336 function _AddEventToCart($eventTitle, $eventInfoStrings, $eventFees = NULL) {
337 // verify event input on info page
338 // start at Manage Events listing
071a6d2e 339 $this->openCiviPage("event/manage", "reset=1");
225a8648 340 $this->clickLink("link=$eventTitle", "link=Add to Cart");
6a488035
TO
341 $this->click("link=Add to Cart");
342 $this->waitForPageToLoad($this->getTimeoutMsec());
343 $this->assertTrue($this->isTextPresent("$eventTitle has been added to your cart"));
344 }
76e86fd8 345
6a488035
TO
346 function _testVerifyEventInfo($eventTitle, $eventInfoStrings, $eventFees = NULL) {
347 // verify event input on info page
348 // start at Manage Events listing
071a6d2e 349 $this->openCiviPage("event/manage", "reset=1");
6a488035
TO
350 $this->click("link=$eventTitle");
351 $this->waitForPageToLoad($this->getTimeoutMsec());
76e86fd8 352
6a488035
TO
353 // Check for correct event info strings
354 $this->assertStringsPresent($eventInfoStrings);
76e86fd8 355
6a488035
TO
356 // Optionally verify event fees (especially for discounts)
357 if ($eventFees) {
76e86fd8
CW
358 $this->assertStringsPresent($eventFees);
359
6a488035
TO
360 }
361 return $this->getLocation();
362 }
42daf119 363
6a488035
TO
364 function _testOnlineRegistration($registerUrl, $numberRegistrations = 1, $anonymous = TRUE) {
365 if ($anonymous) {
42daf119 366 $this->webtestLogout();
6a488035
TO
367 }
368 $this->open($registerUrl);
369 $this->waitForPageToLoad($this->getTimeoutMsec());
370 $this->waitForElementPresent("link=Add to Cart");
371 $this->click("link=Add to Cart");
42daf119 372 $this->waitForPageToLoad($this->getTimeoutMsec());
6a488035 373 }
42daf119 374
f0a9a781 375 function _testCheckOut() {
6a488035
TO
376 //View the Cart
377 $this->click("xpath=//div[@id='messages']/div/div/a[text()='View your cart.']");
76e86fd8 378
6a488035
TO
379 //Click on Checkout
380 $this->waitForElementPresent("xpath=//a[@class='button crm-check-out-button']/span");
381 $this->click("xpath=//a[@class='button crm-check-out-button']/span");
382 $this->waitForPageToLoad($this->getTimeoutMsec());
76e86fd8 383
f0a9a781 384 $firstName = "AB" . substr(sha1(rand()), 0, 7);
385 $lastName = "XY" . substr(sha1(rand()), 0, 7);
386 for ($i = 1; $i <= 3; $i++) {
387 $this->type("xpath=//form[@id='ParticipantsAndPrices']/fieldset[$i]/div/fieldset/div/div/fieldset/div/div[2]/input", "{$firstName}.{$lastName}@home.com");
388 $this->type("xpath=//form[@id='ParticipantsAndPrices']/fieldset[$i]/div/fieldset/div/div[2]/div[2]/input", "{$firstName}.{$lastName}@example.com");
6a488035
TO
389 $this->click("xpath=//form[@id='ParticipantsAndPrices']/fieldset[$i]/div[2]/div[2]/input[2]");
390 }
391 $this->click("_qf_ParticipantsAndPrices_upload-bottom");
392 $this->waitForPageToLoad($this->getTimeoutMsec());
393 $this->select("credit_card_type", "value=Visa");
394 $this->type("credit_card_number", "4111111111111111");
395 $this->type("cvv2", "000");
396 $this->select("credit_card_exp_date[M]", "value=1");
397 $this->select("credit_card_exp_date[Y]", "value=2020");
398 $this->type("billing_first_name", $firstName);
399 $this->type("billing_last_name", $lastName);
400 $this->type("billing_street_address-5", "15 Main St.");
401 $this->type(" billing_city-5", "San Jose");
402 $this->select("billing_country_id-5", "value=1228");
403 $this->select("billing_state_province_id-5", "value=1004");
404 $this->type("billing_postal_code-5", "94129");
405 $this->type("billing_contact_email", "{$firstName}.{$lastName}@example.com");
76e86fd8 406
6a488035
TO
407 $this->click("_qf_Payment_next-bottom");
408 $this->waitForPageToLoad($this->getTimeoutMsec());
76e86fd8 409
6a488035 410 $this->assertTrue($this->isTextPresent("This is your receipt of payment made for the following event registration."));
42daf119 411 return array($firstName, $lastName);
6a488035
TO
412 }
413
f0a9a781 414 function _checkContributionsandEventRegistration($firstName, $lastName, $events) {
6a488035
TO
415 //Type the registered participant's email in autocomplete.
416 $this->click('sort_name_navigation');
f0a9a781 417 $this->type('css=input#sort_name_navigation', "{$firstName}.{$lastName}@home.com");
6a488035 418 $this->typeKeys('css=input#sort_name_navigation', "{$firstName}.{$lastName}@home.com");
76e86fd8 419
6a488035
TO
420 // Wait for result list.
421 $this->waitForElementPresent("css=div.ac_results-inner li");
76e86fd8 422
6a488035
TO
423 // Visit contact summary page.
424 $this->click("css=div.ac_results-inner li");
425 $this->waitForPageToLoad($this->getTimeoutMsec());
76e86fd8 426
6a488035
TO
427 //click on Events Tab
428 $this->click("xpath=//li[@id='tab_participant']/a");
429 //check if the participant is registered for all the three events
f0a9a781 430 foreach ($events as $key => $value) {
6a488035
TO
431 $this->waitForElementPresent("link=$value");
432 $this->assertTrue($this->isElementPresent("link=$value"));
433 }
f0a9a781 434 for ($i = 1; $i <= 3; $i++) {
6a488035
TO
435 $this->waitForElementPresent("xpath=//table[@class='selector']/tbody/tr[$i]/td[6][text()='Registered']");
436 $this->assertTrue($this->isElementPresent("xpath=//table[@class='selector']/tbody/tr[$i]/td[6][text()='Registered']"));
437 }
76e86fd8 438
6a488035
TO
439 //Type the billing email in autocomplete.
440 $this->click('sort_name_navigation');
f0a9a781 441 $this->type('css=input#sort_name_navigation', "{$firstName}.{$lastName}@example.com");
6a488035 442 $this->typeKeys('css=input#sort_name_navigation', "{$firstName}.{$lastName}@example.com");
76e86fd8 443
6a488035
TO
444 // Wait for result list.
445 $this->waitForElementPresent("css=div.ac_results-inner li");
76e86fd8 446
6a488035
TO
447 // Visit contact summary page.
448 $this->click("css=div.ac_results-inner li");
449 $this->waitForPageToLoad($this->getTimeoutMsec());
76e86fd8 450
6a488035
TO
451 //click on Contributions Tab
452 $this->click("xpath=//li[@id='tab_contribute']/a");
453 //check for the three contributions
f0a9a781 454 foreach ($events as $key => $value) {
6a488035
TO
455 $this->waitForElementPresent("xpath=//table[@class='selector']/tbody/tr/td[3][contains(text(),'$value')]");
456 $this->assertTrue($this->isElementPresent("xpath=//table[@class='selector']/tbody/tr/td[3][contains(text(),'$value')]"));
457 }
76e86fd8 458
6a488035 459 //Disable shopping cart style
071a6d2e 460 $this->openCiviPage("admin/setting/preferences/event", "reset=1");
6a488035
TO
461 $this->click("enable_cart");
462 $this->click("_qf_Event_next-top");
463 }
42daf119 464}