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