fixes for WebTest_Contribute_StandaloneAddTest
[civicrm-core.git] / tests / phpunit / WebTest / Event / AddEventTest.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License along with this program; if not, contact CiviCRM LLC |
21 | at info[AT]civicrm[DOT]org. If you have questions about the |
22 | GNU Affero General Public License or the licensing of CiviCRM, |
23 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
24 +--------------------------------------------------------------------+
25*/
26
6a488035
TO
27require_once 'CiviTest/CiviSeleniumTestCase.php';
28class WebTest_Event_AddEventTest extends CiviSeleniumTestCase {
29
30 protected function setUp() {
31 parent::setUp();
32 }
33
34 function testAddPaidEventNoTemplate() {
6a488035
TO
35 // Log in using webtestLogin() method
36 $this->webtestLogin();
37
38 // We need a payment processor
39 $processorName = "Webtest Dummy" . substr(sha1(rand()), 0, 7);
40 $this->webtestAddPaymentProcessor($processorName);
41
071a6d2e 42 $this->openCiviPage("event/add", "reset=1&action=add");
6a488035
TO
43
44 $eventTitle = 'My Conference - ' . substr(sha1(rand()), 0, 7);
45 $eventDescription = "Here is a description for this conference.";
46 $this->_testAddEventInfo($eventTitle, $eventDescription);
47
48 $streetAddress = "100 Main Street";
49 $this->_testAddLocation($streetAddress);
50
51 $this->_testAddReminder($eventTitle);
52
53 $this->_testAddFees(FALSE, FALSE, $processorName);
54
55 // intro text for registration page
56 $registerIntro = "Fill in all the fields below and click Continue.";
57 $multipleRegistrations = TRUE;
58 $this->_testAddOnlineRegistration($registerIntro, $multipleRegistrations);
59
60 $eventInfoStrings = array($eventTitle, $eventDescription, $streetAddress);
05f3c31c 61 $eventId = $this->_testVerifyEventInfo($eventTitle, $eventInfoStrings);
6a488035
TO
62
63 $registerStrings = array("225.00", "Member", "300.00", "Non-member", $registerIntro);
64 $registerUrl = $this->_testVerifyRegisterPage($registerStrings);
65
66 $numberRegistrations = 3;
67 $anonymous = TRUE;
68 $this->_testOnlineRegistration($registerUrl, $numberRegistrations, $anonymous);
05f3c31c
DG
69
70 // Now test making a copy of the event
71 $this->webtestLogin();
72 $this->openCiviPage("event/manage", "reset=1&action=copy&id=$eventId");
73 $copyEventId = $this->_testVerifyEventInfo('Copy of ' . $eventTitle, $eventInfoStrings);
74 $registerUrl = $this->_testVerifyRegisterPage($registerStrings);
6a488035
TO
75 }
76
77 function testAddPaidEventDiscount() {
6a488035
TO
78
79 // Log in using webtestLogin() method
80 $this->webtestLogin();
81
82 // We need a payment processor
83 $processorName = "Webtest Dummy" . substr(sha1(rand()), 0, 7);
84 $this->webtestAddPaymentProcessor($processorName);
85
071a6d2e 86 $this->openCiviPage("event/add", "reset=1&action=add");
6a488035
TO
87
88 $eventTitle = 'My Conference - ' . substr(sha1(rand()), 0, 7);
89 $eventDescription = "Here is a description for this conference.";
90 $this->_testAddEventInfo($eventTitle, $eventDescription);
91
92 $streetAddress = "100 Main Street";
93 $this->_testAddLocation($streetAddress);
94
95 $this->_testAddReminder($eventTitle);
96
97 $this->_testAddFees(TRUE, FALSE, $processorName);
98
99 // intro text for registration page
100 $registerIntro = "Fill in all the fields below and click Continue.";
101 $multipleRegistrations = TRUE;
102 $this->_testAddOnlineRegistration($registerIntro, $multipleRegistrations);
103
76e86fd8
CW
104 $discountFees = array("225.00", "300.00");
105
6a488035
TO
106 $eventInfoStrings = array($eventTitle, $eventDescription, $streetAddress);
107 $this->_testVerifyEventInfo($eventTitle, $eventInfoStrings, $discountFees);
108
109 $registerStrings = array_push($discountFees, "Member", "Non-member", $registerIntro);
110 $registerUrl = $this->_testVerifyRegisterPage($registerStrings);
111
112 $numberRegistrations = 3;
113 $anonymous = TRUE;
114 $this->_testOnlineRegistration($registerUrl, $numberRegistrations, $anonymous);
115 }
116
117 function testDeletePriceSetDiscount() {
6a488035
TO
118
119 // Log in using webtestLogin() method
120 $this->webtestLogin();
121
122 // We need a payment processor
123 $processorName = "Webtest Dummy" . substr(sha1(rand()), 0, 7);
124 $this->webtestAddPaymentProcessor($processorName);
125
071a6d2e 126 $this->openCiviPage("event/add", "reset=1&action=add");
6a488035
TO
127
128 $eventTitle = 'My Conference - ' . substr(sha1(rand()), 0, 7);
129 $eventDescription = "Here is a description for this conference.";
130 $this->_testAddEventInfo($eventTitle, $eventDescription);
131
132 $streetAddress = "100 Main Street";
133 $this->_testAddLocation($streetAddress);
134
135 //Add two discounts
136 $discount = $this->_testAddFees(TRUE, FALSE, $processorName, TRUE);
137
138 // intro text for registration page
139 $registerIntro = "Fill in all the fields below and click Continue.";
140 $multipleRegistrations = TRUE;
141 $this->_testAddOnlineRegistration($registerIntro, $multipleRegistrations);
142
76e86fd8
CW
143 $discountFees = array("225.00", "300.00");
144
6a488035
TO
145 $eventInfoStrings = array($eventTitle, $eventDescription, $streetAddress);
146 $id = $this->_testVerifyEventInfo($eventTitle, $eventInfoStrings, $discountFees);
147
148 $registerStrings = array_push($discountFees, "Member", "Non-member", $registerIntro);
149 $registerUrl = $this->_testVerifyRegisterPage($registerStrings);
150
151 //Add Price Set now
42daf119 152 $this->openCiviPage("event/manage/fee", "reset=1&action=update&id=$id", "_qf_Fee_upload-bottom");
6a488035
TO
153 $this->click("xpath=//a[@id='quickconfig']");
154 $this->waitForElementPresent('popupContainer');
efb29358
CW
155 // Because it tends to cause problems, all uses of sleep() must be justified in comments
156 // Sleep should never be used for wait for anything to load from the server
157 // Justification for this instance: FIXME
6a488035
TO
158 sleep(3);
159 $this->click("xpath=//div[@class='ui-dialog-buttonset']/button[1]");
efb29358
CW
160 // Because it tends to cause problems, all uses of sleep() must be justified in comments
161 // Sleep should never be used for wait for anything to load from the server
162 // Justification for this instance: FIXME
6a488035 163 sleep(3);
76e86fd8 164
6a488035 165 //Assert quick config change and discount deletion
071a6d2e 166 $this->openCiviPage("admin/price", "reset=1");
6a488035
TO
167 $this->assertStringsPresent($discount);
168 }
169
170 function testAddDeleteEventDiscount() {
6a488035
TO
171
172 // Log in using webtestLogin() method
173 $this->webtestLogin();
174
175 // We need a payment processor
176 $processorName = "Webtest Dummy" . substr(sha1(rand()), 0, 7);
177 $this->webtestAddPaymentProcessor($processorName);
178
071a6d2e 179 $this->openCiviPage("event/add", "reset=1&action=add");
6a488035
TO
180
181 $eventTitle = 'My Conference - ' . substr(sha1(rand()), 0, 7);
182 $eventDescription = "Here is a description for this conference.";
183 $this->_testAddEventInfo($eventTitle, $eventDescription);
184
185 $streetAddress = "100 Main Street";
186 $this->_testAddLocation($streetAddress);
187
188 //Add two discounts
189 $discount = $this->_testAddFees(TRUE, FALSE, $processorName, TRUE);
190
191 // intro text for registration page
192 $registerIntro = "Fill in all the fields below and click Continue.";
193 $multipleRegistrations = TRUE;
194 $this->_testAddOnlineRegistration($registerIntro, $multipleRegistrations);
195
76e86fd8
CW
196 $discountFees = array("225.00", "300.00");
197
6a488035
TO
198 $eventInfoStrings = array($eventTitle, $eventDescription, $streetAddress);
199 $id = $this->_testVerifyEventInfo($eventTitle, $eventInfoStrings, $discountFees);
200
201 $registerStrings = array_push($discountFees, "Member", "Non-member", $registerIntro);
202 $registerUrl = $this->_testVerifyRegisterPage($registerStrings);
203 //Delete the discount
204 $this->_deleteDiscount($id, $eventTitle, $discount);
205 }
206
207 function _deleteDiscount($id, $eventTitle, $discount) {
42daf119 208 $this->openCiviPage("event/manage/fee", "reset=1&action=update&id=$id", "_qf_Fee_upload-bottom");
6a488035
TO
209 $this->type("discount_name_2", "");
210 $this->click("xpath=//tr[@id='discount_2']/td[3]/span/a");
211 $this->click("xpath=//tr[@id='discount_2']/td[4]/span/a");
212 $this->type("discounted_value_1_2", "");
213 $this->type("discounted_value_2_2", "");
214 $this->click("_qf_Fee_upload-bottom");
071a6d2e 215 $this->waitForPageToLoad();
6a488035 216 //Assertions
071a6d2e 217 $this->openCiviPage("admin/price", "reset=1");
6a488035
TO
218 $this->assertStringsPresent($discount[1]);
219 }
220
221 function testAddPaidEventWithTemplate() {
6a488035
TO
222
223 // Log in using webtestLogin() method
224 $this->webtestLogin();
225
226 // We need a payment processor
227 $processorName = "Webtest Dummy" . substr(sha1(rand()), 0, 7);
228 $this->webtestAddPaymentProcessor($processorName);
229
071a6d2e 230 $this->openCiviPage("event/add", "reset=1&action=add");
6a488035
TO
231
232 $eventTitle = 'My Conference - ' . substr(sha1(rand()), 0, 7);
233 $eventDescription = "Here is a description for this conference.";
234 // Select paid online registration template.
235 $templateID = 6;
236 $eventTypeID = 1;
237 $this->_testAddEventInfoFromTemplate($eventTitle, $eventDescription, $templateID, $eventTypeID);
238
239 $streetAddress = "100 Main Street";
240 $this->_testAddLocation($streetAddress);
241
242 $this->_testAddFees(FALSE, FALSE, $processorName);
243
244 // intro text for registration page
245 $registerIntro = "Fill in all the fields below and click Continue.";
246 $this->_testAddOnlineRegistration($registerIntro);
247
248 // $eventInfoStrings = array( $eventTitle, $eventDescription, $streetAddress );
249 $eventInfoStrings = array($eventTitle, $streetAddress);
250 $this->_testVerifyEventInfo($eventTitle, $eventInfoStrings);
251
252 $registerStrings = array("225.00", "Member", "300.00", "Non-member", $registerIntro);
253 $this->_testVerifyRegisterPage($registerStrings);
254 }
255
256 function testAddFreeEventWithTemplate() {
6a488035
TO
257
258 // Log in using webtestLogin() method
259 $this->webtestLogin();
42daf119 260
071a6d2e 261 $this->openCiviPage("event/add", "reset=1&action=add");
76e86fd8 262
6a488035
TO
263 $eventTitle = 'My Free Meeting - ' . substr(sha1(rand()), 0, 7);
264 $eventDescription = "Here is a description for this free meeting.";
265 // Select "Free Meeting with Online Registration" template (id = 5).
266 $templateID = 5;
76e86fd8
CW
267 $eventTypeID = 4;
268
6a488035 269 $this->_testAddEventInfoFromTemplate($eventTitle, $eventDescription, $templateID, $eventTypeID);
76e86fd8
CW
270
271 $streetAddress = "100 Main Street";
272
273 $this->_testAddLocation($streetAddress);
6a488035
TO
274
275 // Go to Fees tab and check that Paid Event is false (No)
276 $this->click("link=Fees");
277 $this->waitForElementPresent("_qf_Fee_upload-bottom");
278 $this->verifyChecked("CIVICRM_QFID_0_is_monetary");
279
280 // intro text for registration page
281 $registerIntro = "Fill in all the fields below and click Continue.";
282 $this->_testAddOnlineRegistration($registerIntro);
283
284 // $eventInfoStrings = array( $eventTitle, $eventDescription, $streetAddress );
285 $eventInfoStrings = array($eventTitle, $streetAddress);
286 $this->_testVerifyEventInfo($eventTitle, $eventInfoStrings);
287
288 $registerStrings = array($registerIntro);
289 $this->_testVerifyRegisterPage($registerStrings);
290 // make sure paid_event div is NOT present since this is a free event
291 $this->verifyElementNotPresent("css=div.paid_event-section");
292 }
293
0dce9149 294 function testUnpaidPaid() {
0dce9149
PJ
295
296 // Log in using webtestLogin() method
297 $this->webtestLogin();
298
071a6d2e 299 $this->openCiviPage("event/add", "reset=1&action=add");
0dce9149
PJ
300 $eventTitle = 'My Conference - ' . substr(sha1(rand()), 0, 7);
301 $eventDescription = "Here is a description for this conference.";
302 $this->_testAddEventInfo($eventTitle, $eventDescription);
303
304 //add fee section with pay later checked
305 $this->_testAddFees(FALSE, FALSE, NULL, FALSE, TRUE);
306
307 //make the event unpaid
308 $this->waitForElementPresent("_qf_Fee_upload-bottom");
309 $this->assertChecked('is_pay_later');
310 $this->click("CIVICRM_QFID_0_is_monetary");
ef72146d 311 $this->clickLink("_qf_Fee_upload-bottom", "_qf_Fee_upload-bottom");
0dce9149
PJ
312
313 //check if pay later option is disabled
314 $this->click('CIVICRM_QFID_1_is_monetary');
0dce9149
PJ
315 $this->waitForElementPresent('is_pay_later');
316 $this->assertNotChecked('is_pay_later');
317 }
318
c4e6d4e8
PJ
319 function testAjaxCustomGroupLoad() {
320 $this->webtestLogin();
321
322 $triggerElement = array('name' => 'event_type_id', 'type' => 'select');
323 $customSets = array(
324 array('entity' => 'Event', 'subEntity' => 'Conference', 'triggerElement' => $triggerElement),
325 );
326
327 $pageUrl = array('url' => 'event/add', 'args' => "reset=1&action=add");
328 $this->customFieldSetLoadOnTheFlyCheck($customSets, $pageUrl);
329 }
330
6a488035 331 function _testAddEventInfo($eventTitle, $eventDescription) {
6a488035
TO
332 $this->waitForElementPresent("_qf_EventInfo_upload-bottom");
333
6a488035
TO
334 $this->select("event_type_id", "value=1");
335
336 // Attendee role s/b selected now.
337 $this->select("default_role_id", "value=1");
338
339 // Enter Event Title, Summary and Description
340 $this->type("title", $eventTitle);
341 $this->type("summary", "This is a great conference. Sign up now!");
342
343 // Type description in ckEditor (fieldname, text to type, editor)
344 $this->fillRichTextField("description", $eventDescription, 'CKEditor');
345
346 // Choose Start and End dates.
347 // Using helper webtestFillDate function.
348 $this->webtestFillDateTime("start_date", "+1 week");
349 $this->webtestFillDateTime("end_date", "+1 week 1 day 8 hours ");
350
351 $this->type("max_participants", "50");
352 $this->click("is_map");
353 $this->click("is_public");
354 $this->click("_qf_EventInfo_upload-bottom");
0dce9149 355 $this->waitForPageToLoad($this->getTimeoutMsec());
6a488035
TO
356 }
357
358 function _testAddEventInfoFromTemplate($eventTitle, $eventDescription, $templateID, $eventTypeID) {
6a488035 359 $this->waitForElementPresent("_qf_EventInfo_upload-bottom");
42daf119 360
6a488035 361 // Select event template. Use option value, not label - since labels can be translated and test would fail
76e86fd8 362 $this->select("template_id", "value={$templateID}");
6a488035
TO
363
364 // Wait for event type to be filled in (since page reloads)
365 $this->waitForPageToLoad($this->getTimeoutMsec());
76e86fd8 366 $this->verifySelectedValue("event_type_id", $eventTypeID);
6a488035
TO
367
368 // Attendee role s/b selected now.
369 $this->verifySelectedValue("default_role_id", "1");
76e86fd8 370
6a488035 371 // Enter Event Title, Summary and Description
76e86fd8
CW
372 $this->type("title", $eventTitle);
373
6a488035
TO
374 $this->type("summary", "This is a great conference. Sign up now!");
375
376 // Type description in ckEditor (fieldname, text to type, editor)
377 $this->fillRichTextField("description", $eventDescription, 'CKEditor');
378
379 // Choose Start and End dates.
380 // Using helper webtestFillDate function.
381 $this->webtestFillDateTime("start_date", "+1 week");
382 $this->webtestFillDateTime("end_date", "+1 week 1 day 8 hours ");
383
384 $this->type("max_participants", "50");
385 $this->click("is_map");
76e86fd8
CW
386 $this->click("_qf_EventInfo_upload-bottom");
387
6a488035
TO
388 }
389
390 function _testAddLocation($streetAddress) {
391 // Wait for Location tab form to load
392 $this->waitForPageToLoad($this->getTimeoutMsec());
393 $this->waitForElementPresent("_qf_Location_upload-bottom");
394
395 // Fill in address fields
396 $streetAddress = "100 Main Street";
397 $this->type("address_1_street_address", $streetAddress);
398 $this->type("address_1_city", "San Francisco");
399 $this->type("address_1_postal_code", "94117");
400 $this->select("address_1_state_province_id", "value=1004");
401 $this->type("email_1_email", "info@civicrm.org");
402
403 $this->click("_qf_Location_upload-bottom");
404
405 // Wait for "saved" status msg
406 $this->waitForPageToLoad($this->getTimeoutMsec());
407 $this->waitForTextPresent("'Location' information has been saved.");
408 }
409
0dce9149 410 function _testAddFees($discount = FALSE, $priceSet = FALSE, $processorName = "PP Pro", $double = FALSE, $payLater = FALSE) {
6a488035
TO
411 $discount1 = "Early-bird" . substr(sha1(rand()), 0, 7);
412 $discount2 = "";
413 // Go to Fees tab
414 $this->click("link=Fees");
415 $this->waitForElementPresent("_qf_Fee_upload-bottom");
416 $this->click("CIVICRM_QFID_1_is_monetary");
0dce9149
PJ
417
418 if ($payLater) {
419 $this->check('is_pay_later');
420 $this->type('pay_later_receipt', 'testing later instructions');
421 }
422 else {
423 $this->uncheck('is_pay_later');
424 }
425
426 if ($processorName) {
427 $this->click("xpath=//tr[@class='crm-event-manage-fee-form-block-payment_processor']/td[2]/label[text()='$processorName']");
428 }
6a488035
TO
429 $this->select("financial_type_id", "value=4");
430 if ($priceSet) {
431 // get one - TBD
432 }
433 else {
434 $this->type("label_1", "Member");
435 $this->type("value_1", "225.00");
436 $this->type("label_2", "Non-member");
437 $this->type("value_2", "300.00");
438 $this->click("CIVICRM_QFID_1_4");
439 }
440
441 if ($discount) {
442 // enter early bird discount fees
443 $this->click("is_discount");
444 $this->waitForElementPresent("discount_name_1");
445 $this->type("discount_name_1", $discount1);
446 $this->webtestFillDate("discount_start_date_1", "-3 week");
447 $this->webtestFillDate("discount_end_date_1", "-2 week");
76e86fd8
CW
448 $this->clickLink("_qf_Fee_submit", "discounted_value_1_1");
449
6a488035
TO
450 $this->type("discounted_value_1_1","225.00");
451 $this->type("discounted_value_2_1","300.00");
452
453 if ($double) {
454 $discount2 = "Early-bird" . substr(sha1(rand()), 0, 7);
455 // enter early bird discount fees
456 $this->click("link=another discount set");
457 $this->waitForElementPresent("discount_name_2");
458 $this->type("discount_name_2", $discount2);
459 $this->webtestFillDate("discount_start_date_2", "-1 week");
460 $this->webtestFillDate("discount_end_date_2", "+1 week");
225a8648 461 $this->clickLink("_qf_Fee_submit", "discounted_value_2_1");
6a488035
TO
462 $this->type("discounted_value_1_2","225.00");
463 $this->type("discounted_value_2_2","300.00");
464 }
465 $this->click("xpath=//fieldset[@id='discount']/fieldset/table/tbody/tr[2]/td[3]/input");
466 }
467 $this->click("_qf_Fee_upload-bottom");
76e86fd8 468
6a488035
TO
469 // Wait for "saved" status msg
470 $this->waitForPageToLoad($this->getTimeoutMsec());
6c5f7368 471 $this->waitForText('crm-notification-container', "'Fee' information has been saved");
6a488035
TO
472 return array($discount1, $discount2);
473 }
474
475 function _testAddOnlineRegistration($registerIntro, $multipleRegistrations = FALSE) {
476 // Go to Online Registration tab
477 $this->click("link=Online Registration");
478 $this->waitForElementPresent("_qf_Registration_upload-bottom");
479
480 $this->check("is_online_registration");
481 $this->assertChecked("is_online_registration");
482 if ($multipleRegistrations) {
483 $this->check("is_multiple_registrations");
484 $this->assertChecked("is_multiple_registrations");
485 }
486
487 $this->fillRichTextField("intro_text", $registerIntro);
76e86fd8 488
6a488035
TO
489 // enable confirmation email
490 $this->click("CIVICRM_QFID_1_is_email_confirm");
76e86fd8
CW
491 $this->type("confirm_from_name", "Jane Doe");
492
6a488035
TO
493 $this->type("confirm_from_email", "jane.doe@example.org");
494
495 $this->click("_qf_Registration_upload-bottom");
496 $this->waitForPageToLoad($this->getTimeoutMsec());
497 $this->waitForTextPresent("'Registration' information has been saved.");
498 }
499
500 function _testVerifyEventInfo($eventTitle, $eventInfoStrings, $eventFees = NULL) {
501 // verify event input on info page
502 // start at Manage Events listing
071a6d2e 503 $this->openCiviPage("event/manage", "reset=1");
6a488035
TO
504 $this->click("link=$eventTitle");
505
506 // Look for Register button
507 $this->waitForElementPresent("link=Register Now");
508
509 // Check for correct event info strings
510 $this->assertStringsPresent($eventInfoStrings);
76e86fd8 511
6a488035
TO
512 // Optionally verify event fees (especially for discounts)
513 if ($eventFees) {
76e86fd8
CW
514 $this->assertStringsPresent($eventFees);
515
6a488035 516 }
a471a3b6 517 return $this->urlArg('id');
6a488035
TO
518 }
519
520 function _testVerifyRegisterPage($registerStrings) {
521 // Go to Register page and check for intro text and fee levels
522 $this->click("link=Register Now");
523 $this->waitForElementPresent("_qf_Register_upload-bottom");
524 $this->assertStringsPresent($registerStrings);
525 return $this->getLocation();
526 }
527
dc91d100
PJ
528 function _testOnlineRegistration($registerUrl, $numberRegistrations = 1, $anonymous = TRUE, $isPayLater = FALSE, $participantEmailInfo = array(), $paymentProcessor = NULL) {
529 $infoPassed = FALSE;
530 if (!empty($participantEmailInfo)) {
531 $infoPassed = TRUE;
532 }
6a488035 533 if ($anonymous) {
42daf119 534 $this->webtestLogout();
6a488035 535 }
4a2859ea 536 $primaryParticipantInfo = array();
6a488035 537 $this->open($registerUrl);
dc91d100
PJ
538 $this->waitForPageToLoad($this->getTimeoutMsec());
539
6a488035 540 $this->select("additional_participants", "value=" . $numberRegistrations);
dc91d100
PJ
541
542 $email = $infoPassed ? $participantEmailInfo[0] : "smith" . substr(sha1(rand()), 0, 7) . "@example.org";
4a2859ea 543 $primaryParticipantInfo['email'] = $email;
dc91d100 544 $this->type("email-Primary", $email);
f9057553 545 if (!$isPayLater) {
dc91d100
PJ
546 if ($paymentProcessor) {
547 $paymentProcessorEle = $this->getAttribute("xpath=//form[@id='Register']//label[contains(text(), '{$paymentProcessor}')]/@for");
548 $this->check($paymentProcessorEle);
549 }
f9057553
PN
550 $this->select("credit_card_type", "value=Visa");
551 $this->type("credit_card_number", "4111111111111111");
552 $this->type("cvv2", "000");
553 $this->select("credit_card_exp_date[M]", "value=1");
554 $this->select("credit_card_exp_date[Y]", "value=2020");
4a2859ea
PJ
555 $primaryParticipantInfo['first_name'] = "Jane";
556 $primaryParticipantInfo['last_name'] = "Smith" . substr(sha1(rand()), 0, 7);
557 $this->type("billing_first_name", $primaryParticipantInfo['first_name']);
558 $this->type("billing_last_name", $primaryParticipantInfo['last_name']);
f9057553
PN
559 $this->type("billing_street_address-5", "15 Main St.");
560 $this->type(" billing_city-5", "San Jose");
561 $this->select("billing_country_id-5", "value=1228");
562 $this->select("billing_state_province_id-5", "value=1004");
563 $this->type("billing_postal_code-5", "94129");
564 }
6a488035
TO
565
566 $this->click("_qf_Register_upload-bottom");
567
568 if ($numberRegistrations > 1) {
569 for ($i = 1; $i <= $numberRegistrations; $i++) {
570 $this->waitForPageToLoad($this->getTimeoutMsec());
571 // Look for Skip button
572 $this->waitForElementPresent("_qf_Participant_{$i}_next_skip-Array");
dc91d100
PJ
573 $addtlEmail = $infoPassed ? $participantEmailInfo[$i] : "smith" . substr(sha1(rand()), 0, 7) . "@example.org";
574 $this->type("email-Primary", $addtlEmail);
6a488035
TO
575 $this->click("_qf_Participant_{$i}_next");
576 }
577 }
578
579 $this->waitForPageToLoad($this->getTimeoutMsec());
580 $this->waitForElementPresent("_qf_Confirm_next-bottom");
f9057553
PN
581 $confirmStrings = array("Event Fee(s)");
582 if (!$isPayLater) {
583 $confirmStrings += array("Billing Name and Address", "Credit Card Information");
584 }
6a488035
TO
585 $this->assertStringsPresent($confirmStrings);
586 $this->click("_qf_Confirm_next-bottom");
587 $this->waitForPageToLoad($this->getTimeoutMsec());
f9057553
PN
588 $thankStrings = array("Thank You for Registering", "Event Total");
589 if (!$isPayLater) {
590 $thankStrings = array("Transaction Date");
591 }
592 else {
593 $thankStrings += array("testing later instructions");
594 }
6a488035 595 $this->assertStringsPresent($thankStrings);
4a2859ea 596 return $primaryParticipantInfo;
6a488035
TO
597 }
598
599 function _testAddReminder($eventTitle) {
600 // Go to Schedule Reminders tab
601 $this->click('css=li#tab_reminder a');
602 $this->waitForElementPresent("_qf_ScheduleReminders_upload-bottom");
603 $this->type("title", "Event Reminder for " . $eventTitle);
604 $this->select('entity', 'label=Registered');
605
606 $this->select('start_action_offset', 'label=1');
607 $this->select('start_action_condition', 'label=after');
608 $this->click('is_repeat');
609 $this->select('repetition_frequency_interval', 'label=2');
610 $this->select('end_date', 'label=Event End Date');
611 $this->click('recipient');
612 $this->select('recipient', 'label=Participant Role');
613 // $this->select( 'recipient_listing', 'value=1' );
614
615 // Fill Subject
616 $subject = 'subject' . substr(sha1(rand()), 0, 4);
617 $this->type('subject', $subject);
618 $this->fillRichTextField("html_message", "This is the test HTML version here!!!", 'CKEditor');
619
620 $this->type("text_message", "This is the test text version here!!!");
621 //click on save
622 $this->click('_qf_ScheduleReminders_upload-bottom');
623 $this->waitForElementPresent("link=Add Reminder");
624
625 $this->waitForElementPresent("link=Edit");
626
627 $verifyText = array(
628 1 => 'Event Reminder for ' . $eventTitle,
629 3 => '1 hour after Event Start Date',
630 4 => 'Registered',
631 5 => 'Yes',
632 6 => 'Yes',
633 );
634
635 //verify the fields for Event Reminder selector
636 foreach ($verifyText as $key => $value) {
637 $this->verifyText("xpath=//table[@class='display']/tbody/tr/td[$key]", $value);
638 }
639 }
640
f9057553
PN
641 function testEventAddMultipleParticipant() {
642 // Log in using webtestLogin() method
4a2859ea 643 $this->webtestLogin();
f9057553
PN
644 $this->openCiviPage("event/add", "reset=1&action=add");
645
646 $eventTitle = 'My Conference - ' . substr(sha1(rand()), 0, 7);
647 $eventDescription = "Here is a description for this conference.";
648 $this->_testAddEventInfo($eventTitle, $eventDescription);
649 $streetAddress = "100 Main Street";
650 $this->_testAddLocation($streetAddress);
651
dc91d100 652 $this->_testAddFees(FALSE, FALSE, "Test Processor", FALSE, TRUE);
f9057553
PN
653 $registerIntro = "Fill in all the fields below and click Continue.";
654 $multipleRegistrations = TRUE;
655 $this->_testAddOnlineRegistration($registerIntro, $multipleRegistrations);
656 $eventInfoStrings = array($eventTitle, $eventDescription, $streetAddress);
dc91d100 657 $eventId = $this->_testVerifyEventInfo($eventTitle, $eventInfoStrings);
f9057553
PN
658
659 $registerStrings = array("225.00", "Member", "300.00", "Non-member", $registerIntro);
660 $registerUrl = $this->_testVerifyRegisterPage($registerStrings);
f9057553
PN
661 $numberRegistrations = 3;
662 $anonymous = TRUE;
dc91d100
PJ
663
664 // CRM-12615 add additional participants and check email, amount
665 $primaryParticipant = "smith" . substr(sha1(rand()), 0, 7) . "@example.org";
666 $secParticipant = "smith" . substr(sha1(rand()), 0, 7) . "@example.org";
667 $thirdParticipant = "smith" . substr(sha1(rand()), 0, 7) . "@example.org";
668 $participantEmails = array($primaryParticipant, $secParticipant, $thirdParticipant);
4a2859ea
PJ
669 $addtlPart = array($secParticipant, $thirdParticipant);
670 $primaryParticipantInfo = $this->_testOnlineRegistration($registerUrl, 2, $anonymous, FALSE, $participantEmails, "Test Processor");
671 $primaryDisplayName = "{$primaryParticipantInfo['first_name']} {$primaryParticipantInfo['last_name']}";
dc91d100
PJ
672 $this->webtestLogin();
673 $this->openCiviPage("event/search?reset=1", "reset=1");
674 $this->type('event_name', $eventTitle);
675 $this->click("event_name");
676 $this->waitForElementPresent("css=div.ac_results-inner li");
677 $this->click("css=div.ac_results-inner li");
678 $this->clickLink('_qf_Search_refresh');
679 $this->verifyText("xpath=//div[@id='participantSearch']/table/tbody//tr/td[3]/a[contains(text(), '{$secParticipant}')]/../../td[6]", preg_quote('225.00'));
680 $this->verifyText("xpath=//div[@id='participantSearch']/table/tbody//tr/td[3]/a[contains(text(), '{$thirdParticipant}')]/../../td[6]", preg_quote('225.00'));
4a2859ea
PJ
681
682 //CRM-12618 check edit screen of additional participant and ensuring record_contribution not present
683 foreach ($addtlPart as $value) {
684 $this->clickLink("xpath=//div[@id='participantSearch']/table/tbody//tr/td[3]/a[contains(text(), '{$value}')]/../../td[11]/span/a[2][contains(text(), 'Edit')]", '_qf_Participant_upload-bottom');
685 $this->assertTrue($this->isElementPresent("xpath=//tr[@class='crm-participant-form-block-registered-by']/td[2]/a[contains(text(), '$primaryDisplayName')]"), 'Registered By info is wrong on additional participant edit form');
686 $this->assertElementContainsText("xpath=//form[@id='Participant']/h3", 'Edit Event Registration');
687 $this->assertTrue($this->isElementPresent("xpath=//table/tbody/tr[@class='crm-participant-form-block-displayName']/td[2][contains(text(), '{$value}')]"),
688 'Wrong Participant edit form'
689 );
690 $this->assertFalse($this->isElementPresent('record_contribution'), 'Record Payment checkbox showed up wrongly for additional participant edit screen');
691 $this->clickLink("_qf_Participant_cancel-top");
692 }
693
dc91d100
PJ
694 //unselect the payment processor configured
695 $this->openCiviPage("event/manage/fee", "reset=1&action=update&id={$eventId}", '_qf_Fee_upload-bottom');
696 $this->click("xpath=//tr[@class='crm-event-manage-fee-form-block-payment_processor']/td[2]/label[text()='Test Processor']");
697 $this->clickLink("_qf_Fee_upload-bottom");
698
f9057553
PN
699 // add participant and 3 additional participant and change status of participant from edit participant
700 $this->_testOnlineRegistration($registerUrl, $numberRegistrations, $anonymous, TRUE);
dc91d100 701 $this->webtestLogin();
f9057553
PN
702
703 $this->openCiviPage("event/search?reset=1", "reset=1");
704 $this->type('event_name', $eventTitle);
705 $this->click("event_name");
706 $this->waitForElementPresent("css=div.ac_results-inner li");
707 $this->click("css=div.ac_results-inner li");
708 $this->click("xpath=//td[@class='crm-event-form-block-participant_status']/div[@class='listing-box']//div/label[text()='Pending from pay later']");
709 $this->click('_qf_Search_refresh');
710 $this->waitForPageToLoad($this->getTimeoutMsec());
711 $this->click("xpath=//div[@id='participantSearch']/table/tbody//tr/td[11]/span/a[text()='Edit']");
712 $this->waitForPageToLoad($this->getTimeoutMsec());
713 $this->select('status_id', 'label=Registered');
714 $this->click('record_contribution');
715 $this->select('contribution_status_id', 'label=Completed');
716 $pID = $this->urlArg('id');
717 $contributionID = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $pID, 'contribution_id', 'participant_id');
718 $this->click('_qf_Participant_upload-top');
719 $this->waitForPageToLoad($this->getTimeoutMsec());
720 $this->verifyFinancialRecords($contributionID);
4a2859ea 721
f9057553
PN
722 // add participant and 3 additional participant and change status of participant from edit contribution
723 $this->_testOnlineRegistration($registerUrl, $numberRegistrations, $anonymous, TRUE);
724 $this->webtestLogin();
725
726 $this->openCiviPage("event/search?reset=1", "reset=1"); $this->type('event_name', $eventTitle);
727 $this->click("event_name");
728 $this->waitForElementPresent("css=div.ac_results-inner li");
729 $this->click("css=div.ac_results-inner li");
730 $this->click("xpath=//td[@class='crm-event-form-block-participant_status']/div[@class='listing-box']//div/label[text()='Pending from pay later']");
731 $this->click('_qf_Search_refresh');
732 $this->waitForPageToLoad($this->getTimeoutMsec());
733 $this->click("xpath=//div[@id='participantSearch']/table/tbody//tr/td[11]/span/a[text()='View']");
734 $this->waitForPageToLoad($this->getTimeoutMsec());
735 $pID = $this->urlArg('id');
736 $contributionID = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $pID, 'contribution_id', 'participant_id');
737 $this->click("xpath=//tr[@id='rowid$contributionID']/td[8]/span//a[text()='Edit']");
738 $this->waitForPageToLoad($this->getTimeoutMsec());
739 $this->select('contribution_status_id', 'label=Completed');
740 $this->click('_qf_Contribution_upload-bottom');
741 $this->waitForPageToLoad($this->getTimeoutMsec());
742 $this->verifyFinancialRecords($contributionID);
743 }
744
745 function verifyFinancialRecords($contributionID) {
746 // check count for civicrm_contribution and civicrm_financial_item in civicrm_entity_financial_trxn
747 $query = "SELECT COUNT(DISTINCT(c1.id)) civicrm_contribution, COUNT(c2.id) civicrm_financial_item FROM civicrm_entity_financial_trxn c1
748LEFT JOIN civicrm_entity_financial_trxn c2 ON c1.financial_trxn_id = c2.financial_trxn_id AND c2.entity_table ='civicrm_financial_item'
749LEFT JOIN civicrm_financial_item cfi ON cfi.id = c2.entity_id
750WHERE c1.entity_table = 'civicrm_contribution' AND c1.entity_id = %1 AND cfi.status_id = 1";
751 $params = array(1 => array($contributionID, 'Integer'));
752 $dao = CRM_Core_DAO::executeQuery($query, $params);
753 $dao->fetch();
754 $this->assertEquals('2', $dao->civicrm_contribution, 'civicrm_financial_trxn count does not match');
755 $this->assertEquals('8',$dao->civicrm_financial_item, 'civicrm_financial_item count does not match');
756 $query = "SELECT COUNT(cft.id) civicrm_financial_trxn FROM civicrm_entity_financial_trxn ceft
757INNER JOIN civicrm_financial_trxn cft ON ceft.financial_trxn_id = cft.id
758WHERE ceft.entity_id = %1 AND ceft.entity_table = 'civicrm_contribution'";
759 $dao = CRM_Core_DAO::executeQuery($query, $params);
760 $dao->fetch();
761 $this->assertEquals('2', $dao->civicrm_financial_trxn, 'civicrm_financial_trxn count does not match');
762 }
42daf119 763}