Merge pull request #3223 from lcdservices/CRM-14672
[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 class WebTest_Event_MultipleEventRegistrationbyCartTest extends CiviSeleniumTestCase {
29
30 protected function setUp() {
31 parent::setUp();
32 }
33
34 // this functionality is broken hence skipping the test
35 function skiptestAuthenticatedMultipleEvent() {
36
37 // Log in using webtestLogin() method
38 $this->webtestLogin();
39
40 //Enable shopping cart style
41 $this->openCiviPage("admin/setting/preferences/event", "reset=1");
42 $this->check("enable_cart");
43 $this->click("_qf_Event_next-top");
44 $this->waitForPageToLoad($this->getTimeoutMsec());
45
46 // We need a payment processor
47 $processorName = "Webtest Dummy" . substr(sha1(rand()), 0, 7);
48 $this->webtestAddPaymentProcessor($processorName);
49
50 //event 1
51
52 $this->openCiviPage("event/add", "reset=1&action=add");
53
54 $eventTitle1 = 'My Conference1 - ' . substr(sha1(rand()), 0, 7);
55 $eventDescription1 = "Here is a description for this conference 1.";
56 $this->_testAddEventInfo($eventTitle1, $eventDescription1);
57
58 $streetAddress1 = "100 Main Street";
59 $this->_testAddLocation($streetAddress1);
60
61 $this->_testAddFees(FALSE, FALSE, $processorName);
62
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);
67
68 $eventInfoStrings1 = array($eventTitle1, $eventDescription1, $streetAddress1);
69 $this->_AddEventToCart($eventTitle1, $eventInfoStrings1);
70
71 //event 2
72
73 $this->openCiviPage("event/add", "reset=1&action=add");
74
75 $eventTitle2 = 'My Conference2 - ' . substr(sha1(rand()), 0, 7);
76 $eventDescription2 = "Here is a description for this conference 2.";
77 $this->_testAddEventInfo($eventTitle2, $eventDescription2);
78
79 $streetAddress2 = "101 Main Street";
80 $this->_testAddLocation($streetAddress2);
81
82 $this->_testAddFees(FALSE, FALSE, $processorName);
83
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);
88
89 $eventInfoStrings2 = array($eventTitle2, $eventDescription2, $streetAddress2);
90 $this->_AddEventToCart($eventTitle2, $eventInfoStrings2);
91
92 //event 3
93
94 $this->openCiviPage("event/add", "reset=1&action=add");
95
96 $eventTitle3 = 'My Conference3 - ' . substr(sha1(rand()), 0, 7);
97 $eventDescription3 = "Here is a description for this conference 3.";
98 $this->_testAddEventInfo($eventTitle3, $eventDescription3);
99
100 $streetAddress3 = "102 Main Street";
101 $this->_testAddLocation($streetAddress3);
102
103 $this->_testAddFees(FALSE, FALSE, $processorName);
104
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);
109
110 $eventInfoStrings3 = array($eventTitle3, $eventDescription3, $streetAddress3);
111 $this->_AddEventToCart($eventTitle3, $eventInfoStrings3);
112
113 //Checkout
114 $value = $this->_testCheckOut();
115
116 //three event names
117 $events = array(
118 1 => $eventTitle1,
119 2 => $eventTitle2,
120 3 => $eventTitle3,
121 );
122 //check the existence of the contacts who were registered and the one who did the contribution
123
124 $this->_checkContributionsandEventRegistration($value[0], $value[1], $events);
125 }
126
127 // this functionality is broken hence skipping the test
128 function skiptestAnonymousMultipleEvent() {
129 // This is the path where our testing install resides.
130 // The rest of URL is defined in CiviSeleniumTestCase base class, in
131 // class attributes.
132
133 // Log in using webtestLogin() method
134 $this->webtestLogin();
135
136 // We need a payment processor
137 $processorName = "Webtest Dummy" . substr(sha1(rand()), 0, 7);
138 $this->webtestAddPaymentProcessor($processorName);
139
140 //event 1
141
142 $this->openCiviPage("event/add", "reset=1&action=add");
143
144 $eventTitle1 = 'My Conference1 - ' . substr(sha1(rand()), 0, 7);
145 $eventDescription1 = "Here is a description for this conference 1.";
146 $this->_testAddEventInfo($eventTitle1, $eventDescription1);
147
148 $streetAddress1 = "100 Main Street";
149 $this->_testAddLocation($streetAddress1);
150
151 $this->_testAddFees(FALSE, FALSE, $processorName);
152
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);
157
158 $eventInfoStrings1 = array($eventTitle1, $eventDescription1, $streetAddress1);
159 $registerUrl1 = $this->_testVerifyEventInfo($eventTitle1, $eventInfoStrings1);
160
161 //event 2
162
163 $this->openCiviPage("event/add", "reset=1&action=add");
164
165 $eventTitle2 = 'My Conference2 - ' . substr(sha1(rand()), 0, 7);
166 $eventDescription2 = "Here is a description for this conference 2.";
167 $this->_testAddEventInfo($eventTitle2, $eventDescription2);
168
169 $streetAddress2 = "101 Main Street";
170 $this->_testAddLocation($streetAddress2);
171
172 $this->_testAddFees(FALSE, FALSE, $processorName);
173
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);
178
179 $eventInfoStrings2 = array($eventTitle2, $eventDescription2, $streetAddress2);
180 $registerUrl2 = $this->_testVerifyEventInfo($eventTitle2, $eventInfoStrings2);
181
182 //event 3
183
184 $this->openCiviPage("event/add", "reset=1&action=add");
185
186 $eventTitle3 = 'My Conference3 - ' . substr(sha1(rand()), 0, 7);
187 $eventDescription3 = "Here is a description for this conference 3.";
188 $this->_testAddEventInfo($eventTitle3, $eventDescription3);
189
190 $streetAddress3 = "102 Main Street";
191 $this->_testAddLocation($streetAddress3);
192
193 $this->_testAddFees(FALSE, FALSE, $processorName);
194
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);
199
200 $eventInfoStrings3 = array($eventTitle3, $eventDescription3, $streetAddress3);
201 $registerUrl3 = $this->_testVerifyEventInfo($eventTitle3, $eventInfoStrings3);
202
203 //Enable shopping cart style
204 $this->openCiviPage("admin/setting/preferences/event", "reset=1");
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
218 $this->openCiviPage("dashboard", "reset=1");
219
220 //three event names
221 $events = array(
222 1 => $eventTitle1,
223 2 => $eventTitle2,
224 3 => $eventTitle3,
225 );
226 //check the existence of the contacts who were registered and the one who did the contribution
227
228 $this->_checkContributionsandEventRegistration($value[0], $value[1], $events);
229 }
230
231 function _testAddEventInfo($eventTitle, $eventDescription) {
232 $this->waitForElementPresent("_qf_EventInfo_upload-bottom");
233
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");
260
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']");
280 $this->select('financial_type_id', 'Event Fee');
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");
299 $this->clickLink("_qf_Fee_submit", "discounted_value_2_1");
300 $this->type("discounted_value_1_1", "225.00");
301 $this->type("discounted_value_2_1", "300.00");
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
339 $this->openCiviPage("event/manage", "reset=1");
340 $this->clickLink("link=$eventTitle", "link=Add to Cart");
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 }
345
346 function _testVerifyEventInfo($eventTitle, $eventInfoStrings, $eventFees = NULL) {
347 // verify event input on info page
348 // start at Manage Events listing
349 $this->openCiviPage("event/manage", "reset=1");
350 $this->click("link=$eventTitle");
351 $this->waitForPageToLoad($this->getTimeoutMsec());
352
353 // Check for correct event info strings
354 $this->assertStringsPresent($eventInfoStrings);
355
356 // Optionally verify event fees (especially for discounts)
357 if ($eventFees) {
358 $this->assertStringsPresent($eventFees);
359
360 }
361 return $this->getLocation();
362 }
363
364 function _testOnlineRegistration($registerUrl, $numberRegistrations = 1, $anonymous = TRUE) {
365 if ($anonymous) {
366 $this->webtestLogout();
367 }
368 $this->open($registerUrl);
369 $this->waitForPageToLoad($this->getTimeoutMsec());
370 $this->waitForElementPresent("link=Add to Cart");
371 $this->click("link=Add to Cart");
372 $this->waitForPageToLoad($this->getTimeoutMsec());
373 }
374
375 function _testCheckOut() {
376 //View the Cart
377 $this->click("xpath=//div[@id='messages']/div/div/a[text()='View your cart.']");
378
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());
383
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");
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");
406
407 $this->click("_qf_Payment_next-bottom");
408 $this->waitForPageToLoad($this->getTimeoutMsec());
409
410 $this->assertTrue($this->isTextPresent("This is your receipt of payment made for the following event registration."));
411 return array($firstName, $lastName);
412 }
413
414 function _checkContributionsandEventRegistration($firstName, $lastName, $events) {
415 //Type the registered participant's email in autocomplete.
416 $this->click('sort_name_navigation');
417 $this->type('css=input#sort_name_navigation', "{$firstName}.{$lastName}@home.com");
418 $this->typeKeys('css=input#sort_name_navigation', "{$firstName}.{$lastName}@home.com");
419
420 // Wait for result list.
421 $this->waitForElementPresent("css=div.ac_results-inner li");
422
423 // Visit contact summary page.
424 $this->click("css=div.ac_results-inner li");
425 $this->waitForPageToLoad($this->getTimeoutMsec());
426
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
430 foreach ($events as $key => $value) {
431 $this->waitForElementPresent("link=$value");
432 $this->assertTrue($this->isElementPresent("link=$value"));
433 }
434 for ($i = 1; $i <= 3; $i++) {
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 }
438
439 //Type the billing email in autocomplete.
440 $this->click('sort_name_navigation');
441 $this->type('css=input#sort_name_navigation', "{$firstName}.{$lastName}@example.com");
442 $this->typeKeys('css=input#sort_name_navigation', "{$firstName}.{$lastName}@example.com");
443
444 // Wait for result list.
445 $this->waitForElementPresent("css=div.ac_results-inner li");
446
447 // Visit contact summary page.
448 $this->click("css=div.ac_results-inner li");
449 $this->waitForPageToLoad($this->getTimeoutMsec());
450
451 //click on Contributions Tab
452 $this->click("xpath=//li[@id='tab_contribute']/a");
453 //check for the three contributions
454 foreach ($events as $key => $value) {
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 }
458
459 //Disable shopping cart style
460 $this->openCiviPage("admin/setting/preferences/event", "reset=1");
461 $this->click("enable_cart");
462 $this->click("_qf_Event_next-top");
463 }
464 }