CRM-14043 - cid=0 contribution form giving contribution to logged in user
[civicrm-core.git] / tests / phpunit / WebTest / Event / AddEventTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License along with this program; if not, contact CiviCRM LLC |
21 | at info[AT]civicrm[DOT]org. If you have questions about the |
22 | GNU Affero General Public License or the licensing of CiviCRM, |
23 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
24 +--------------------------------------------------------------------+
25 */
26
27 require_once 'CiviTest/CiviSeleniumTestCase.php';
28 class WebTest_Event_AddEventTest extends CiviSeleniumTestCase {
29
30 protected function setUp() {
31 parent::setUp();
32 }
33
34 function testAddPaidEventNoTemplate() {
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
42 $this->openCiviPage("event/add", "reset=1&action=add");
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);
61 $eventId = $this->_testVerifyEventInfo($eventTitle, $eventInfoStrings);
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);
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 $this->_testVerifyEventInfo('Copy of ' . $eventTitle, $eventInfoStrings);
74 $this->_testVerifyRegisterPage($registerStrings);
75 }
76
77 function testAddPaidEventDiscount() {
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
86 $this->openCiviPage("event/add", "reset=1&action=add");
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
104 $discountFees = array("225.00", "300.00");
105
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() {
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
126 $this->openCiviPage("event/add", "reset=1&action=add");
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
143 $discountFees = array("225.00", "300.00");
144
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
152 $this->openCiviPage("event/manage/fee", "reset=1&action=update&id=$id", "_qf_Fee_upload-bottom");
153 $this->click("xpath=//a[@id='quickconfig']");
154 $this->waitForElementPresent('popupContainer');
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
158 sleep(3);
159 $this->click("xpath=//div[@class='ui-dialog-buttonset']/button[1]");
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
163 sleep(3);
164
165 //Assert quick config change and discount deletion
166 $this->openCiviPage("admin/price", "reset=1");
167 $this->assertStringsPresent($discount);
168 }
169
170 function testAddDeleteEventDiscount() {
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
179 $this->openCiviPage("event/add", "reset=1&action=add");
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
196 $discountFees = array("225.00", "300.00");
197
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) {
208 $this->openCiviPage("event/manage/fee", "reset=1&action=update&id=$id", "_qf_Fee_upload-bottom");
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");
215 $this->waitForPageToLoad();
216 //Assertions
217 $this->openCiviPage("admin/price", "reset=1");
218 $this->assertStringsPresent($discount[1]);
219 }
220
221 function testAddPaidEventWithTemplate() {
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
230 $this->openCiviPage("event/add", "reset=1&action=add");
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() {
257
258 // Log in using webtestLogin() method
259 $this->webtestLogin();
260
261 $this->openCiviPage("event/add", "reset=1&action=add");
262
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;
267 $eventTypeID = 4;
268
269 $this->_testAddEventInfoFromTemplate($eventTitle, $eventDescription, $templateID, $eventTypeID);
270
271 $streetAddress = "100 Main Street";
272
273 $this->_testAddLocation($streetAddress);
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
294 function testUnpaidPaid() {
295 // Log in using webtestLogin() method
296 $this->webtestLogin();
297
298 $this->openCiviPage("event/add", "reset=1&action=add");
299 $eventTitle = 'My Conference - ' . substr(sha1(rand()), 0, 7);
300 $eventDescription = "Here is a description for this conference.";
301 $this->_testAddEventInfo($eventTitle, $eventDescription);
302
303 //add fee section with pay later checked
304 $this->_testAddFees(FALSE, FALSE, NULL, FALSE, TRUE);
305
306 //make the event unpaid
307 $this->waitForElementPresent("_qf_Fee_upload-bottom");
308 $this->assertChecked('is_pay_later');
309 $this->click("CIVICRM_QFID_0_is_monetary");
310 $this->clickLink("_qf_Fee_upload-bottom", "_qf_Fee_upload-bottom");
311
312 //check if pay later option is disabled
313 $this->click('CIVICRM_QFID_1_is_monetary');
314 $this->waitForElementPresent('is_pay_later');
315 $this->assertNotChecked('is_pay_later');
316 }
317
318 function testAjaxCustomGroupLoad() {
319 $this->webtestLogin();
320
321 $triggerElement = array('name' => 'event_type_id', 'type' => 'select');
322 $customSets = array(
323 array('entity' => 'Event', 'subEntity' => 'Conference', 'triggerElement' => $triggerElement),
324 );
325
326 $pageUrl = array('url' => 'event/add', 'args' => "reset=1&action=add");
327 $this->customFieldSetLoadOnTheFlyCheck($customSets, $pageUrl);
328 }
329
330 function _testAddEventInfo($eventTitle, $eventDescription) {
331 $this->waitForElementPresent("_qf_EventInfo_upload-bottom");
332
333 $this->select("event_type_id", "value=1");
334
335 // Attendee role s/b selected now.
336 $this->select("default_role_id", "value=1");
337
338 // Enter Event Title, Summary and Description
339 $this->type("title", $eventTitle);
340 $this->type("summary", "This is a great conference. Sign up now!");
341
342 // Type description in ckEditor (fieldname, text to type, editor)
343 $this->fillRichTextField("description", $eventDescription, 'CKEditor');
344
345 // Choose Start and End dates.
346 // Using helper webtestFillDate function.
347 $this->webtestFillDateTime("start_date", "+1 week");
348 $this->webtestFillDateTime("end_date", "+1 week 1 day 8 hours ");
349
350 $this->type("max_participants", "50");
351 $this->click("is_map");
352 $this->click("is_public");
353 $this->click("_qf_EventInfo_upload-bottom");
354 $this->waitForPageToLoad($this->getTimeoutMsec());
355 }
356
357 function _testAddEventInfoFromTemplate($eventTitle, $eventDescription, $templateID, $eventTypeID) {
358 $this->waitForElementPresent("_qf_EventInfo_upload-bottom");
359
360 // Select event template. Use option value, not label - since labels can be translated and test would fail
361 $this->select("template_id", "value={$templateID}");
362
363 // Wait for event type to be filled in (since page reloads)
364 $this->waitForPageToLoad($this->getTimeoutMsec());
365 $this->verifySelectedValue("event_type_id", $eventTypeID);
366
367 // Attendee role s/b selected now.
368 $this->verifySelectedValue("default_role_id", "1");
369
370 // Enter Event Title, Summary and Description
371 $this->type("title", $eventTitle);
372
373 $this->type("summary", "This is a great conference. Sign up now!");
374
375 // Type description in ckEditor (fieldname, text to type, editor)
376 $this->fillRichTextField("description", $eventDescription, 'CKEditor');
377
378 // Choose Start and End dates.
379 // Using helper webtestFillDate function.
380 $this->webtestFillDateTime("start_date", "+1 week");
381 $this->webtestFillDateTime("end_date", "+1 week 1 day 8 hours ");
382
383 $this->type("max_participants", "50");
384 $this->click("is_map");
385 $this->click("_qf_EventInfo_upload-bottom");
386
387 }
388
389 function _testAddLocation($streetAddress) {
390 // Wait for Location tab form to load
391 $this->waitForPageToLoad($this->getTimeoutMsec());
392 $this->waitForElementPresent("_qf_Location_upload-bottom");
393
394 // Fill in address fields
395 $streetAddress = "100 Main Street";
396 $this->type("address_1_street_address", $streetAddress);
397 $this->type("address_1_city", "San Francisco");
398 $this->type("address_1_postal_code", "94117");
399 $this->select("address_1_state_province_id", "value=1004");
400 $this->type("email_1_email", "info@civicrm.org");
401
402 $this->click("_qf_Location_upload-bottom");
403
404 // Wait for "saved" status msg
405 $this->waitForPageToLoad($this->getTimeoutMsec());
406 $this->waitForTextPresent("'Location' information has been saved.");
407 }
408
409 function _testAddFees($discount = FALSE, $priceSet = FALSE, $processorName = "PP Pro", $double = FALSE, $payLater = FALSE) {
410 $discount1 = "Early-bird" . substr(sha1(rand()), 0, 7);
411 $discount2 = "";
412 // Go to Fees tab
413 $this->click("link=Fees");
414 $this->waitForElementPresent("_qf_Fee_upload-bottom");
415 $this->click("CIVICRM_QFID_1_is_monetary");
416
417 if ($payLater) {
418 $this->check('is_pay_later');
419 $this->fillRichTextField('pay_later_receipt', 'testing later instructions');
420 }
421 else {
422 $this->uncheck('is_pay_later');
423 }
424
425 if ($processorName) {
426 $this->click("xpath=//tr[@class='crm-event-manage-fee-form-block-payment_processor']/td[2]/label[text()='$processorName']");
427 }
428 $this->select("financial_type_id", "value=4");
429 if ($priceSet) {
430 // get one - TBD
431 }
432 else {
433 $this->type("label_1", "Member");
434 $this->type("value_1", "225.00");
435 $this->type("label_2", "Non-member");
436 $this->type("value_2", "300.00");
437 $this->click("CIVICRM_QFID_1_4");
438 }
439
440 if ($discount) {
441 // enter early bird discount fees
442 $this->click("is_discount");
443 $this->waitForElementPresent("discount_name_1");
444 $this->type("discount_name_1", $discount1);
445 $this->webtestFillDate("discount_start_date_1", "-3 week");
446 $this->webtestFillDate("discount_end_date_1", "-2 week");
447 $this->clickLink("_qf_Fee_submit", "discounted_value_1_1");
448
449 $this->type("discounted_value_1_1", "225.00");
450 $this->type("discounted_value_2_1", "300.00");
451
452 if ($double) {
453 $discount2 = "Early-bird" . substr(sha1(rand()), 0, 7);
454 // enter early bird discount fees
455 $this->click("link=another discount set");
456 $this->waitForElementPresent("discount_name_2");
457 $this->type("discount_name_2", $discount2);
458 $this->webtestFillDate("discount_start_date_2", "-1 week");
459 $this->webtestFillDate("discount_end_date_2", "+1 week");
460 $this->clickLink("_qf_Fee_submit", "discounted_value_2_1");
461 $this->type("discounted_value_1_2", "225.00");
462 $this->type("discounted_value_2_2", "300.00");
463 }
464 $this->click("xpath=//fieldset[@id='discount']/fieldset/table/tbody/tr[2]/td[3]/input");
465 }
466 $this->click("_qf_Fee_upload-bottom");
467
468 // Wait for "saved" status msg
469 $this->waitForPageToLoad($this->getTimeoutMsec());
470 $this->waitForText('crm-notification-container', "'Fee' information has been saved");
471 return array($discount1, $discount2);
472 }
473
474 function _testAddOnlineRegistration($registerIntro, $multipleRegistrations = FALSE) {
475 // Go to Online Registration tab
476 $this->click("link=Online Registration");
477 $this->waitForElementPresent("_qf_Registration_upload-bottom");
478
479 $this->check("is_online_registration");
480 $this->assertChecked("is_online_registration");
481 if ($multipleRegistrations) {
482 $this->check("is_multiple_registrations");
483 $this->assertChecked("is_multiple_registrations");
484 }
485
486 $this->fillRichTextField("intro_text", $registerIntro);
487
488 // enable confirmation email
489 $this->click("CIVICRM_QFID_1_is_email_confirm");
490 $this->type("confirm_from_name", "Jane Doe");
491
492 $this->type("confirm_from_email", "jane.doe@example.org");
493
494 $this->click("_qf_Registration_upload-bottom");
495 $this->waitForPageToLoad($this->getTimeoutMsec());
496 $this->waitForTextPresent("'Registration' information has been saved.");
497 }
498
499 function _testVerifyEventInfo($eventTitle, $eventInfoStrings, $eventFees = NULL) {
500 // verify event input on info page
501 // start at Manage Events listing
502 $this->openCiviPage("event/manage", "reset=1");
503 $this->click("link=$eventTitle");
504
505 // Look for Register button
506 $this->waitForElementPresent("link=Register Now");
507
508 // Check for correct event info strings
509 $this->assertStringsPresent($eventInfoStrings);
510
511 // Optionally verify event fees (especially for discounts)
512 if ($eventFees) {
513 $this->assertStringsPresent($eventFees);
514
515 }
516 return $this->urlArg('id');
517 }
518
519 function _testVerifyRegisterPage($registerStrings) {
520 // Go to Register page and check for intro text and fee levels
521 $this->click("link=Register Now");
522 $this->waitForElementPresent("_qf_Register_upload-bottom");
523 $this->assertStringsPresent($registerStrings);
524 return $this->getLocation();
525 }
526
527 function _testOnlineRegistration($registerUrl, $numberRegistrations = 1, $anonymous = TRUE, $isPayLater = FALSE, $participantEmailInfo = array(), $paymentProcessor = NULL) {
528 $infoPassed = FALSE;
529 if (!empty($participantEmailInfo)) {
530 $infoPassed = TRUE;
531 }
532 if ($anonymous) {
533 $this->webtestLogout();
534 }
535 $primaryParticipantInfo = array();
536 $this->open($registerUrl);
537 $this->waitForPageToLoad($this->getTimeoutMsec());
538
539 $this->select("additional_participants", "value=" . $numberRegistrations);
540
541 if ($infoPassed) {
542 $primaryParticipantInfo['first_name'] = $participantEmailInfo[0]['first_name'];
543 $primaryParticipantInfo['last_name'] = $participantEmailInfo[0]['last_name'];
544 $primaryParticipantInfo['email'] = $participantEmailInfo[0]['email'];
545 }
546 else {
547 $primaryParticipantInfo['first_name'] = "Jane";
548 $primaryParticipantInfo['last_name'] = "Smith" . substr(sha1(rand()), 0, 7);
549 $primaryParticipantInfo['email'] = "smith" . substr(sha1(rand()), 0, 7) . "@example.org";
550 }
551
552 $this->type("first_name", $primaryParticipantInfo['first_name']);
553 $this->type("last_name", $primaryParticipantInfo['last_name']);
554 $this->type("email-Primary", $primaryParticipantInfo['email']);
555
556 if (!$isPayLater) {
557 if ($paymentProcessor) {
558 $paymentProcessorEle = $this->getAttribute("xpath=//form[@id='Register']//label[contains(text(), '{$paymentProcessor}')]/@for");
559 $this->check($paymentProcessorEle);
560 }
561 $this->select("credit_card_type", "value=Visa");
562 $this->type("credit_card_number", "4111111111111111");
563 $this->type("cvv2", "000");
564 $this->select("credit_card_exp_date[M]", "value=1");
565 $this->select("credit_card_exp_date[Y]", "value=2020");
566 $this->type("billing_first_name", $primaryParticipantInfo['first_name']);
567 $this->type("billing_last_name", $primaryParticipantInfo['last_name']);
568 $this->type("billing_street_address-5", "15 Main St.");
569 $this->type(" billing_city-5", "San Jose");
570 $this->select("billing_country_id-5", "value=1228");
571 $this->select("billing_state_province_id-5", "value=1004");
572 $this->type("billing_postal_code-5", "94129");
573 }
574
575 $this->click("_qf_Register_upload-bottom");
576
577 if ($numberRegistrations > 1) {
578 for ($i = 1; $i <= $numberRegistrations; $i++) {
579 $this->waitForPageToLoad($this->getTimeoutMsec());
580 // Look for Skip button
581 $this->waitForElementPresent("_qf_Participant_{$i}_next_skip-Array");
582
583 if ($infoPassed) {
584 $this->type("first_name", $participantEmailInfo[$i]['first_name']);
585 $this->type("last_name", $participantEmailInfo[$i]['last_name']);
586 $this->type("email-Primary", $participantEmailInfo[$i]['email']);
587 }
588 else {
589 $this->type("first_name", "Jane Add $i");
590 $this->type("last_name", "Smith" . substr(sha1(rand()), 0, 7));
591 $this->type("email-Primary", "smith" . substr(sha1(rand()), 0, 7) . "@example.org");
592 }
593
594 $this->click("_qf_Participant_{$i}_next");
595 }
596 }
597
598 $this->waitForPageToLoad($this->getTimeoutMsec());
599 $this->waitForElementPresent("_qf_Confirm_next-bottom");
600 $confirmStrings = array("Event Fee(s)");
601 if (!$isPayLater) {
602 $confirmStrings += array("Billing Name and Address", "Credit Card Information");
603 }
604 $this->assertStringsPresent($confirmStrings);
605 $this->click("_qf_Confirm_next-bottom");
606 $this->waitForPageToLoad($this->getTimeoutMsec());
607 $thankStrings = array("Thank You for Registering", "Event Total");
608 if (!$isPayLater) {
609 $thankStrings = array("Transaction Date");
610 }
611 else {
612 $thankStrings += array("testing later instructions");
613 }
614 $this->assertStringsPresent($thankStrings);
615 return $primaryParticipantInfo;
616 }
617
618 function _testAddReminder($eventTitle) {
619 // Go to Schedule Reminders tab
620 $this->click('css=li#tab_reminder a');
621 $this->waitForElementPresent("_qf_ScheduleReminders_upload-bottom");
622 $this->type("title", "Event Reminder for " . $eventTitle);
623 $this->select('entity', 'label=Registered');
624
625 $this->select('start_action_offset', 'label=1');
626 $this->select('start_action_condition', 'label=after');
627 $this->click('is_repeat');
628 $this->select('repetition_frequency_interval', 'label=2');
629 $this->select('end_date', 'label=Event End Date');
630 $this->click('recipient');
631 $this->select('recipient', 'label=Participant Role');
632 // $this->select( 'recipient_listing', 'value=1' );
633
634 // Fill Subject
635 $subject = 'subject' . substr(sha1(rand()), 0, 4);
636 $this->type('subject', $subject);
637 $this->fillRichTextField("html_message", "This is the test HTML version here!!!", 'CKEditor');
638
639 $this->type("text_message", "This is the test text version here!!!");
640 //click on save
641 $this->click('_qf_ScheduleReminders_upload-bottom');
642 $this->waitForElementPresent("link=Add Reminder");
643
644 $this->waitForElementPresent("link=Edit");
645
646 $verifyText = array(
647 1 => 'Event Reminder for ' . $eventTitle,
648 3 => '1 hour after Event Start Date',
649 4 => 'Registered',
650 5 => 'Yes',
651 6 => 'Yes',
652 );
653
654 //verify the fields for Event Reminder selector
655 foreach ($verifyText as $key => $value) {
656 $this->verifyText("xpath=//table[@class='display']/tbody/tr/td[$key]", $value);
657 }
658 }
659
660 function testEventAddMultipleParticipant() {
661 // Log in using webtestLogin() method
662 $this->webtestLogin();
663 $this->openCiviPage("event/add", "reset=1&action=add");
664
665 $eventTitle = 'My Conference - ' . substr(sha1(rand()), 0, 7);
666 $eventDescription = "Here is a description for this conference.";
667 $this->_testAddEventInfo($eventTitle, $eventDescription);
668 $streetAddress = "100 Main Street";
669 $this->_testAddLocation($streetAddress);
670
671 $this->_testAddFees(FALSE, FALSE, "Test Processor", FALSE, TRUE);
672 $registerIntro = "Fill in all the fields below and click Continue.";
673 $multipleRegistrations = TRUE;
674 $this->_testAddOnlineRegistration($registerIntro, $multipleRegistrations);
675 $eventInfoStrings = array($eventTitle, $eventDescription, $streetAddress);
676 $eventId = $this->_testVerifyEventInfo($eventTitle, $eventInfoStrings);
677
678 $registerStrings = array("225.00", "Member", "300.00", "Non-member", $registerIntro);
679 $registerUrl = $this->_testVerifyRegisterPage($registerStrings);
680 $numberRegistrations = 3;
681 $anonymous = TRUE;
682
683 // CRM-12615 add additional participants and check email, amount
684 $primaryParticipant = array(
685 'email' => "smith" . substr(sha1(rand()), 0, 7) . "@example.org",
686 'first_name' => "Kate",
687 'last_name' => "Simth" . substr(sha1(rand()), 0, 7),
688 );
689 $secParticipant = array(
690 'email' => "smith" . substr(sha1(rand()), 0, 7) . "@example.org",
691 'first_name' => "Kate Add 1",
692 'last_name' => "Simth" . substr(sha1(rand()), 0, 7),
693 );
694 $thirdParticipant = array(
695 'email' => "smith" . substr(sha1(rand()), 0, 7) . "@example.org",
696 'first_name' => "Kate Add 2",
697 'last_name' => "Simth" . substr(sha1(rand()), 0, 7),
698 );
699
700 $participantEmails = array($primaryParticipant, $secParticipant, $thirdParticipant);
701 $addtlPart = array($secParticipant, $thirdParticipant);
702 $primaryParticipantInfo =
703 $this->_testOnlineRegistration($registerUrl, 2, $anonymous, FALSE, $participantEmails, "Test Processor");
704 $primaryDisplayName = "{$primaryParticipantInfo['first_name']} {$primaryParticipantInfo['last_name']}";
705 $this->webtestLogin();
706 $this->openCiviPage("event/search?reset=1", "reset=1");
707 $this->type('event_name', $eventTitle);
708 $this->click("event_name");
709 $this->waitForElementPresent("css=div.ac_results-inner li");
710 $this->click("css=div.ac_results-inner li");
711 $this->clickLink('_qf_Search_refresh');
712 $this->verifyText("xpath=//div[@id='participantSearch']/table/tbody//tr/td[3]/a[contains(text(),
713 '{$secParticipant['last_name']}, {$secParticipant['first_name']}')]/../../td[6]", preg_quote('225.00'));
714 $this->verifyText("xpath=//div[@id='participantSearch']/table/tbody//tr/td[3]/a[contains(text(),
715 '{$thirdParticipant['last_name']}, {$thirdParticipant['first_name']}')]/../../td[6]", preg_quote('225.00'));
716
717 //CRM-12618 check edit screen of additional participant and ensuring record_contribution not present
718 foreach ($addtlPart as $value) {
719 $this->clickLink("xpath=//div[@id='participantSearch']/table/tbody//tr/td[3]/a[contains(text(),
720 '{$value['last_name']}, {$value['first_name']}')]/../../td[11]/span/a[2][contains(text(), 'Edit')]",
721 '_qf_Participant_upload-bottom');
722 $this->assertTrue(
723 $this->isElementPresent("xpath=//tr[@class='crm-participant-form-block-registered-by']/td[2]/a[contains(text(),
724 '$primaryDisplayName')]"), 'Registered By info is wrong on additional participant edit form');
725 $this->assertElementContainsText("xpath=//form[@id='Participant']/h3", 'Edit Event Registration');
726 $this->assertTrue(
727 $this->isElementPresent(
728 "xpath=//table/tbody/tr[@class='crm-participant-form-block-displayName']/td[2][contains(text(),
729 '{$value['first_name']} {$value['last_name']}')]"),
730 'Wrong Participant edit form'
731 );
732 $this->assertFalse($this->isElementPresent('record_contribution'),
733 'Record Payment checkbox showed up wrongly for additional participant edit screen');
734 $this->clickLink("_qf_Participant_cancel-top");
735 }
736
737 //unselect the payment processor configured
738 $this->openCiviPage("event/manage/fee", "reset=1&action=update&id={$eventId}", '_qf_Fee_upload-bottom');
739 $this->click("xpath=//tr[@class='crm-event-manage-fee-form-block-payment_processor']/td[2]/label[text()='Test Processor']");
740 $this->clickLink("_qf_Fee_upload-bottom");
741
742 // add participant and 3 additional participant and change status of participant from edit participant
743 $this->_testOnlineRegistration($registerUrl, $numberRegistrations, $anonymous, TRUE);
744 $this->webtestLogin();
745
746 $this->openCiviPage("event/search?reset=1", "reset=1");
747 $this->type('event_name', $eventTitle);
748 $this->click("event_name");
749 $this->waitForElementPresent("css=div.ac_results-inner li");
750 $this->click("css=div.ac_results-inner li");
751 $this->click("xpath=//td[@class='crm-event-form-block-participant_status']/div[@class='listing-box']//div/label[text()='Pending from pay later']");
752 $this->click('_qf_Search_refresh');
753 $this->waitForPageToLoad($this->getTimeoutMsec());
754 $this->click("xpath=//div[@id='participantSearch']/table/tbody//tr/td[11]/span/a[text()='Edit']");
755 $this->waitForPageToLoad($this->getTimeoutMsec());
756 $this->select('status_id', 'label=Registered');
757 $this->click('record_contribution');
758 $this->select('contribution_status_id', 'label=Completed');
759 $pID = $this->urlArg('id');
760 $contributionID = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $pID, 'contribution_id', 'participant_id');
761 $this->click('_qf_Participant_upload-top');
762 $this->waitForPageToLoad($this->getTimeoutMsec());
763 $this->verifyFinancialRecords($contributionID);
764
765 // add participant and 3 additional participant and change status of participant from edit contribution
766 $this->_testOnlineRegistration($registerUrl, $numberRegistrations, $anonymous, TRUE);
767 $this->webtestLogin();
768
769 $this->openCiviPage("event/search?reset=1", "reset=1");
770 $this->type('event_name', $eventTitle);
771 $this->click("event_name");
772 $this->waitForElementPresent("css=div.ac_results-inner li");
773 $this->click("css=div.ac_results-inner li");
774 $this->click("xpath=//td[@class='crm-event-form-block-participant_status']/div[@class='listing-box']//div/label[text()='Pending from pay later']");
775 $this->click('_qf_Search_refresh');
776 $this->waitForPageToLoad($this->getTimeoutMsec());
777 $this->click("xpath=//div[@id='participantSearch']/table/tbody//tr/td[11]/span/a[text()='View']");
778 $this->waitForPageToLoad($this->getTimeoutMsec());
779 $pID = $this->urlArg('id');
780 $contributionID = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $pID, 'contribution_id', 'participant_id');
781 $this->click("xpath=//tr[@id='rowid$contributionID']/td[8]/span//a[text()='Edit']");
782 $this->waitForPageToLoad($this->getTimeoutMsec());
783 $this->select('contribution_status_id', 'label=Completed');
784 $this->click('_qf_Contribution_upload-bottom');
785 $this->waitForPageToLoad($this->getTimeoutMsec());
786 $this->verifyFinancialRecords($contributionID);
787 }
788
789 function verifyFinancialRecords($contributionID) {
790 // check count for civicrm_contribution and civicrm_financial_item in civicrm_entity_financial_trxn
791 $query = "SELECT COUNT(DISTINCT(c1.id)) civicrm_contribution, COUNT(c2.id) civicrm_financial_item FROM civicrm_entity_financial_trxn c1
792 LEFT JOIN civicrm_entity_financial_trxn c2 ON c1.financial_trxn_id = c2.financial_trxn_id AND c2.entity_table ='civicrm_financial_item'
793 LEFT JOIN civicrm_financial_item cfi ON cfi.id = c2.entity_id
794 WHERE c1.entity_table = 'civicrm_contribution' AND c1.entity_id = %1 AND cfi.status_id = 1";
795 $params = array(1 => array($contributionID, 'Integer'));
796 $dao = CRM_Core_DAO::executeQuery($query, $params);
797 $dao->fetch();
798 $this->assertEquals('2', $dao->civicrm_contribution, 'civicrm_financial_trxn count does not match');
799 $this->assertEquals('8', $dao->civicrm_financial_item, 'civicrm_financial_item count does not match');
800 $query = "SELECT COUNT(cft.id) civicrm_financial_trxn FROM civicrm_entity_financial_trxn ceft
801 INNER JOIN civicrm_financial_trxn cft ON ceft.financial_trxn_id = cft.id
802 WHERE ceft.entity_id = %1 AND ceft.entity_table = 'civicrm_contribution'";
803 $dao = CRM_Core_DAO::executeQuery($query, $params);
804 $dao->fetch();
805 $this->assertEquals('2', $dao->civicrm_financial_trxn, 'civicrm_financial_trxn count does not match');
806 }
807 }