CRM-15031 - Partial fixes for Event related webtests.
[civicrm-core.git] / tests / phpunit / WebTest / Event / AddEventTest.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_AddEventTest
31 */
32 class WebTest_Event_AddEventTest extends CiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
38 function testAddPaidEventNoTemplate() {
39 // Log in using webtestLogin() method
40 $this->webtestLogin();
41
42 // We need a payment processor
43 $processorName = "Webtest Dummy" . substr(sha1(rand()), 0, 7);
44 $this->webtestAddPaymentProcessor($processorName);
45
46 $this->openCiviPage("event/add", "reset=1&action=add");
47
48 $eventTitle = 'My Conference - ' . substr(sha1(rand()), 0, 7);
49 $eventDescription = "Here is a description for this conference.";
50 $this->_testAddEventInfo($eventTitle, $eventDescription);
51
52 $streetAddress = "100 Main Street";
53 $this->_testAddLocation($streetAddress);
54
55 $this->_testAddReminder($eventTitle);
56
57 $this->_testAddFees(FALSE, FALSE, $processorName);
58
59 // intro text for registration page
60 $registerIntro = "Fill in all the fields below and click Continue.";
61 $multipleRegistrations = TRUE;
62 $this->_testAddOnlineRegistration($registerIntro, $multipleRegistrations);
63
64 $eventInfoStrings = array($eventTitle, $eventDescription, $streetAddress);
65 $eventId = $this->_testVerifyEventInfo($eventTitle, $eventInfoStrings);
66
67 $registerStrings = array("225.00", "Member", "300.00", "Non-member", $registerIntro);
68 $registerUrl = $this->_testVerifyRegisterPage($registerStrings);
69
70 $numberRegistrations = 3;
71 $anonymous = TRUE;
72 $this->_testOnlineRegistration($registerUrl, $numberRegistrations, $anonymous);
73
74 // Now test making a copy of the event
75 $this->webtestLogin();
76 $this->openCiviPage("event/manage", "reset=1&action=copy&id=$eventId");
77 $this->_testVerifyEventInfo('Copy of ' . $eventTitle, $eventInfoStrings);
78 $this->_testVerifyRegisterPage($registerStrings);
79 }
80
81 function testAddPaidEventDiscount() {
82
83 // Log in using webtestLogin() method
84 $this->webtestLogin();
85
86 // We need a payment processor
87 $processorName = "Webtest Dummy" . substr(sha1(rand()), 0, 7);
88 $this->webtestAddPaymentProcessor($processorName);
89
90 $this->openCiviPage("event/add", "reset=1&action=add");
91
92 $eventTitle = 'My Conference - ' . substr(sha1(rand()), 0, 7);
93 $eventDescription = "Here is a description for this conference.";
94 $this->_testAddEventInfo($eventTitle, $eventDescription);
95
96 $streetAddress = "100 Main Street";
97 $this->_testAddLocation($streetAddress);
98
99 $this->_testAddReminder($eventTitle);
100
101 $this->_testAddFees(TRUE, FALSE, $processorName);
102
103 // intro text for registration page
104 $registerIntro = "Fill in all the fields below and click Continue.";
105 $multipleRegistrations = TRUE;
106 $this->_testAddOnlineRegistration($registerIntro, $multipleRegistrations);
107
108 $discountFees = array("225.00", "300.00");
109
110 $eventInfoStrings = array($eventTitle, $eventDescription, $streetAddress);
111 $this->_testVerifyEventInfo($eventTitle, $eventInfoStrings, $discountFees);
112
113 $registerStrings = array_push($discountFees, "Member", "Non-member", $registerIntro);
114 $registerUrl = $this->_testVerifyRegisterPage($registerStrings);
115
116 $numberRegistrations = 3;
117 $anonymous = TRUE;
118 $this->_testOnlineRegistration($registerUrl, $numberRegistrations, $anonymous);
119 }
120
121 function testDeletePriceSetDiscount() {
122
123 // Log in using webtestLogin() method
124 $this->webtestLogin();
125
126 // We need a payment processor
127 $processorName = "Webtest Dummy" . substr(sha1(rand()), 0, 7);
128 $this->webtestAddPaymentProcessor($processorName);
129
130 $this->openCiviPage("event/add", "reset=1&action=add");
131
132 $eventTitle = 'My Conference - ' . substr(sha1(rand()), 0, 7);
133 $eventDescription = "Here is a description for this conference.";
134 $this->_testAddEventInfo($eventTitle, $eventDescription);
135
136 $streetAddress = "100 Main Street";
137 $this->_testAddLocation($streetAddress);
138
139 //Add two discounts
140 $discount = $this->_testAddFees(TRUE, FALSE, $processorName, TRUE);
141
142 // intro text for registration page
143 $registerIntro = "Fill in all the fields below and click Continue.";
144 $multipleRegistrations = TRUE;
145 $this->_testAddOnlineRegistration($registerIntro, $multipleRegistrations);
146
147 $discountFees = array("225.00", "300.00");
148
149 $eventInfoStrings = array($eventTitle, $eventDescription, $streetAddress);
150 $id = $this->_testVerifyEventInfo($eventTitle, $eventInfoStrings, $discountFees);
151
152 $registerStrings = array_push($discountFees, "Member", "Non-member", $registerIntro);
153 $registerUrl = $this->_testVerifyRegisterPage($registerStrings);
154
155 //Add Price Set now
156 $this->openCiviPage("event/manage/fee", "reset=1&action=update&id=$id", "_qf_Fee_upload-bottom");
157 $this->click("xpath=//a[@id='quickconfig']");
158 $this->waitForElementPresent('popupContainer');
159 // Because it tends to cause problems, all uses of sleep() must be justified in comments
160 // Sleep should never be used for wait for anything to load from the server
161 // Justification for this instance: FIXME
162 sleep(3);
163 $this->click("xpath=//div[@class='ui-dialog-buttonset']/button[1]");
164 // Because it tends to cause problems, all uses of sleep() must be justified in comments
165 // Sleep should never be used for wait for anything to load from the server
166 // Justification for this instance: FIXME
167 sleep(3);
168
169 //Assert quick config change and discount deletion
170 $this->openCiviPage("admin/price", "reset=1");
171 $this->assertStringsPresent($discount);
172 }
173
174 function testAddDeleteEventDiscount() {
175
176 // Log in using webtestLogin() method
177 $this->webtestLogin();
178
179 // We need a payment processor
180 $processorName = "Webtest Dummy" . substr(sha1(rand()), 0, 7);
181 $this->webtestAddPaymentProcessor($processorName);
182
183 $this->openCiviPage("event/add", "reset=1&action=add");
184
185 $eventTitle = 'My Conference - ' . substr(sha1(rand()), 0, 7);
186 $eventDescription = "Here is a description for this conference.";
187 $this->_testAddEventInfo($eventTitle, $eventDescription);
188
189 $streetAddress = "100 Main Street";
190 $this->_testAddLocation($streetAddress);
191
192 //Add two discounts
193 $discount = $this->_testAddFees(TRUE, FALSE, $processorName, TRUE);
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 $discountFees = array("225.00", "300.00");
201
202 $eventInfoStrings = array($eventTitle, $eventDescription, $streetAddress);
203 $id = $this->_testVerifyEventInfo($eventTitle, $eventInfoStrings, $discountFees);
204
205 $registerStrings = array_push($discountFees, "Member", "Non-member", $registerIntro);
206 $registerUrl = $this->_testVerifyRegisterPage($registerStrings);
207 //Delete the discount
208 $this->_deleteDiscount($id, $eventTitle, $discount);
209 }
210
211 /**
212 * @param $id
213 * @param $eventTitle
214 * @param $discount
215 */
216 function _deleteDiscount($id, $eventTitle, $discount) {
217 $this->openCiviPage("event/manage/fee", "reset=1&action=update&id=$id", "_qf_Fee_upload-bottom");
218 $this->type("discount_name_2", "");
219 $this->click("xpath=//tr[@id='discount_2']/td[3]/span/a");
220 $this->click("xpath=//tr[@id='discount_2']/td[4]/span/a");
221 $this->type("discounted_value_1_2", "");
222 $this->type("discounted_value_2_2", "");
223 $this->click("_qf_Fee_upload-bottom");
224 $this->waitForPageToLoad();
225 //Assertions
226 $this->openCiviPage("admin/price", "reset=1");
227 $this->assertStringsPresent($discount[1]);
228 }
229
230 function testAddPaidEventWithTemplate() {
231
232 // Log in using webtestLogin() method
233 $this->webtestLogin();
234
235 // We need a payment processor
236 $processorName = "Webtest Dummy" . substr(sha1(rand()), 0, 7);
237 $this->webtestAddPaymentProcessor($processorName);
238
239 $this->openCiviPage("event/add", "reset=1&action=add");
240
241 $eventTitle = 'My Conference - ' . substr(sha1(rand()), 0, 7);
242 $eventDescription = "Here is a description for this conference.";
243 // Select paid online registration template.
244 $templateID = 6;
245 $eventTypeID = 1;
246 $this->_testAddEventInfoFromTemplate($eventTitle, $eventDescription, $templateID, $eventTypeID);
247
248 $streetAddress = "100 Main Street";
249 $this->_testAddLocation($streetAddress);
250
251 $this->_testAddFees(FALSE, FALSE, $processorName);
252
253 // intro text for registration page
254 $registerIntro = "Fill in all the fields below and click Continue.";
255 $this->_testAddOnlineRegistration($registerIntro);
256
257 // $eventInfoStrings = array( $eventTitle, $eventDescription, $streetAddress );
258 $eventInfoStrings = array($eventTitle, $streetAddress);
259 $this->_testVerifyEventInfo($eventTitle, $eventInfoStrings);
260
261 $registerStrings = array("225.00", "Member", "300.00", "Non-member", $registerIntro);
262 $this->_testVerifyRegisterPage($registerStrings);
263 }
264
265 function testAddFreeEventWithTemplate() {
266
267 // Log in using webtestLogin() method
268 $this->webtestLogin();
269
270 $this->openCiviPage("event/add", "reset=1&action=add");
271
272 $eventTitle = 'My Free Meeting - ' . substr(sha1(rand()), 0, 7);
273 $eventDescription = "Here is a description for this free meeting.";
274 // Select "Free Meeting with Online Registration" template (id = 5).
275 $templateID = 5;
276 $eventTypeID = 4;
277
278 $this->_testAddEventInfoFromTemplate($eventTitle, $eventDescription, $templateID, $eventTypeID);
279
280 $streetAddress = "100 Main Street";
281
282 $this->_testAddLocation($streetAddress);
283
284 // Go to Fees tab and check that Paid Event is false (No)
285 $this->click("link=Fees");
286 $this->waitForElementPresent("_qf_Fee_upload-bottom");
287 $this->verifyChecked("CIVICRM_QFID_0_is_monetary");
288
289 // intro text for registration page
290 $registerIntro = "Fill in all the fields below and click Continue.";
291 $this->_testAddOnlineRegistration($registerIntro);
292
293 // $eventInfoStrings = array( $eventTitle, $eventDescription, $streetAddress );
294 $eventInfoStrings = array($eventTitle, $streetAddress);
295 $this->_testVerifyEventInfo($eventTitle, $eventInfoStrings);
296
297 $registerStrings = array($registerIntro);
298 $this->_testVerifyRegisterPage($registerStrings);
299 // make sure paid_event div is NOT present since this is a free event
300 $this->verifyElementNotPresent("css=div.paid_event-section");
301 }
302
303 function testUnpaidPaid() {
304 // Log in using webtestLogin() method
305 $this->webtestLogin();
306
307 $this->openCiviPage("event/add", "reset=1&action=add");
308 $eventTitle = 'My Conference - ' . substr(sha1(rand()), 0, 7);
309 $eventDescription = "Here is a description for this conference.";
310 $this->_testAddEventInfo($eventTitle, $eventDescription);
311
312 //add fee section with pay later checked
313 $this->_testAddFees(FALSE, FALSE, NULL, FALSE, TRUE);
314
315 //make the event unpaid
316 $this->waitForElementPresent("_qf_Fee_upload-bottom");
317 $this->assertChecked('is_pay_later');
318 $this->click("CIVICRM_QFID_0_is_monetary");
319 $this->clickLink("_qf_Fee_upload-bottom", "_qf_Fee_upload-bottom");
320
321 //check if pay later option is disabled
322 $this->click('CIVICRM_QFID_1_is_monetary');
323 $this->waitForElementPresent('is_pay_later');
324 $this->assertNotChecked('is_pay_later');
325 }
326
327 function testAjaxCustomGroupLoad() {
328 $this->webtestLogin();
329
330 $triggerElement = array('name' => 'event_type_id', 'type' => 'select');
331 $customSets = array(
332 array('entity' => 'Event', 'subEntity' => 'Conference', 'triggerElement' => $triggerElement),
333 );
334
335 $pageUrl = array('url' => 'event/add', 'args' => "reset=1&action=add");
336 $this->customFieldSetLoadOnTheFlyCheck($customSets, $pageUrl);
337 }
338
339 /**
340 * @param $eventTitle
341 * @param $eventDescription
342 */
343 function _testAddEventInfo($eventTitle, $eventDescription) {
344 $this->waitForElementPresent("_qf_EventInfo_upload-bottom");
345
346 $this->select("event_type_id", "value=1");
347
348 // Attendee role s/b selected now.
349 $this->select("default_role_id", "value=1");
350
351 // Enter Event Title, Summary and Description
352 $this->type("title", $eventTitle);
353 $this->type("summary", "This is a great conference. Sign up now!");
354
355 // Type description in ckEditor (fieldname, text to type, editor)
356 $this->fillRichTextField("description", $eventDescription, 'CKEditor');
357
358 // Choose Start and End dates.
359 // Using helper webtestFillDate function.
360 $this->webtestFillDateTime("start_date", "+1 week");
361 $this->webtestFillDateTime("end_date", "+1 week 1 day 8 hours ");
362
363 $this->type("max_participants", "50");
364 $this->click("is_map");
365 $this->click("is_public");
366 $this->click("_qf_EventInfo_upload-bottom");
367 $this->waitForPageToLoad($this->getTimeoutMsec());
368 }
369
370 /**
371 * @param $eventTitle
372 * @param $eventDescription
373 * @param $templateID
374 * @param $eventTypeID
375 */
376 function _testAddEventInfoFromTemplate($eventTitle, $eventDescription, $templateID, $eventTypeID) {
377 $this->waitForElementPresent("_qf_EventInfo_upload-bottom");
378
379 // Select event template. Use option value, not label - since labels can be translated and test would fail
380 $this->select("template_id", "value={$templateID}");
381
382 // Wait for event type to be filled in (since page reloads)
383 $this->waitForPageToLoad($this->getTimeoutMsec());
384 $this->verifySelectedValue("event_type_id", $eventTypeID);
385
386 // Attendee role s/b selected now.
387 $this->verifySelectedValue("default_role_id", "1");
388
389 // Enter Event Title, Summary and Description
390 $this->type("title", $eventTitle);
391
392 $this->type("summary", "This is a great conference. Sign up now!");
393
394 // Type description in ckEditor (fieldname, text to type, editor)
395 $this->fillRichTextField("description", $eventDescription, 'CKEditor');
396
397 // Choose Start and End dates.
398 // Using helper webtestFillDate function.
399 $this->webtestFillDateTime("start_date", "+1 week");
400 $this->webtestFillDateTime("end_date", "+1 week 1 day 8 hours ");
401
402 $this->type("max_participants", "50");
403 $this->click("is_map");
404 $this->click("_qf_EventInfo_upload-bottom");
405
406 }
407
408 /**
409 * @param $streetAddress
410 */
411 function _testAddLocation($streetAddress) {
412 // Wait for Location tab form to load
413 $this->waitForPageToLoad($this->getTimeoutMsec());
414 $this->waitForElementPresent("_qf_Location_upload-bottom");
415
416 // Fill in address fields
417 $streetAddress = "100 Main Street";
418 $this->type("address_1_street_address", $streetAddress);
419 $this->type("address_1_city", "San Francisco");
420 $this->type("address_1_postal_code", "94117");
421 $this->select("address_1_state_province_id", "value=1004");
422 $this->type("email_1_email", "info@civicrm.org");
423
424 $this->click("_qf_Location_upload-bottom");
425
426 // Wait for "saved" status msg
427 $this->waitForText('crm-notification-container', "'Event Location' information has been saved.");
428 }
429
430 /**
431 * @param bool $discount
432 * @param bool $priceSet
433 * @param string $processorName
434 * @param bool $double
435 * @param bool $payLater
436 *
437 * @return array
438 */
439 function _testAddFees($discount = FALSE, $priceSet = FALSE, $processorName = "PP Pro", $double = FALSE, $payLater = FALSE) {
440 $discount1 = "Early-bird" . substr(sha1(rand()), 0, 7);
441 $discount2 = "";
442 // Go to Fees tab
443 $this->click("link=Fees");
444 $this->waitForElementPresent("_qf_Fee_upload-bottom");
445 $this->click("CIVICRM_QFID_1_is_monetary");
446
447 if ($payLater) {
448 $this->click('is_pay_later');
449 $this->fillRichTextField('pay_later_receipt', 'testing later instructions');
450 }
451 else {
452 $this->uncheck('is_pay_later');
453 }
454
455 if ($processorName) {
456 $this->click("xpath=//tr[@class='crm-event-manage-fee-form-block-payment_processor']/td[2]/label[text()='$processorName']");
457 }
458 $this->select("financial_type_id", "value=4");
459 if ($priceSet) {
460 // get one - TBD
461 }
462 else {
463 $this->type("label_1", "Member");
464 $this->type("value_1", "225.00");
465 $this->type("label_2", "Non-member");
466 $this->type("value_2", "300.00");
467 $this->click("CIVICRM_QFID_1_6");
468 }
469
470 if ($discount) {
471 // enter early bird discount fees
472 $this->click("is_discount");
473 $this->waitForElementPresent("discount_name_1");
474 $this->type("discount_name_1", $discount1);
475 $this->webtestFillDate("discount_start_date_1", "-3 week");
476 $this->webtestFillDate("discount_end_date_1", "-2 week");
477 $this->clickLink("_qf_Fee_submit", "discounted_value_1_1");
478
479 $this->type("discounted_value_1_1", "225.00");
480 $this->type("discounted_value_2_1", "300.00");
481
482 if ($double) {
483 $discount2 = "Early-bird" . substr(sha1(rand()), 0, 7);
484 // enter early bird discount fees
485 $this->click("link=another discount set");
486 $this->waitForElementPresent("discount_name_2");
487 $this->type("discount_name_2", $discount2);
488 $this->webtestFillDate("discount_start_date_2", "-1 week");
489 $this->webtestFillDate("discount_end_date_2", "+1 week");
490 $this->clickLink("_qf_Fee_submit", "discounted_value_2_1");
491 $this->type("discounted_value_1_2", "225.00");
492 $this->type("discounted_value_2_2", "300.00");
493 }
494 $this->click("xpath=//fieldset[@id='discount']/fieldset/table/tbody/tr[2]/td[3]/input");
495 }
496 $this->click("_qf_Fee_upload-bottom");
497
498 // Wait for "saved" status msg
499 $this->waitForText('crm-notification-container', "'Fees' information has been saved");
500 return array($discount1, $discount2);
501 }
502
503 /**
504 * @param $registerIntro
505 * @param bool $multipleRegistrations
506 */
507 function _testAddOnlineRegistration($registerIntro, $multipleRegistrations = FALSE) {
508 // Go to Online Registration tab
509 $this->click("link=Online Registration");
510 $this->waitForElementPresent("_qf_Registration_upload-bottom");
511
512 $this->click("is_online_registration");
513 $this->assertChecked("is_online_registration");
514 if ($multipleRegistrations) {
515 $this->click("is_multiple_registrations");
516 $this->assertChecked("is_multiple_registrations");
517 }
518
519 $this->fillRichTextField("intro_text", $registerIntro, 'CKEditor', TRUE);
520
521 // enable confirmation email
522 $this->click("CIVICRM_QFID_1_is_email_confirm");
523 $this->type("confirm_from_name", "Jane Doe");
524
525 $this->type("confirm_from_email", "jane.doe@example.org");
526
527 $this->click("_qf_Registration_upload-bottom");
528 $this->waitForText('crm-notification-container', "'Online Registration' information has been saved.");
529 }
530
531 /**
532 * @param $eventTitle
533 * @param $eventInfoStrings
534 * @param null $eventFees
535 *
536 * @return null
537 */
538 function _testVerifyEventInfo($eventTitle, $eventInfoStrings, $eventFees = NULL) {
539 // verify event input on info page
540 // start at Manage Events listing
541 $this->openCiviPage("event/manage", "reset=1");
542 $this->click("link=$eventTitle");
543
544 // Look for Register button
545 $this->waitForElementPresent("link=Register Now");
546
547 // Check for correct event info strings
548 $this->assertStringsPresent($eventInfoStrings);
549
550 // Optionally verify event fees (especially for discounts)
551 if ($eventFees) {
552 $this->assertStringsPresent($eventFees);
553
554 }
555 return $this->urlArg('id');
556 }
557
558 /**
559 * @param $registerStrings
560 *
561 * @return string
562 */
563 function _testVerifyRegisterPage($registerStrings) {
564 // Go to Register page and check for intro text and fee levels
565 $this->click("link=Register Now");
566 $this->waitForElementPresent("_qf_Register_upload-bottom");
567 $this->assertStringsPresent($registerStrings);
568 return $this->getLocation();
569 }
570
571 /**
572 * @param $registerUrl
573 * @param int $numberRegistrations
574 * @param bool $anonymous
575 * @param bool $isPayLater
576 * @param array $participantEmailInfo
577 * @param null $paymentProcessor
578 *
579 * @return array
580 */
581 function _testOnlineRegistration($registerUrl, $numberRegistrations = 1, $anonymous = TRUE, $isPayLater = FALSE, $participantEmailInfo = array(), $paymentProcessor = NULL) {
582 $infoPassed = FALSE;
583 if (!empty($participantEmailInfo)) {
584 $infoPassed = TRUE;
585 }
586 if ($anonymous) {
587 $this->webtestLogout();
588 }
589 $primaryParticipantInfo = array();
590 $this->open($registerUrl);
591 $this->waitForPageToLoad($this->getTimeoutMsec());
592
593 $this->select("additional_participants", "value=" . $numberRegistrations);
594
595 if ($infoPassed) {
596 $primaryParticipantInfo['first_name'] = $participantEmailInfo[0]['first_name'];
597 $primaryParticipantInfo['last_name'] = $participantEmailInfo[0]['last_name'];
598 $primaryParticipantInfo['email'] = $participantEmailInfo[0]['email'];
599 }
600 else {
601 $primaryParticipantInfo['first_name'] = "Jane";
602 $primaryParticipantInfo['last_name'] = "Smith" . substr(sha1(rand()), 0, 7);
603 $primaryParticipantInfo['email'] = "smith" . substr(sha1(rand()), 0, 7) . "@example.org";
604 }
605
606 $this->type("first_name", $primaryParticipantInfo['first_name']);
607 $this->type("last_name", $primaryParticipantInfo['last_name']);
608 $this->type("email-Primary", $primaryParticipantInfo['email']);
609
610 if (!$isPayLater) {
611 if ($paymentProcessor) {
612 $paymentProcessorEle = $this->getAttribute("xpath=//form[@id='Register']//label[contains(text(), '{$paymentProcessor}')]/@for");
613 $this->click($paymentProcessorEle);
614 }
615 $this->select("credit_card_type", "value=Visa");
616 $this->type("credit_card_number", "4111111111111111");
617 $this->type("cvv2", "000");
618 $this->select("credit_card_exp_date[M]", "value=1");
619 $this->select("credit_card_exp_date[Y]", "value=2020");
620 $this->type("billing_first_name", $primaryParticipantInfo['first_name']);
621 $this->type("billing_last_name", $primaryParticipantInfo['last_name']);
622 $this->type("billing_street_address-5", "15 Main St.");
623 $this->type(" billing_city-5", "San Jose");
624 $this->select("billing_country_id-5", "value=1228");
625 $this->select("billing_state_province_id-5", "value=1004");
626 $this->type("billing_postal_code-5", "94129");
627 }
628
629 $this->click("_qf_Register_upload-bottom");
630
631 if ($numberRegistrations > 1) {
632 for ($i = 1; $i <= $numberRegistrations; $i++) {
633 $this->waitForPageToLoad($this->getTimeoutMsec());
634 // Look for Skip button
635 $this->waitForElementPresent("_qf_Participant_{$i}_next_skip-Array");
636
637 if ($infoPassed) {
638 $this->type("first_name", $participantEmailInfo[$i]['first_name']);
639 $this->type("last_name", $participantEmailInfo[$i]['last_name']);
640 $this->type("email-Primary", $participantEmailInfo[$i]['email']);
641 }
642 else {
643 $this->type("first_name", "Jane Add $i");
644 $this->type("last_name", "Smith" . substr(sha1(rand()), 0, 7));
645 $this->type("email-Primary", "smith" . substr(sha1(rand()), 0, 7) . "@example.org");
646 }
647
648 $this->click("_qf_Participant_{$i}_next");
649 }
650 }
651
652 $this->waitForPageToLoad($this->getTimeoutMsec());
653 $this->waitForElementPresent("_qf_Confirm_next-bottom");
654 $confirmStrings = array("Event Fee(s)");
655 if (!$isPayLater) {
656 $confirmStrings += array("Billing Name and Address", "Credit Card Information");
657 }
658 $this->assertStringsPresent($confirmStrings);
659 $this->click("_qf_Confirm_next-bottom");
660 $this->waitForPageToLoad($this->getTimeoutMsec());
661 $thankStrings = array("Thank You for Registering", "Event Total");
662 if (!$isPayLater) {
663 $thankStrings = array("Transaction Date");
664 }
665 else {
666 $thankStrings += array("testing later instructions");
667 }
668 $this->assertStringsPresent($thankStrings);
669 return $primaryParticipantInfo;
670 }
671
672 /**
673 * @param $eventTitle
674 */
675 function _testAddReminder($eventTitle) {
676 // Go to Schedule Reminders tab
677 $this->click('css=li#tab_reminder a');
678 $this->waitForElementPresent("newScheduleReminder");
679 $this->click("newScheduleReminder");
680 $this->waitForElementPresent("_qf_ScheduleReminders_upload-bottom");
681 $this->type("title", "Event Reminder for " . $eventTitle);
682 $this->select('entity', 'label=Registered');
683
684 $this->select('start_action_offset', 'label=1');
685 $this->select('start_action_condition', 'label=after');
686 $this->click('is_repeat');
687 $this->select('repetition_frequency_interval', 'label=2');
688 $this->select('end_date', 'label=Event End Date');
689 $this->click('recipient');
690 $this->select('recipient', 'label=Participant Role');
691 // $this->select( 'recipient_listing', 'value=1' );
692
693 // Fill Subject
694 $subject = 'subject' . substr(sha1(rand()), 0, 4);
695 $this->type('subject', $subject);
696 $this->fillRichTextField("html_message", "This is the test HTML version here!!!", 'CKEditor');
697
698 $this->type("text_message", "This is the test text version here!!!");
699 //click on save
700 $this->click('_qf_ScheduleReminders_upload-bottom');
701 $this->waitForElementPresent("link=Add Reminder");
702
703 $this->waitForElementPresent("link=Edit");
704
705 $verifyText = array(
706 1 => 'Event Reminder for ' . $eventTitle,
707 3 => '1 hour after Event Start Date',
708 4 => 'Registered',
709 5 => 'Yes',
710 // Not sure why it's not finding the 6th cell? dgg.
711 // 6 => 'Yes',
712 );
713
714 //verify the fields for Event Reminder selector
715 foreach ($verifyText as $key => $value) {
716 $this->verifyText("xpath=//div['option11_wrapper']/table/tbody/tr/td[$key]", $value);
717 }
718 }
719
720 function testEventAddMultipleParticipant() {
721 // Log in using webtestLogin() method
722 $this->webtestLogin();
723 $this->openCiviPage("event/add", "reset=1&action=add");
724
725 $eventTitle = 'My Conference - ' . substr(sha1(rand()), 0, 7);
726 $eventDescription = "Here is a description for this conference.";
727 $this->_testAddEventInfo($eventTitle, $eventDescription);
728 $streetAddress = "100 Main Street";
729 $this->_testAddLocation($streetAddress);
730
731 $this->_testAddFees(FALSE, FALSE, "Test Processor", FALSE, TRUE);
732 $registerIntro = "Fill in all the fields below and click Continue.";
733 $multipleRegistrations = TRUE;
734 $this->_testAddOnlineRegistration($registerIntro, $multipleRegistrations);
735 $eventInfoStrings = array($eventTitle, $eventDescription, $streetAddress);
736 $eventId = $this->_testVerifyEventInfo($eventTitle, $eventInfoStrings);
737
738 $registerStrings = array("225.00", "Member", "300.00", "Non-member", $registerIntro);
739 $registerUrl = $this->_testVerifyRegisterPage($registerStrings);
740 $numberRegistrations = 3;
741 $anonymous = TRUE;
742
743 // CRM-12615 add additional participants and check email, amount
744 $primaryParticipant = array(
745 'email' => "smith" . substr(sha1(rand()), 0, 7) . "@example.org",
746 'first_name' => "Kate",
747 'last_name' => "Simth" . substr(sha1(rand()), 0, 7),
748 );
749 $secParticipant = array(
750 'email' => "smith" . substr(sha1(rand()), 0, 7) . "@example.org",
751 'first_name' => "Kate Add 1",
752 'last_name' => "Simth" . substr(sha1(rand()), 0, 7),
753 );
754 $thirdParticipant = array(
755 'email' => "smith" . substr(sha1(rand()), 0, 7) . "@example.org",
756 'first_name' => "Kate Add 2",
757 'last_name' => "Simth" . substr(sha1(rand()), 0, 7),
758 );
759
760 $participantEmails = array($primaryParticipant, $secParticipant, $thirdParticipant);
761 $addtlPart = array($secParticipant, $thirdParticipant);
762 $primaryParticipantInfo =
763 $this->_testOnlineRegistration($registerUrl, 2, $anonymous, FALSE, $participantEmails, "Test Processor");
764 $primaryDisplayName = "{$primaryParticipantInfo['first_name']} {$primaryParticipantInfo['last_name']}";
765 $this->webtestLogin();
766 $this->openCiviPage("event/search?reset=1", "reset=1");
767 $this->type('event_name', $eventTitle);
768 $this->click("event_name");
769 $this->waitForElementPresent("css=div.ac_results-inner li");
770 $this->click("css=div.ac_results-inner li");
771 $this->clickLink('_qf_Search_refresh');
772 $this->verifyText("xpath=//div[@id='participantSearch']/table/tbody//tr/td[3]/a[contains(text(),
773 '{$secParticipant['last_name']}, {$secParticipant['first_name']}')]/../../td[6]", preg_quote('225.00'));
774 $this->verifyText("xpath=//div[@id='participantSearch']/table/tbody//tr/td[3]/a[contains(text(),
775 '{$thirdParticipant['last_name']}, {$thirdParticipant['first_name']}')]/../../td[6]", preg_quote('225.00'));
776
777 //CRM-12618 check edit screen of additional participant and ensuring record_contribution not present
778 foreach ($addtlPart as $value) {
779 $this->clickLink("xpath=//div[@id='participantSearch']/table/tbody//tr/td[3]/a[contains(text(),
780 '{$value['last_name']}, {$value['first_name']}')]/../../td[11]/span/a[2][contains(text(), 'Edit')]",
781 '_qf_Participant_upload-bottom');
782 $this->assertTrue(
783 $this->isElementPresent("xpath=//tr[@class='crm-participant-form-block-registered-by']/td[2]/a[contains(text(),
784 '$primaryDisplayName')]"), 'Registered By info is wrong on additional participant edit form');
785 $this->assertElementContainsText("xpath=//form[@id='Participant']/h3", 'Edit Event Registration');
786 $this->assertTrue(
787 $this->isElementPresent(
788 "xpath=//table/tbody/tr[@class='crm-participant-form-block-displayName']/td[2][contains(text(),
789 '{$value['first_name']} {$value['last_name']}')]"),
790 'Wrong Participant edit form'
791 );
792 $this->assertFalse($this->isElementPresent('record_contribution'),
793 'Record Payment checkbox showed up wrongly for additional participant edit screen');
794 $this->clickLink("_qf_Participant_cancel-top");
795 }
796
797 //unselect the payment processor configured
798 $this->openCiviPage("event/manage/fee", "reset=1&action=update&id={$eventId}", '_qf_Fee_upload-bottom');
799 $this->click("xpath=//tr[@class='crm-event-manage-fee-form-block-payment_processor']/td[2]/label[text()='Test Processor']");
800 $this->clickLink("_qf_Fee_upload-bottom");
801
802 // add participant and 3 additional participant and change status of participant from edit participant
803 $this->_testOnlineRegistration($registerUrl, $numberRegistrations, $anonymous, TRUE);
804 $this->webtestLogin();
805
806 $this->openCiviPage("event/search?reset=1", "reset=1");
807 $this->type('event_name', $eventTitle);
808 $this->click("event_name");
809 $this->waitForElementPresent("css=div.ac_results-inner li");
810 $this->click("css=div.ac_results-inner li");
811 $this->click("xpath=//td[@class='crm-event-form-block-participant_status']/div[@class='listing-box']//div/label[text()='Pending from pay later']");
812 $this->click('_qf_Search_refresh');
813 $this->waitForPageToLoad($this->getTimeoutMsec());
814 $this->click("xpath=//div[@id='participantSearch']/table/tbody//tr/td[11]/span/a[text()='Edit']");
815 $this->waitForPageToLoad($this->getTimeoutMsec());
816 $this->select('status_id', 'label=Registered');
817 $this->click('record_contribution');
818 $this->select('contribution_status_id', 'label=Completed');
819 $pID = $this->urlArg('id');
820 $contributionID = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $pID, 'contribution_id', 'participant_id');
821 $this->click('_qf_Participant_upload-top');
822 $this->waitForPageToLoad($this->getTimeoutMsec());
823 $this->verifyFinancialRecords($contributionID);
824
825 // add participant and 3 additional participant and change status of participant from edit contribution
826 $this->_testOnlineRegistration($registerUrl, $numberRegistrations, $anonymous, TRUE);
827 $this->webtestLogin();
828
829 $this->openCiviPage("event/search?reset=1", "reset=1");
830 $this->type('event_name', $eventTitle);
831 $this->click("event_name");
832 $this->waitForElementPresent("css=div.ac_results-inner li");
833 $this->click("css=div.ac_results-inner li");
834 $this->click("xpath=//td[@class='crm-event-form-block-participant_status']/div[@class='listing-box']//div/label[text()='Pending from pay later']");
835 $this->click('_qf_Search_refresh');
836 $this->waitForPageToLoad($this->getTimeoutMsec());
837 $this->click("xpath=//div[@id='participantSearch']/table/tbody//tr/td[11]/span/a[text()='View']");
838 $this->waitForPageToLoad($this->getTimeoutMsec());
839 $pID = $this->urlArg('id');
840 $contributionID = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $pID, 'contribution_id', 'participant_id');
841 $this->click("xpath=//tr[@id='rowid$contributionID']/td[8]/span//a[text()='Edit']");
842 $this->waitForPageToLoad($this->getTimeoutMsec());
843 $this->select('contribution_status_id', 'label=Completed');
844 $this->click('_qf_Contribution_upload-bottom');
845 $this->waitForPageToLoad($this->getTimeoutMsec());
846 $this->verifyFinancialRecords($contributionID);
847 }
848
849 /**
850 * @param $contributionID
851 */
852 function verifyFinancialRecords($contributionID) {
853 // check count for civicrm_contribution and civicrm_financial_item in civicrm_entity_financial_trxn
854 $query = "SELECT COUNT(DISTINCT(c1.id)) civicrm_contribution, COUNT(c2.id) civicrm_financial_item FROM civicrm_entity_financial_trxn c1
855 LEFT JOIN civicrm_entity_financial_trxn c2 ON c1.financial_trxn_id = c2.financial_trxn_id AND c2.entity_table ='civicrm_financial_item'
856 LEFT JOIN civicrm_financial_item cfi ON cfi.id = c2.entity_id
857 WHERE c1.entity_table = 'civicrm_contribution' AND c1.entity_id = %1 AND cfi.status_id = 1";
858 $params = array(1 => array($contributionID, 'Integer'));
859 $dao = CRM_Core_DAO::executeQuery($query, $params);
860 $dao->fetch();
861 $this->assertEquals('2', $dao->civicrm_contribution, 'civicrm_financial_trxn count does not match');
862 $this->assertEquals('8', $dao->civicrm_financial_item, 'civicrm_financial_item count does not match');
863 $query = "SELECT COUNT(cft.id) civicrm_financial_trxn FROM civicrm_entity_financial_trxn ceft
864 INNER JOIN civicrm_financial_trxn cft ON ceft.financial_trxn_id = cft.id
865 WHERE ceft.entity_id = %1 AND ceft.entity_table = 'civicrm_contribution'";
866 $dao = CRM_Core_DAO::executeQuery($query, $params);
867 $dao->fetch();
868 $this->assertEquals('2', $dao->civicrm_financial_trxn, 'civicrm_financial_trxn count does not match');
869 }
870
871 function testEventApprovalRegistration() {
872 $this->webtestLogin();
873
874 //Participant Status
875 $this->openCiviPage("admin/participant_status", "reset=1&action=browse");
876 $this->_testEnableParticipantStatuses('Awaiting approval');
877 $this->isElementPresent("xpath=//td[@class='crm-particpant-label'][contains(text(), 'Awaiting approval')]/../td[9]/span/a[2][text()='Disable']");
878 $this->_testEnableParticipantStatuses('Pending from approval');
879 $this->isElementPresent("xpath=//td[@class='crm-particpant-label'][contains(text(), 'Pending from approval')]/../td[9]/span/a[2][text()='Disable']");
880 $this->_testEnableParticipantStatuses('Rejected');
881 $this->isElementPresent("xpath=//td[@class='crm-particpant-label'][contains(text(), 'Rejected')]/../td[9]/span/a[2][text()='Disable']");
882
883 //Create New Event
884
885 $this->openCiviPage('event/add', 'reset=1&action=add', '_qf_EventInfo_upload-bottom');
886 $eventTitle = 'My Conference - ' . substr(sha1(rand()), 0, 7);
887 $email = 'Smith' . substr(sha1(rand()), 0, 7) . '@example.com';
888 $eventDescription = 'Here is a description for this conference.';
889 $this->select('event_type_id', 'value=1');
890
891 // Attendee role s/b selected now.
892 $this->select('default_role_id', 'value=1');
893 // Enter Event Title, Summary and Description
894 $this->type('title', $eventTitle);
895 $this->type('summary', 'This is a great conference. Sign up now!');
896
897 // Type description in ckEditor (fieldname, text to type, editor)
898 $this->fillRichTextField('description', $eventDescription );
899 $this->type('max_participants', '50');
900 $this->click('is_map');
901 $this->click('_qf_EventInfo_upload-bottom');
902
903 // Wait for Location tab form to load
904 $this->waitForPageToLoad($this->getTimeoutMsec());
905
906 // Go to Fees tab
907 $this->click('link=Fees');
908 $id = $this->urlArg('id');
909 $this->waitForElementPresent('_qf_Fee_upload-bottom');
910 $this->click('CIVICRM_QFID_1_is_monetary');
911 $processorName = 'Test Processor';
912 $this->click("xpath=//tr[@class='crm-event-manage-fee-form-block-payment_processor']/td[2]/label[text()='$processorName']");
913 $this->select('financial_type_id','label=Event Fee');
914 $this->type("label[1]",'Junior Stars');
915 $this->type("value[1]",'500.00');
916 $this->type("label[2]",'Super Stars');
917 $this->type("value[2]",'1000.00');
918 $this->check('default');
919 $this->click('_qf_Fee_upload-bottom');
920 $this->waitForPageToLoad($this->getTimeoutMsec());
921
922 // intro text for registration page
923 $registerIntro = 'Fill in all the fields below and click Continue.';
924
925 // Go to Online Registration tab
926 $this->click('link=Online Registration');
927 $this->waitForElementPresent('_qf_Registration_upload-bottom');
928 $this->click('is_online_registration');
929 $this->assertChecked('is_online_registration');
930
931 //Requires Approvel
932 $this->click('requires_approval');
933 $this->assertChecked('requires_approval');
934 $this->click('_qf_Registration_upload-bottom');
935 $this->waitForText('crm-notification-container', "'Online Registration' information has been saved.");
936
937 // verify event input on info page
938 // start at Manage Events listing
939 $this->openCiviPage('event/manage', 'reset=1');
940 $this->click("link=$eventTitle");
941 $this->waitForPageToLoad($this->getTimeoutMsec());
942 $firstName = substr(sha1(rand()), 0, 7);
943 $this->webtestAddContact($firstName, 'Anderson', TRUE);
944 $contactName = "Anderson, $firstName";
945 $displayName = "$firstName Anderson";
946 $this->openCiviPage("event/register", "reset=1&id=$id", '_qf_Register_upload-bottom');
947 $this->type('first_name',$firstName);
948
949 //fill in last name
950 $lastName = 'Recuron'.substr(sha1(rand()), 0, 7);
951 $this->type('last_name', $contactName);
952 $email = $firstName . '@example.com';
953 $this->type('email-Primary', $email);
954 $this->click('_qf_Register_upload');
955 $this->waitForElementPresent("_qf_Confirm_next");
956 $this->click('_qf_Confirm_next');
957 $this->waitForPageToLoad($this->getTimeoutMsec());
958 $this->waitForElementPresent("xpath=//div[@class='section']");
959 $this->assertTextPresent("Thank You for Registering");
960
961 }
962
963 /**
964 * @param $status
965 */
966 function _testEnableParticipantStatuses($status) {
967 // enable participant status
968 if ($this->isElementPresent("xpath=//td[@class='crm-particpant-label'][contains(text(), '{$status}')]/../td[9]/span/a[2][text()='Enable']")){
969 $this->click("xpath=//td[@class='crm-particpant-label'][contains(text(), '{$status}')]/../td[9]/span/a[2][text()='Enable']");
970 $this->waitForElementPresent("xpath=//div[@class='ui-dialog-buttonset']");
971 $this->click("xpath=//div[@class='ui-dialog-buttonset']/button[2]");
972 }
973 }
974 }