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