Merge pull request #9973 from lcdservices/CRM-19469
[civicrm-core.git] / tests / phpunit / WebTest / Event / AddEventTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
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 public function testAddPaidEventNoTemplate() {
39 // Log in using webtestLogin() method
40 $this->webtestLogin();
41
42 // Use default payment processor
43 $processorName = 'Test Processor';
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 public function testAddPaidEventDiscount() {
82
83 // Log in using webtestLogin() method
84 $this->webtestLogin();
85
86 // Use default payment processor
87 $processorName = 'Test Processor';
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 public function testDeletePriceSetDiscount() {
122
123 // Log in using webtestLogin() method
124 $this->webtestLogin();
125
126 // Use default payment processor
127 $processorName = 'Test Processor';
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("xpath=//div[@class='ui-dialog-buttonset']");
159 $this->click("xpath=//div[@class='ui-dialog-buttonset']//button/span[text()='Continue']");
160
161 //Assert quick config change and discount deletion
162 $this->openCiviPage("admin/price", "reset=1");
163 foreach ($discount as $key => $val) {
164 $this->waitForTextPresent($val);
165 }
166 }
167
168 public function testAddDeleteEventDiscount() {
169
170 // Log in using webtestLogin() method
171 $this->webtestLogin();
172
173 // Use default payment processor
174 $processorName = 'Test Processor';
175 $this->webtestAddPaymentProcessor($processorName);
176
177 $this->openCiviPage("event/add", "reset=1&action=add");
178
179 $eventTitle = 'My Conference - ' . substr(sha1(rand()), 0, 7);
180 $eventDescription = "Here is a description for this conference.";
181 $this->_testAddEventInfo($eventTitle, $eventDescription);
182
183 $streetAddress = "100 Main Street";
184 $this->_testAddLocation($streetAddress);
185
186 //Add two discounts
187 $discount = $this->_testAddFees(TRUE, FALSE, $processorName, TRUE);
188
189 // intro text for registration page
190 $registerIntro = "Fill in all the fields below and click Continue.";
191 $multipleRegistrations = TRUE;
192 $this->_testAddOnlineRegistration($registerIntro, $multipleRegistrations);
193
194 $discountFees = array("225.00", "300.00");
195
196 $eventInfoStrings = array($eventTitle, $eventDescription, $streetAddress);
197 $id = $this->_testVerifyEventInfo($eventTitle, $eventInfoStrings, $discountFees);
198
199 $registerStrings = array_push($discountFees, "Member", "Non-member", $registerIntro);
200 $registerUrl = $this->_testVerifyRegisterPage($registerStrings);
201 //Delete the discount
202 $this->_deleteDiscount($id, $eventTitle, $discount);
203 }
204
205 /**
206 * @param int $id
207 * @param $eventTitle
208 * @param $discount
209 */
210 public function _deleteDiscount($id, $eventTitle, $discount) {
211 $this->openCiviPage("event/manage/fee", "reset=1&action=update&id=$id", "_qf_Fee_upload-bottom");
212 $this->type("discount_name_2", "");
213 $this->click("xpath=//tr[@id='discount_2']/td[3]/a");
214 $this->click("xpath=//tr[@id='discount_2']/td[4]/a");
215 $this->type("discounted_value_1_2", "");
216 $this->type("discounted_value_2_2", "");
217 $this->click("_qf_Fee_upload-bottom");
218 $this->waitForText('crm-notification-container', "'Fees' information has been saved.");
219 //Assertions
220 $this->openCiviPage("admin/price", "reset=1");
221 $this->assertStringsPresent($discount[1]);
222 }
223
224 public function testAddPaidEventWithTemplate() {
225
226 // Log in using webtestLogin() method
227 $this->webtestLogin();
228
229 // Use default payment processor
230 $processorName = 'Test Processor';
231 $this->webtestAddPaymentProcessor($processorName);
232
233 $this->openCiviPage("event/add", "reset=1&action=add");
234
235 $eventTitle = 'My Conference - ' . substr(sha1(rand()), 0, 7);
236 $eventDescription = "Here is a description for this conference.";
237 // Select paid online registration template.
238 $templateID = 6;
239 $eventTypeID = 1;
240 $this->_testAddEventInfoFromTemplate($eventTitle, $eventDescription, $templateID, $eventTypeID);
241
242 $streetAddress = "100 Main Street";
243 $this->_testAddLocation($streetAddress);
244
245 $this->_testAddFees(FALSE, FALSE, $processorName);
246
247 // intro text for registration page
248 $registerIntro = "Fill in all the fields below and click Continue.";
249 $this->_testAddOnlineRegistration($registerIntro);
250
251 // $eventInfoStrings = array( $eventTitle, $eventDescription, $streetAddress );
252 $eventInfoStrings = array($eventTitle, $streetAddress);
253 $this->_testVerifyEventInfo($eventTitle, $eventInfoStrings);
254
255 $registerStrings = array("225.00", "Member", "300.00", "Non-member", $registerIntro);
256 $this->_testVerifyRegisterPage($registerStrings);
257 }
258
259 public function testAddFreeEventWithTemplate() {
260
261 // Log in using webtestLogin() method
262 $this->webtestLogin();
263
264 $this->openCiviPage("event/add", "reset=1&action=add");
265
266 $eventTitle = 'My Free Meeting - ' . substr(sha1(rand()), 0, 7);
267 $eventDescription = "Here is a description for this free meeting.";
268 // Select "Free Meeting with Online Registration" template (id = 5).
269 $templateID = 5;
270 $eventTypeID = 4;
271
272 $this->_testAddEventInfoFromTemplate($eventTitle, $eventDescription, $templateID, $eventTypeID);
273
274 $streetAddress = "100 Main Street";
275
276 $this->_testAddLocation($streetAddress);
277
278 // Go to Fees tab and check that Paid Event is false (No)
279 $this->click("link=Fees");
280 $this->waitForElementPresent("_qf_Fee_upload-bottom");
281 $this->verifyChecked("CIVICRM_QFID_0_is_monetary");
282
283 // intro text for registration page
284 $registerIntro = "Fill in all the fields below and click Continue.";
285 $this->_testAddOnlineRegistration($registerIntro);
286
287 // $eventInfoStrings = array( $eventTitle, $eventDescription, $streetAddress );
288 $eventInfoStrings = array($eventTitle, $streetAddress);
289 $this->_testVerifyEventInfo($eventTitle, $eventInfoStrings);
290
291 $registerStrings = array($registerIntro);
292 $this->_testVerifyRegisterPage($registerStrings);
293 // make sure paid_event div is NOT present since this is a free event
294 $this->verifyElementNotPresent("css=div.paid_event-section");
295 }
296
297 public function testUnpaidPaid() {
298 $this->markTestSkipped('Skipping for now as it works fine locally.');
299 // Log in using webtestLogin() method
300 $this->webtestLogin();
301
302 $this->openCiviPage("event/add", "reset=1&action=add");
303 $eventTitle = 'My Conference - ' . substr(sha1(rand()), 0, 7);
304 $eventDescription = "Here is a description for this conference.";
305 $this->_testAddEventInfo($eventTitle, $eventDescription);
306
307 //add fee section with pay later checked
308 $this->_testAddFees(FALSE, FALSE, NULL, FALSE, TRUE);
309
310 //make the event unpaid
311 $this->waitForElementPresent("_qf_Fee_upload-bottom");
312 $this->assertChecked('is_pay_later');
313 $this->click("CIVICRM_QFID_0_is_monetary");
314
315 $this->click("_qf_Fee_upload-bottom");
316 $this->waitForText('crm-notification-container', "'Fees' information has been saved.");
317 $this->waitForAjaxContent();
318
319 //check if pay later option is disabled
320 $this->click('CIVICRM_QFID_1_is_monetary');
321 $this->waitForPageToLoad($this->getTimeoutMsec());
322 $this->waitForElementPresent('is_pay_later');
323 $this->assertNotChecked('is_pay_later');
324 }
325
326 public function testAjaxCustomGroupLoad() {
327 $this->webtestLogin();
328
329 $triggerElement = array('name' => 'event_type_id', 'type' => 'select');
330 $customSets = array(
331 array('entity' => 'Event', 'subEntity' => 'Conference', 'triggerElement' => $triggerElement),
332 );
333
334 $pageUrl = array('url' => 'event/add', 'args' => "reset=1&action=add");
335 $this->customFieldSetLoadOnTheFlyCheck($customSets, $pageUrl);
336 }
337
338 /**
339 * @param $eventTitle
340 * @param $eventDescription
341 */
342 public function _testAddEventInfo($eventTitle, $eventDescription) {
343 $this->waitForElementPresent("_qf_EventInfo_upload-bottom");
344
345 $this->select("event_type_id", "value=1");
346
347 // Attendee role s/b selected now.
348 $this->select("default_role_id", "value=1");
349
350 // Enter Event Title, Summary and Description
351 $this->type("title", $eventTitle);
352 $this->type("summary", "This is a great conference. Sign up now!");
353
354 // Type description in ckEditor (fieldname, text to type, editor)
355 $this->fillRichTextField("description", $eventDescription, 'CKEditor');
356
357 // Choose Start and End dates.
358 // Using helper webtestFillDate function.
359 $this->webtestFillDateTime("start_date", "+1 week");
360 $this->webtestFillDateTime("end_date", "+1 week 1 day 8 hours ");
361 $this->waitForElementPresent('max_participants');
362 $this->type("max_participants", "50");
363 $this->click("is_map");
364 $this->click("is_public");
365 $this->clickLink("_qf_EventInfo_upload-bottom");
366 }
367
368 /**
369 * @param $eventTitle
370 * @param $eventDescription
371 * @param int $templateID
372 * @param int $eventTypeID
373 */
374 public function _testAddEventInfoFromTemplate($eventTitle, $eventDescription, $templateID, $eventTypeID) {
375 $this->waitForElementPresent("_qf_EventInfo_upload-bottom");
376
377 // Select event template. Use option value, not label - since labels can be translated and test would fail
378 $this->select("template_id", "value={$templateID}");
379
380 // Wait for event type to be filled in (since page refreshes)
381 $this->waitForAjaxContent();
382 $this->verifySelectedValue("event_type_id", $eventTypeID);
383
384 // Attendee role s/b selected now.
385 $this->verifySelectedValue("default_role_id", "1");
386
387 // Enter Event Title, Summary and Description
388 $this->type("title", $eventTitle);
389
390 $this->type("summary", "This is a great conference. Sign up now!");
391
392 // Type description in ckEditor (fieldname, text to type, editor)
393 $this->fillRichTextField("description", $eventDescription, 'CKEditor');
394
395 // Choose Start and End dates.
396 // Using helper webtestFillDate function.
397 $this->webtestFillDateTime("start_date", "+1 week");
398 $this->webtestFillDateTime("end_date", "+1 week 1 day 8 hours ");
399
400 $this->type("max_participants", "50");
401 $this->click("is_map");
402 $this->clickLink("_qf_EventInfo_upload-bottom");
403 }
404
405 /**
406 * @param $streetAddress
407 */
408 public function _testAddLocation($streetAddress) {
409 // Wait for Location tab form to load
410 $this->waitForAjaxContent();
411 $this->waitForElementPresent("_qf_Location_upload-bottom");
412
413 // Fill in address fields
414 $streetAddress = "100 Main Street";
415 $this->type("address_1_street_address", $streetAddress);
416 $this->type("address_1_city", "San Francisco");
417 $this->type("address_1_postal_code", "94117");
418 $this->select('address_1_country_id', 'UNITED STATES');
419 $this->select("address_1_state_province_id", "value=1004");
420 $this->type("email_1_email", "info@civicrm.org");
421
422 $this->click("_qf_Location_upload-bottom");
423
424 // Wait for "saved" status msg
425 $this->waitForText('crm-notification-container', "'Event Location' information has been saved.");
426 }
427
428 /**
429 * @param bool $discount
430 * @param bool $priceSet
431 * @param string $processorName
432 * @param bool $double
433 * @param bool $payLater
434 *
435 * @return array
436 */
437 public function _testAddFees($discount = FALSE, $priceSet = FALSE, $processorName = "PP Pro", $double = FALSE, $payLater = FALSE) {
438 $discount1 = "Early-bird" . substr(sha1(rand()), 0, 7);
439 $discount2 = "";
440 // Go to Fees tab
441 $this->click("link=Fees");
442 $this->waitForElementPresent("_qf_Fee_upload-bottom");
443 $this->click("CIVICRM_QFID_1_is_monetary");
444
445 if ($payLater) {
446 $this->click('is_pay_later');
447 $this->fillRichTextField('pay_later_receipt', 'testing later instructions');
448 }
449 else {
450 $this->uncheck('is_pay_later');
451 }
452
453 if ($processorName) {
454 $this->select2('payment_processor', $processorName, TRUE);
455 }
456 $this->select("financial_type_id", "value=4");
457 if ($priceSet) {
458 // get one - TBD
459 }
460 else {
461 $this->type("label_1", "Member");
462 $this->type("value_1", "225.00");
463 $this->type("label_2", "Non-member");
464 $this->type("value_2", "300.00");
465 $this->click("CIVICRM_QFID_1_6");
466 }
467
468 if ($discount) {
469 // enter early bird discount fees
470 $this->click("is_discount");
471 $this->waitForElementPresent("discount_name_1");
472 $this->type("discount_name_1", $discount1);
473 $this->webtestFillDate("discount_start_date_1", "-3 week");
474 $this->webtestFillDate("discount_end_date_1", "-2 week");
475 $this->clickLink("_qf_Fee_submit", "discounted_value_1_1");
476
477 $this->type("discounted_value_1_1", "225.00");
478 $this->type("discounted_value_2_1", "300.00");
479
480 if ($double) {
481 $discount2 = "Early-bird" . substr(sha1(rand()), 0, 7);
482 // enter early bird discount fees
483 $this->click("link=another discount set");
484 $this->waitForElementPresent("discount_name_2");
485 $this->type("discount_name_2", $discount2);
486 $this->webtestFillDate("discount_start_date_2", "-1 week");
487 $this->webtestFillDate("discount_end_date_2", "+1 week");
488 $this->clickLink("_qf_Fee_submit", "discounted_value_2_1");
489 $this->type("discounted_value_1_2", "225.00");
490 $this->type("discounted_value_2_2", "300.00");
491 }
492 $this->click("xpath=//fieldset[@id='discount']/fieldset/table/tbody/tr[2]/td[3]/input");
493 }
494 $this->click("_qf_Fee_upload-bottom");
495
496 // Wait for "saved" status msg
497 $this->waitForText('crm-notification-container', "'Fees' information has been saved");
498 return array($discount1, $discount2);
499 }
500
501 /**
502 * @param $registerIntro
503 * @param bool $multipleRegistrations
504 */
505 public function _testAddOnlineRegistration($registerIntro, $multipleRegistrations = FALSE, $allowSelfService = FALSE) {
506 // Go to Online Registration tab
507 $this->click("link=Online Registration");
508 $this->waitForElementPresent("_qf_Registration_upload-bottom");
509
510 $isChecked = $this->isChecked('is_online_registration');
511 if (!$isChecked) {
512 $this->click("is_online_registration");
513 }
514 $this->assertChecked("is_online_registration");
515 if ($multipleRegistrations) {
516 $isChecked = $this->isChecked('is_multiple_registrations');
517 if (!$isChecked) {
518 $this->click("is_multiple_registrations");
519 }
520 $this->assertChecked("is_multiple_registrations");
521 }
522
523 //enable 'Allow self-service'
524 if ($allowSelfService) {
525 $isChecked = $this->isChecked('allow_selfcancelxfer');
526 if (!$isChecked) {
527 $this->click("allow_selfcancelxfer");
528 }
529 $this->assertChecked("allow_selfcancelxfer");
530 }
531 $this->fillRichTextField("intro_text", $registerIntro, 'CKEditor', TRUE);
532
533 // enable confirmation email
534 $this->click("CIVICRM_QFID_1_is_email_confirm");
535 $this->type("confirm_from_name", "Jane Doe");
536
537 $this->type("confirm_from_email", "jane.doe@example.org");
538
539 $this->click("_qf_Registration_upload-bottom");
540 $this->waitForText('crm-notification-container', "'Online Registration' information has been saved.");
541 }
542
543 /**
544 * @param $eventTitle
545 * @param $eventInfoStrings
546 * @param null $eventFees
547 *
548 * @return null
549 */
550 public function _testVerifyEventInfo($eventTitle, $eventInfoStrings, $eventFees = NULL) {
551 // verify event input on info page
552 // start at Manage Events listing
553 $this->openCiviPage("event/manage", "reset=1");
554 $this->click("link=$eventTitle");
555
556 // Look for Register button
557 $this->waitForElementPresent("link=Register Now");
558
559 // Check for correct event info strings
560 $this->assertStringsPresent($eventInfoStrings);
561
562 // Optionally verify event fees (especially for discounts)
563 if ($eventFees) {
564 $this->assertStringsPresent($eventFees);
565
566 }
567 return $this->urlArg('id');
568 }
569
570 /**
571 * @param $registerStrings
572 *
573 * @return string
574 */
575 public function _testVerifyRegisterPage($registerStrings) {
576 // Go to Register page and check for intro text and fee levels
577 $this->click("link=Register Now");
578 $this->waitForElementPresent("_qf_Register_upload-bottom");
579 $this->assertStringsPresent($registerStrings);
580 return $this->getLocation();
581 }
582
583 /**
584 * @param $registerUrl
585 * @param int $numberRegistrations
586 * @param bool $anonymous
587 * @param bool $isPayLater
588 * @param array $participantEmailInfo
589 * @param null $paymentProcessor
590 *
591 * @return array
592 */
593 public function _testOnlineRegistration($registerUrl, $numberRegistrations = 1, $anonymous = TRUE, $isPayLater = FALSE, $participantEmailInfo = array(), $paymentProcessor = NULL) {
594 $infoPassed = FALSE;
595 if (!empty($participantEmailInfo)) {
596 $infoPassed = TRUE;
597 }
598 if ($anonymous) {
599 $this->webtestLogout();
600 }
601 $primaryParticipantInfo = array();
602 $this->open($registerUrl);
603 $this->waitForPageToLoad($this->getTimeoutMsec());
604
605 $this->waitForElementPresent('additional_participants');
606
607 $this->select("additional_participants", "value=" . $numberRegistrations);
608
609 if ($infoPassed) {
610 $primaryParticipantInfo['first_name'] = $participantEmailInfo[0]['first_name'];
611 $primaryParticipantInfo['last_name'] = $participantEmailInfo[0]['last_name'];
612 $primaryParticipantInfo['email'] = $participantEmailInfo[0]['email'];
613 }
614 else {
615 $primaryParticipantInfo['first_name'] = "Jane";
616 $primaryParticipantInfo['last_name'] = "Smith" . substr(sha1(rand()), 0, 7);
617 $primaryParticipantInfo['email'] = "smith" . substr(sha1(rand()), 0, 7) . "@example.org";
618 }
619
620 $this->type("first_name", $primaryParticipantInfo['first_name']);
621 $this->type("last_name", $primaryParticipantInfo['last_name']);
622 $this->type("email-Primary", $primaryParticipantInfo['email']);
623
624 if (!$isPayLater) {
625 if ($paymentProcessor) {
626 $paymentProcessorEle = $this->getAttribute("xpath=//form[@id='Register']//label[contains(text(), '{$paymentProcessor}')]/@for");
627 $this->click($paymentProcessorEle);
628 }
629 $this->select("credit_card_type", "value=Visa");
630 $this->type("credit_card_number", "4111111111111111");
631 $this->type("cvv2", "000");
632 $this->select("credit_card_exp_date[M]", "value=1");
633 $this->select("credit_card_exp_date[Y]", "value=2020");
634 $this->type("billing_first_name", $primaryParticipantInfo['first_name']);
635 $this->type("billing_last_name", $primaryParticipantInfo['last_name']);
636 $this->type("billing_street_address-5", "15 Main St.");
637 $this->type(" billing_city-5", "San Jose");
638 $this->select("billing_country_id-5", "value=1228");
639 $this->select("billing_state_province_id-5", "value=1004");
640 $this->type("billing_postal_code-5", "94129");
641 }
642
643 $this->click("_qf_Register_upload-bottom");
644
645 if ($numberRegistrations > 1) {
646 for ($i = 1; $i <= $numberRegistrations; $i++) {
647 $this->waitForPageToLoad($this->getTimeoutMsec());
648 // Look for Skip button
649 $this->waitForElementPresent("_qf_Participant_{$i}_next_skip-Array");
650
651 if ($infoPassed) {
652 $this->type("first_name", $participantEmailInfo[$i]['first_name']);
653 $this->type("last_name", $participantEmailInfo[$i]['last_name']);
654 $this->type("email-Primary", $participantEmailInfo[$i]['email']);
655 }
656 else {
657 $this->type("first_name", "Jane Add $i");
658 $this->type("last_name", "Smith" . substr(sha1(rand()), 0, 7));
659 $this->type("email-Primary", "smith" . substr(sha1(rand()), 0, 7) . "@example.org");
660 }
661
662 $this->click("_qf_Participant_{$i}_next");
663 }
664 }
665
666 $this->waitForPageToLoad($this->getTimeoutMsec());
667 $this->waitForElementPresent("_qf_Confirm_next-bottom");
668 $confirmStrings = array("Event Fee(s)");
669 if (!$isPayLater) {
670 $confirmStrings += array("Billing Name and Address", "Credit Card Information");
671 }
672 $this->assertStringsPresent($confirmStrings);
673 $this->click("_qf_Confirm_next-bottom");
674 $this->waitForPageToLoad($this->getTimeoutMsec());
675 $thankStrings = array("Thank You for Registering", "Event Total");
676 if (!$isPayLater) {
677 $thankStrings = array("Transaction Date");
678 }
679 else {
680 $thankStrings += array("testing later instructions");
681 }
682 $this->assertStringsPresent($thankStrings);
683 return $primaryParticipantInfo;
684 }
685
686 /**
687 * @param $eventTitle
688 */
689 public function _testAddReminder($eventTitle) {
690 // Go to Schedule Reminders tab
691 $this->click("link=Schedule Reminders");
692 $this->waitForElementPresent("newScheduleReminder");
693 $this->click("newScheduleReminder");
694 $this->waitForElementPresent("_qf_ScheduleReminders_next-bottom");
695 $this->type("title", "Event Reminder for " . $eventTitle);
696 $this->select('entity', 'label=Registered');
697
698 $this->select('start_action_offset', 'label=1');
699 $this->select('start_action_condition', 'label=after');
700 $this->click('is_repeat');
701 $this->select('repetition_frequency_interval', 'label=2');
702 $this->select('end_date', 'label=Event End Date');
703 $this->click('recipient');
704 $this->select('recipient', 'label=Participant Role');
705 // $this->select( 'recipient_listing', 'value=1' );
706
707 // Fill Subject
708 $subject = 'subject' . substr(sha1(rand()), 0, 4);
709 $this->type('subject', $subject);
710 $this->fillRichTextField("html_message", "This is the test HTML version here!!!", 'CKEditor');
711
712 $this->type("text_message", "This is the test text version here!!!");
713 //click on save
714 $this->click('_qf_ScheduleReminders_next-bottom');
715 $this->waitForElementPresent("link=Add Reminder");
716
717 $this->waitForElementPresent("xpath=//div[@class='dataTables_wrapper no-footer']/table/tbody/tr/td[7]/span/a[1]");
718
719 $verifyText = array(
720 1 => 'Event Reminder for ' . $eventTitle,
721 3 => '1 hour after Event Start Date',
722 4 => 'Registered',
723 5 => 'Yes',
724 6 => 'Yes',
725 );
726
727 $this->waitForElementPresent("xpath=//form[@id='ScheduleReminders']//div[@id='option11_wrapper']");
728 //verify the fields for Event Reminder selector
729 foreach ($verifyText as $key => $value) {
730 $this->verifyText("xpath=//div[@class='dataTables_wrapper no-footer']/table/tbody//tr/td[$key]", $value);
731 }
732 }
733
734 public function testEventAddMultipleParticipant() {
735 $this->markTestSkipped('Skipping for now as it works fine locally.');
736 // Log in using webtestLogin() method
737 $this->webtestLogin();
738 $this->openCiviPage("event/add", "reset=1&action=add");
739
740 $eventTitle = 'My Conference - ' . substr(sha1(rand()), 0, 7);
741 $eventDescription = "Here is a description for this conference.";
742 $this->_testAddEventInfo($eventTitle, $eventDescription);
743 $streetAddress = "100 Main Street";
744 $this->_testAddLocation($streetAddress);
745
746 $this->_testAddFees(FALSE, FALSE, "Test Processor", FALSE, TRUE);
747 $registerIntro = "Fill in all the fields below and click Continue.";
748 $multipleRegistrations = TRUE;
749 $this->_testAddOnlineRegistration($registerIntro, $multipleRegistrations);
750 $eventInfoStrings = array($eventTitle, $eventDescription, $streetAddress);
751 $eventId = $this->_testVerifyEventInfo($eventTitle, $eventInfoStrings);
752
753 $registerStrings = array("225.00", "Member", "300.00", "Non-member", $registerIntro);
754 $registerUrl = $this->_testVerifyRegisterPage($registerStrings);
755 $numberRegistrations = 3;
756 $anonymous = TRUE;
757
758 // CRM-12615 add additional participants and check email, amount
759 $primaryParticipant = array(
760 'email' => "smith" . substr(sha1(rand()), 0, 7) . "@example.org",
761 'first_name' => "Kate",
762 'last_name' => "Simth" . substr(sha1(rand()), 0, 7),
763 );
764 $secParticipant = array(
765 'email' => "smith" . substr(sha1(rand()), 0, 7) . "@example.org",
766 'first_name' => "Kate Add 1",
767 'last_name' => "Simth" . substr(sha1(rand()), 0, 7),
768 );
769 $thirdParticipant = array(
770 'email' => "smith" . substr(sha1(rand()), 0, 7) . "@example.org",
771 'first_name' => "Kate Add 2",
772 'last_name' => "Simth" . substr(sha1(rand()), 0, 7),
773 );
774
775 $participantEmails = array($primaryParticipant, $secParticipant, $thirdParticipant);
776 $addtlPart = array($secParticipant, $thirdParticipant);
777 $primaryParticipantInfo = $this->_testOnlineRegistration($registerUrl, 2, $anonymous, FALSE, $participantEmails, "Test Processor");
778 $primaryDisplayName = "{$primaryParticipantInfo['first_name']} {$primaryParticipantInfo['last_name']}";
779 $this->webtestLogin();
780 $this->openCiviPage("event/search", "reset=1");
781 $this->select2("event_id", $eventTitle, FALSE);
782 $this->clickLink('_qf_Search_refresh');
783 $this->waitForElementPresent("xpath=//div[@id='participantSearch']/table/tbody//tr/td[3]/a");
784 $this->verifyText("xpath=//div[@id='participantSearch']/table/tbody//tr/td[@class='crm-participant-sort_name']/a[contains(text(),
785 '{$secParticipant['last_name']}, {$secParticipant['first_name']}')]/../../td[6]", preg_quote('225.00'));
786 $this->verifyText("xpath=//div[@id='participantSearch']/table/tbody//tr/td[@class='crm-participant-sort_name']/a[contains(text(),
787 '{$thirdParticipant['last_name']}, {$thirdParticipant['first_name']}')]/../../td[6]", preg_quote('225.00'));
788
789 //CRM-12618 check edit screen of additional participant and ensuring record_contribution not present
790 foreach ($addtlPart as $value) {
791 $this->clickAjaxLink("xpath=//div[@id='participantSearch']/table/tbody//tr/td[3]/a[contains(text(),
792 '{$value['last_name']}, {$value['first_name']}')]/../../td[11]/span/a[2][contains(text(), 'Edit')]",
793 '_qf_Participant_upload-bottom');
794 $this->assertTrue(
795 $this->isElementPresent("xpath=//tr[@class='crm-participant-form-block-registered-by']/td[2]/a[contains(text(),
796 '$primaryDisplayName')]"), 'Registered By info is wrong on additional participant edit form');
797 $this->assertTrue(
798 $this->isElementPresent(
799 "xpath=//table/tbody/tr[@class='crm-participant-form-block-displayName']/td[2][contains(text(),
800 '{$value['first_name']} {$value['last_name']}')]"),
801 'Wrong Participant edit form'
802 );
803 $this->assertFalse($this->isElementPresent('record_contribution'),
804 'Record Payment checkbox showed up wrongly for additional participant edit screen');
805 $this->click("_qf_Participant_cancel-top");
806 }
807
808 //unselect the payment processor configured
809 $this->openCiviPage("event/manage/fee", "reset=1&action=update&id={$eventId}", '_qf_Fee_upload-bottom');
810 $this->click("_qf_Fee_upload-bottom");
811 $this->waitForText('crm-notification-container', "'Fees' information has been saved.");
812
813 // add participant and 3 additional participant and change status of participant from edit participant
814 $this->_testOnlineRegistration($registerUrl, $numberRegistrations, $anonymous, TRUE);
815 $this->webtestLogin();
816
817 $this->openCiviPage("event/search?reset=1", "reset=1");
818 $this->select2("event_id", $eventTitle, FALSE);
819 $this->multiselect2('participant_status_id', array('Pending (pay later)'));
820 $this->clickLink('_qf_Search_refresh');
821 $this->waitForElementPresent("xpath=//div[@id='participantSearch']/table/tbody//tr/td[11]/span/a[2][text()='Edit']");
822
823 $uRL = $this->getAttribute("xpath=//div[@id='participantSearch']/table/tbody//tr/td[11]/span/a[2][text()='Edit']@href");
824 $this->click("xpath=//div[@id='participantSearch']/table/tbody//tr/td[11]/span/a[2][text()='Edit']");
825 $this->waitForElementPresent("status_id");
826 $this->select('status_id', 'label=Registered');
827 $this->waitForElementPresent("record_contribution");
828 $this->click('record_contribution');
829 $this->waitForElementPresent("contribution_status_id");
830 $this->select('contribution_status_id', 'label=Completed');
831 $pID = $this->urlArg('id', $uRL);
832 $contributionID = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $pID, 'contribution_id', 'participant_id');
833 $this->click('_qf_Participant_upload-top');
834 $this->waitForElementPresent("xpath=//div[@id='participantSearch']/table/tbody//tr/td[11]/span/a[text()='Edit']");
835 $this->waitForElementPresent("xpath=//div[@id='participantSearch']/table/tbody//tr/td[11]/span/a[text()='View']");
836 $this->click("xpath=//div[@id='participantSearch']/table/tbody//tr/td[11]/span/a[text()='View']");
837 $this->waitForElementPresent("css=.ui-dialog");
838 $this->waitForAjaxContent();
839 $this->verifyFinancialRecords($contributionID);
840
841 // add participant and 3 additional participant and change status of participant from edit contribution
842 $this->_testOnlineRegistration($registerUrl, $numberRegistrations, $anonymous, TRUE);
843 $this->webtestLogin();
844
845 $this->openCiviPage("event/search?reset=1", "reset=1");
846 $this->select2("event_id", $eventTitle, FALSE);
847 $this->multiselect2('participant_status_id', array('Pending (pay later)'));
848 $this->clickLink('_qf_Search_refresh');
849 $this->waitForElementPresent("xpath=//div[@id='participantSearch']/table/tbody//tr/td[11]/span/a[text()='View']");
850 $uRL = $this->getAttribute("xpath=//div[@id='participantSearch']/table/tbody//tr/td[11]/span/a[text()='View']@href");
851 $this->click("xpath=//div[@id='participantSearch']/table/tbody//tr/td[11]/span/a[text()='View']");
852 $pID = $this->urlArg('id', $uRL);
853 $contributionID = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $pID, 'contribution_id', 'participant_id');
854 $this->waitForElementPresent("xpath=//tr[@id='rowid$contributionID']/td[8]/span//a[text()='Edit']");
855 $this->click("xpath=//tr[@id='rowid$contributionID']/td[8]/span//a[text()='Edit']");
856 $this->waitForElementPresent("_qf_Contribution_upload-bottom");
857 $this->select('contribution_status_id', 'label=Completed');
858 $this->clickLink('_qf_Contribution_upload-bottom', '_qf_ParticipantView_cancel-bottom', FALSE);
859 $this->waitForAjaxContent();
860 $this->verifyFinancialRecords($contributionID);
861 }
862
863 /**
864 * @param int $contributionID
865 */
866 public function verifyFinancialRecords($contributionID) {
867 // check count for civicrm_contribution and civicrm_financial_item in civicrm_entity_financial_trxn
868 $query = "SELECT COUNT(DISTINCT(c1.id)) civicrm_contribution, COUNT(c2.id) civicrm_financial_item FROM civicrm_entity_financial_trxn c1
869 LEFT JOIN civicrm_entity_financial_trxn c2 ON c1.financial_trxn_id = c2.financial_trxn_id AND c2.entity_table ='civicrm_financial_item'
870 LEFT JOIN civicrm_financial_item cfi ON cfi.id = c2.entity_id
871 WHERE c1.entity_table = 'civicrm_contribution' AND c1.entity_id = %1 AND cfi.status_id = 1";
872 $params = array(1 => array($contributionID, 'Integer'));
873 $dao = CRM_Core_DAO::executeQuery($query, $params);
874 $dao->fetch();
875 $this->assertEquals('2', $dao->civicrm_contribution, 'civicrm_financial_trxn count does not match');
876 $this->assertEquals('8', $dao->civicrm_financial_item, 'civicrm_financial_item count does not match');
877 $query = "SELECT COUNT(cft.id) civicrm_financial_trxn FROM civicrm_entity_financial_trxn ceft
878 INNER JOIN civicrm_financial_trxn cft ON ceft.financial_trxn_id = cft.id
879 WHERE ceft.entity_id = %1 AND ceft.entity_table = 'civicrm_contribution'";
880 $dao = CRM_Core_DAO::executeQuery($query, $params);
881 $dao->fetch();
882 $this->assertEquals('2', $dao->civicrm_financial_trxn, 'civicrm_financial_trxn count does not match');
883 }
884
885 public function testEventApprovalRegistration() {
886 $this->webtestLogin();
887
888 //Participant Status
889 $this->openCiviPage("admin/participant_status", "reset=1&action=browse");
890 foreach (array('Awaiting approval', 'Pending from approval', 'Rejected') as $label) {
891 $status = $this->webtest_civicrm_api("ParticipantStatusType", "getsingle", array('label' => $label));
892 $this->_testEnableParticipantStatuses($status['id']);
893 $this->isElementPresent("xpath=//tr[@id='participant_status_type-{$status['id']}']/td[9]/span/a[2][text()='Disable']");
894 }
895
896 //Create New Event
897
898 $this->openCiviPage('event/add', 'reset=1&action=add', '_qf_EventInfo_upload-bottom');
899 $eventTitle = 'My Conference - ' . substr(sha1(rand()), 0, 7);
900 $email = 'Smith' . substr(sha1(rand()), 0, 7) . '@example.com';
901 $eventDescription = 'Here is a description for this conference.';
902 $this->select('event_type_id', 'value=1');
903
904 // Attendee role s/b selected now.
905 $this->select('default_role_id', 'value=1');
906 // Enter Event Title, Summary and Description
907 $this->type('title', $eventTitle);
908 $this->type('summary', 'This is a great conference. Sign up now!');
909
910 // Type description in ckEditor (fieldname, text to type, editor)
911 $this->fillRichTextField('description', $eventDescription);
912 $this->type('max_participants', '50');
913 $this->click('is_map');
914 $this->click('_qf_EventInfo_upload-bottom');
915
916 // Wait for Location tab form to load
917 $this->waitForPageToLoad($this->getTimeoutMsec());
918
919 // Go to Fees tab
920 $this->click('link=Fees');
921 $id = $this->urlArg('id');
922 $this->waitForElementPresent('_qf_Fee_upload-bottom');
923 $this->click('CIVICRM_QFID_1_is_monetary');
924 $processorName = 'Test Processor';
925 $this->select2('payment_processor', $processorName, TRUE);
926
927 $this->select('financial_type_id', 'label=Event Fee');
928 $this->type("label[1]", 'Junior Stars');
929 $this->type("value[1]", '500.00');
930 $this->type("label[2]", 'Super Stars');
931 $this->type("value[2]", '1000.00');
932 $this->check('default');
933 $this->click('_qf_Fee_upload-bottom');
934 $this->waitForText('crm-notification-container', "'Fees' information has been saved.");
935
936 // intro text for registration page
937 $registerIntro = 'Fill in all the fields below and click Continue.';
938
939 // Go to Online Registration tab
940 $this->click('link=Online Registration');
941 $this->waitForElementPresent('_qf_Registration_upload-bottom');
942 $this->click('is_online_registration');
943 $this->assertChecked('is_online_registration');
944
945 //Requires Approvel
946 $this->click('requires_approval');
947 $this->assertChecked('requires_approval');
948 $this->click('_qf_Registration_upload-bottom');
949 $this->waitForText('crm-notification-container', "'Online Registration' information has been saved.");
950
951 // verify event input on info page
952 // start at Manage Events listing
953 $this->openCiviPage('event/manage', 'reset=1');
954 $this->click("link=$eventTitle");
955 $this->waitForPageToLoad($this->getTimeoutMsec());
956 $firstName = substr(sha1(rand()), 0, 7);
957 $this->webtestAddContact($firstName, 'Anderson', TRUE);
958 $contactName = "Anderson, $firstName";
959 $displayName = "$firstName Anderson";
960 $this->openCiviPage("event/register", "reset=1&id=$id&action=preview", '_qf_Register_upload-bottom');
961 $this->type('first_name', $firstName);
962
963 //fill in last name
964 $lastName = 'Recuron' . substr(sha1(rand()), 0, 7);
965 $this->type('last_name', $contactName);
966 $email = $firstName . '@example.com';
967 $this->type('email-Primary', $email);
968 $this->click('_qf_Register_upload');
969 $this->waitForElementPresent("_qf_Confirm_next");
970 $this->click('_qf_Confirm_next');
971 $this->waitForPageToLoad($this->getTimeoutMsec());
972 $this->waitForElementPresent("xpath=//div[@class='crm-group participant_info-group']");
973 $this->assertTextPresent("Thank You for Registering");
974
975 }
976
977 /**
978 * Test enabling participant statuses.
979 *
980 * @param int $statusId
981 */
982 public function _testEnableParticipantStatuses($statusId) {
983 // enable participant status
984 if ($this->isElementPresent("xpath=//tr[@id='participant_status_type-{$statusId}']/td[9]/span/a[2][text()='Enable']")) {
985 $this->click("xpath=//tr[@id='participant_status_type-{$statusId}']/td[9]/span/a[2][text()='Enable']");
986 $this->waitForElementPresent("xpath=//tr[@id='participant_status_type-{$statusId}']/td[9]/span/a[2][text()='Disable']");
987 }
988 }
989
990 /**
991 * CRM-16777: Allow to add schedule reminder for event with 'edit all event' permission
992 */
993 public function testConfigureScheduleReminder() {
994 // Log in using webtestLogin() method
995 $this->webtestLogin('admin');
996
997 //Details for TestUser1
998 $role1 = 'role1' . substr(sha1(rand()), 0, 7);
999 $TestUser1 = "TestUser1" . substr(sha1(rand()), 0, 4);
1000 $emailId1 = substr(sha1(rand()), 0, 7) . '@web.com';
1001
1002 //create Role1 with permission 'Access CiviCRM', 'edit all events' and 'Access CiviEvent' permissions.
1003 $this->open($this->sboxPath . "admin/people/permissions/roles");
1004 $this->type("edit-name", $role1);
1005 $this->waitForElementPresent("edit-add");
1006 $this->click("edit-add");
1007 $this->waitForPageToLoad($this->getTimeoutMsec());
1008 $this->open($this->sboxPath . "admin/people/permissions/roles");
1009 $this->waitForElementPresent("xpath=//table[@id='user-roles']/tbody//tr/td[1][text()='{$role1}']");
1010 $roleId = explode('/', $this->getAttribute("xpath=//table[@id='user-roles']/tbody//tr/td[1][text()='{$role1}']/../td[4]/a[text()='edit permissions']/@href"));
1011 $permissions = array(
1012 "edit-{$roleId[5]}-access-civicrm",
1013 "edit-{$roleId[5]}-edit-all-events",
1014 "edit-{$roleId[5]}-access-civievent",
1015 );
1016 $this->changePermissions($permissions);
1017
1018 //Create TestUser1
1019 $this->open($this->sboxPath . "admin/people/create");
1020 $this->waitForElementPresent("edit-submit");
1021 $this->type("edit-name", $TestUser1);
1022 $this->type("edit-mail", $emailId1);
1023 $this->type("edit-pass-pass1", "Test12345");
1024 $this->type("edit-pass-pass2", "Test12345");
1025 $this->click("xpath=//div[@class='form-item form-type-checkboxes form-item-roles']/div//div/label[contains(text(), '{$role1}')]");
1026 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
1027 $lastName = 'An' . substr(sha1(rand()), 0, 7);
1028 $this->type("first_name", $firstName);
1029 $this->type("last_name", $lastName);
1030 $this->type("street_address-1", "902C El Camino Way SW");
1031 $this->type("city-1", "Dumfries");
1032 $this->type("postal_code-1", "1234");
1033 $this->select("state_province-1", "value=1019");
1034 $this->click("edit-submit");
1035 $this->waitForPageToLoad($this->getTimeoutMsec());
1036
1037 //Add event
1038 $this->openCiviPage("event/add", "reset=1&action=add");
1039 $this->waitForElementPresent("_qf_EventInfo_cancel-bottom");
1040 $eventName = 'My Event - ' . substr(sha1(rand()), 0, 7);
1041 $eventDescription = "Here is a description for this conference.";
1042 $this->_testAddEventInfo($eventName, $eventDescription);
1043
1044 //Logging out
1045 $this->webtestLogout();
1046
1047 //Login with TestUser1
1048 $this->webtestLogin($TestUser1, 'Test12345');
1049 $this->openCiviPage("event/manage", "reset=1");
1050 $this->type("title", $eventName);
1051 $this->click("_qf_SearchEvent_refresh");
1052 $this->waitForAjaxContent();
1053 $this->_testAddReminder($eventName);
1054 $this->webtestLogout();
1055
1056 //Details for TestUser2
1057 $role2 = 'role2' . substr(sha1(rand()), 0, 5);
1058 $TestUser2 = "TestUser2" . substr(sha1(rand()), 0, 5);
1059 $emailId2 = substr(sha1(rand()), 0, 7) . '@web.com';
1060
1061 //create Role2 with only 'Access CiviCRM' and 'Access CiviEvent' permissions
1062 $this->webtestLogin('admin');
1063 $this->open($this->sboxPath . "admin/people/permissions/roles");
1064 $this->type("edit-name", $role2);
1065 $this->waitForElementPresent("edit-add");
1066 $this->click("edit-add");
1067 $this->waitForPageToLoad($this->getTimeoutMsec());
1068 $this->open($this->sboxPath . "admin/people/permissions/roles");
1069 $this->waitForElementPresent("xpath=//table[@id='user-roles']/tbody//tr/td[1][text()='{$role2}']");
1070 $roleId = explode('/', $this->getAttribute("xpath=//table[@id='user-roles']/tbody//tr/td[1][text()='{$role2}']/../td[4]/a[text()='edit permissions']/@href"));
1071 $permissions = array(
1072 "edit-{$roleId[5]}-access-civicrm",
1073 "edit-{$roleId[5]}-access-civievent",
1074 );
1075 $this->changePermissions($permissions);
1076
1077 //Create TestUser2
1078 $this->open($this->sboxPath . "admin/people/create");
1079 $this->waitForElementPresent("edit-submit");
1080 $this->type("edit-name", $TestUser2);
1081 $this->type("edit-mail", $emailId2);
1082 $this->type("edit-pass-pass1", "Test123");
1083 $this->type("edit-pass-pass2", "Test123");
1084 $this->click("xpath=//div[@class='form-item form-type-checkboxes form-item-roles']/div//div/label[contains(text(), '{$role2}')]");
1085 $firstName = 'Smith' . substr(sha1(rand()), 0, 4);
1086 $lastName = 'John' . substr(sha1(rand()), 0, 5);
1087 $this->type("first_name", $firstName);
1088 $this->type("last_name", $lastName);
1089 $this->type("street_address-1", "902C El Camino Way SW");
1090 $this->type("city-1", "Dumfries");
1091 $this->type("postal_code-1", "1234");
1092 $this->select("state_province-1", "value=1019");
1093 $this->click("edit-submit");
1094 $this->waitForPageToLoad($this->getTimeoutMsec());
1095
1096 //Logout
1097 $this->webtestLogout();
1098
1099 //Login with TestUser2
1100 $this->webtestLogin($TestUser2, 'Test123');
1101 $this->openCiviPage("event/manage", "reset=1");
1102 $this->waitForElementPresent("xpath=//div[@id='event_status_id']/div[@class='dataTables_wrapper no-footer']");
1103 $this->verifyText("xpath=//div[@id='event_status_id']/div[@class='dataTables_wrapper no-footer']/table/tbody/tr/td", "None found.");
1104 $this->webtestLogout();
1105 }
1106
1107 /**
1108 * CRM-16761: Self service view, update and cancel for CiviEvent
1109 */
1110 public function testAllowSelfService() {
1111 $this->webtestLogin('admin');
1112
1113 // Create Individual
1114 $contact1 = substr(sha1(rand()), 0, 7);
1115 $this->webtestAddContact($contact1, "Anderson", "{$contact1}@example.com");
1116
1117 // Add event
1118 $this->openCiviPage("event/add", "reset=1&action=add");
1119 $eventTitle = 'My Conference - ' . substr(sha1(rand()), 0, 7);
1120 $eventDescription = "Here is a description for this conference.";
1121 $registerIntro = "Fill in all the fields below and click Continue.";
1122 $multipleRegistrations = TRUE;
1123 $allowSelfService = TRUE;
1124 $this->_testAddEventInfo($eventTitle, $eventDescription);
1125 $streetAddress = "100 Main Street";
1126 $this->_testAddLocation($streetAddress);
1127 $this->_testAddFees(FALSE, FALSE, "Test Processor", FALSE, TRUE);
1128 $this->_testAddOnlineRegistration($registerIntro, FALSE, $allowSelfService);
1129
1130 // Register participant
1131 $id = $this->urlArg('id');
1132 $this->openCiviPage("event/register", "reset=1&id=$id&action=preview", '_qf_Register_upload-bottom');
1133 $this->waitForElementPresent("xpath=//div[@id='crm-event-register-different']/a");
1134 $this->click("xpath=//div[@id='crm-event-register-different']/a");
1135 $this->waitForAjaxcontent();
1136 $this->select2("select_contact_id", "$contact1");
1137
1138 // Fill card details
1139 $this->select("credit_card_type", "value=Visa");
1140 $this->type("credit_card_number", "4111111111111111");
1141 $this->type("cvv2", "000");
1142 $this->select("credit_card_exp_date[M]", "value=1");
1143 $this->select("credit_card_exp_date[Y]", "value=2020");
1144
1145 // Add billing Address
1146 $this->webtestAddBillingDetails($contact1, NULL, 'Anderson');
1147 $this->click("_qf_Register_upload-bottom");
1148 $this->waitForPageToLoad($this->getTimeoutMsec());
1149 $this->waitForElementPresent("_qf_Confirm_next-top");
1150 $this->click("_qf_Confirm_next-top");
1151
1152 // Find Participant.
1153 $this->openCiviPage("event/search", "reset=1");
1154 $this->waitForElementPresent("_qf_Search_refresh");
1155 $this->type('sort_name', "Anderson, $contact1");
1156 $this->click("_qf_Search_refresh");
1157 $this->waitForElementPresent("xpath=//div[@id='participantSearch']");
1158
1159 // Get the id of primary participant
1160 $primaryParticipantId = $this->urlArg('id', $this->getAttribute("xpath=//div[@id='participantSearch']/table/tbody/tr/td[3]/a[text()='Anderson, $contact1']/../../td[11]/span/a[1][text()='View']@href"));
1161
1162 // Get the contact id of primary participant
1163 $primaryParticipantContactid = $this->urlArg('cid', $this->getAttribute("xpath=//div[@id='participantSearch']/table/tbody/tr/td[3]/a[text()='Anderson, $contact1']/../../td[11]/span/a[1][text()='View']@href"));
1164
1165 // Generate checksum for primary participant
1166 $checkSum = CRM_Contact_BAO_Contact_Utils::generateChecksum($primaryParticipantContactid);
1167 $this->open($this->sboxPath . "admin/people/permissions/roles");
1168 $permissions = array(
1169 "edit-1-access-civicrm",
1170 "edit-1-access-civievent",
1171 "edit-1-edit-all-events",
1172 );
1173 $this->webtestLogout();
1174
1175 // Transfer event registration.
1176 $this->openCiviPage("event/selfsvcupdate", "reset=1&pid=$primaryParticipantId&cs=$checkSum");
1177 $this->waitForElementPresent("xpath=//table[@class='crm-selfsvcupdate-form-details']");
1178 $this->verifyText("xpath=//table[@class='crm-selfsvcupdate-form-details']/tbody/tr/td[1]", preg_quote("Anderson, $contact1"));
1179 $this->verifyText("xpath=//table[@class='crm-selfsvcupdate-form-details']/tbody/tr/td[2]", preg_quote("$eventTitle"));
1180 $this->select("action", "value=1");
1181 $this->click("_qf_SelfSvcUpdate_submit-bottom");
1182 $this->waitForElementPresent("_qf_SelfSvcTransfer_submit-bottom");
1183 $newParticipantFirstName = substr(sha1(rand()), 0, 5);
1184 $newParticipantLastName = "Smith";
1185 $newParticipantEmail = "{$newParticipantFirstName}@example.com";
1186 $this->type('email', $newParticipantEmail);
1187 $this->type('last_name', $newParticipantLastName);
1188 $this->type('first_name', $newParticipantFirstName);
1189 $this->click("_qf_SelfSvcTransfer_submit-bottom");
1190
1191 // Cancel event registration.
1192 $this->webtestLogin('admin');
1193 $this->openCiviPage("event/search", "reset=1");
1194 $this->type('sort_name', "Smith, $newParticipantFirstName");
1195 $this->click("_qf_Search_refresh");
1196 $this->waitForElementPresent("xpath=//div[@id='participantSearch']/table/tbody/tr/td[3]/a[text()='Smith, $newParticipantFirstName']/../../td[11]/span/a[1][text()='View']");
1197
1198 // Get the id of new participant
1199 $newParticipantId = $this->urlArg('id', $this->getAttribute("xpath=//div[@id='participantSearch']/table/tbody/tr/td[3]/a[text()='Smith, $newParticipantFirstName']/../../td[11]/span/a[1][text()='View']@href"));
1200
1201 // Get the contact id of new participant
1202 $newParticipantContactId = $this->urlArg('cid', $this->getAttribute("xpath=//div[@id='participantSearch']/table/tbody/tr/td[3]/a[text()='Smith, $newParticipantFirstName']/../../td[11]/span/a[1][text()='View']@href"));
1203
1204 // Generate checksum for new participant
1205 $newParticipantcheckSum = CRM_Contact_BAO_Contact_Utils::generateChecksum($newParticipantContactId);
1206 $this->webtestLogout();
1207 $this->openCiviPage("event/selfsvcupdate", "reset=1&pid=$newParticipantId&cs=$newParticipantcheckSum");
1208 $this->verifyText("xpath=//table[@class='crm-selfsvcupdate-form-details']/tbody/tr/td[1]", preg_quote("Smith, $newParticipantFirstName"));
1209 $this->verifyText("xpath=//table[@class='crm-selfsvcupdate-form-details']/tbody/tr/td[2]", preg_quote("$eventTitle"));
1210 $this->select("action", "value=2");
1211 $this->click("_qf_SelfSvcUpdate_submit-bottom");
1212
1213 // Check the status of participant
1214 $this->webtestLogin('admin');
1215 $this->openCiviPage("event/search", "reset=1");
1216 $this->waitForElementPresent('_qf_Search_refresh');
1217 $this->select2("event_id", $eventTitle);
1218 $this->click("xpath=//div[@id='searchForm']/table/tbody/tr[9]/td[1]/label[text()='No']");
1219 $this->click("_qf_Search_refresh");
1220 $this->waitForElementPresent("xpath=//div[@id='participantSearch']/table/tbody");
1221 $this->assertElementContainsText("xpath=//div[@id='participantSearch']/table/tbody/tr[@id='rowid$primaryParticipantId']/td[9]", "Transferred");
1222 $this->assertElementContainsText("xpath=//div[@id='participantSearch']/table/tbody/tr[@id='rowid$newParticipantId']/td[9]", "Cancelled");
1223 }
1224
1225 /**
1226 * CRM-17745: Make maximum number of participants configurable
1227 */
1228 public function testLimitMaximumParticipants() {
1229 $this->webtestLogin('admin');
1230
1231 // Add event
1232 $this->openCiviPage("event/add", "reset=1&action=add");
1233 $eventTitle = 'My Conference - ' . substr(sha1(rand()), 0, 7);
1234 $eventDescription = "Here is a description for this conference.";
1235 $registerIntro = "Fill in all the fields below and click Continue.";
1236 $this->_testAddEventInfo($eventTitle, $eventDescription);
1237 $multipleRegistrations = TRUE;
1238 $this->_testAddOnlineRegistration($registerIntro, $multipleRegistrations);
1239 $id = $this->urlArg('id');
1240
1241 // Limit additional participants
1242 $this->openCiviPage("event/manage/registration", "reset=1&action=update&id=$id", '_qf_Registration_upload-bottom');
1243 $this->select("max_additional_participants", "value=4");
1244 $this->click("_qf_Registration_upload-bottom");
1245 $this->waitForText('crm-notification-container', "'Online Registration' information has been saved.");
1246
1247 // Open registration page and check maximum participants
1248 $this->openCiviPage("event/register", "reset=1&id=$id&action=preview", '_qf_Register_upload-bottom');
1249 $this->verifyText("xpath=//select[@id='additional_participants']/option[last()]", 5);
1250 }
1251
1252 }