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