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