CRM-15031 Event Webtest Fix
[civicrm-core.git] / tests / phpunit / WebTest / Event / AddParticipationTest.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
06a1bc01 4 | CiviCRM version 4.5 |
6a488035 5 +--------------------------------------------------------------------+
06a1bc01 6 | Copyright CiviCRM LLC (c) 2004-2014 |
6a488035
TO
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 27require_once 'CiviTest/CiviSeleniumTestCase.php';
e9479dcf
EM
28
29/**
30 * Class WebTest_Event_AddParticipationTest
31 */
6a488035
TO
32class WebTest_Event_AddParticipationTest extends CiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
38 function testEventParticipationAdd() {
6a488035
TO
39 // Log in using webtestLogin() method
40 $this->webtestLogin();
41
42 // Adding contact with randomized first name (so we can then select that contact when creating event registration)
43 // We're using Quick Add block on the main page for this.
44 $firstName = substr(sha1(rand()), 0, 7);
45 $this->webtestAddContact($firstName, 'Anderson', TRUE);
46 $contactName = "Anderson, $firstName";
47 $displayName = "$firstName Anderson";
48
c038a4f0 49 $this->openCiviPage("participant/add", "reset=1&action=add&context=standalone", "_qf_Participant_upload-bottom");
6a488035 50
6a488035
TO
51 // Type contact last name in contact auto-complete, wait for dropdown and click first result
52 $this->webtestFillAutocomplete($firstName);
53
54 // Select event. Based on label for now.
33cf86bd 55 $this->select2('event_id', "Rain-forest Cup Youth Soccer Tournament");
6a488035
TO
56
57 // Select role
673c7418 58 $this->multiselect2('role_id', array('Volunteer'));
6a488035
TO
59
60 // Choose Registration Date.
61 // Using helper webtestFillDate function.
62 $this->webtestFillDate('register_date', 'now');
63 $today = date('F jS, Y', strtotime('now'));
64 // May 5th, 2010
65
66 // Select participant status
33cf86bd 67 $this->select('status_id', 'value=1');
6a488035
TO
68
69 // Setting registration source
70 $this->type('source', 'Event StandaloneAddTest Webtest');
71
72 // Since we're here, let's check of screen help is being displayed properly
73 $this->assertTrue($this->isTextPresent('Source for this registration (if applicable).'));
74
75 // Select an event fee
76 $this->waitForElementPresent('priceset');
77
2861538e 78 $this->click("xpath=//input[@class='crm-form-radio']");
6a488035
TO
79
80 // Enter amount to be paid (note: this should default to selected fee level amount, s/b fixed during 3.2 cycle)
81 $this->type('total_amount', '800');
82
83 // Select payment method = Check and enter chk number
84 $this->select('payment_instrument_id', 'value=4');
85 $this->waitForElementPresent('check_number');
86 $this->type('check_number', '1044');
87
88 // go for the chicken combo (obviously)
89 // $this->click('CIVICRM_QFID_chicken_Chicken');
90
91 // Clicking save.
92 $this->click('_qf_Participant_upload-bottom');
93 $this->waitForPageToLoad($this->getTimeoutMsec());
94
95 // Is status message correct?
6c5f7368 96 $this->waitForText('crm-notification-container', "Event registration for $displayName has been added");
6a488035 97
2861538e 98 $this->waitForElementPresent("xpath=//*[@id='Search']//table/tbody/tr[1]/td[8]/span/a[text()='View']");
6a488035 99 //click through to the participant view screen
2861538e 100 $this->click("xpath=//*[@id='Search']//table/tbody/tr[1]/td[8]/span/a[text()='View']");
6a488035
TO
101 $this->waitForElementPresent('_qf_ParticipantView_cancel-bottom');
102
6a488035
TO
103 $this->webtestVerifyTabularData(
104 array(
105 'Event' => 'Rain-forest Cup Youth Soccer Tournament',
106 'Participant Role' => 'Attendee',
107 'Status' => 'Registered',
108 'Event Source' => 'Event StandaloneAddTest Webtest',
2861538e 109 'Fees' => '$ 800.00',
6a488035
TO
110 )
111 );
112 // check contribution record as well
113 //click through to the contribution view screen
2861538e 114 $this->click("xpath=id('ParticipantView')/div[2]/table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='View']");
6a488035
TO
115 $this->waitForElementPresent('_qf_ContributionView_cancel-bottom');
116
117 $this->webtestVerifyTabularData(
118 array(
119 'From' => $displayName,
120 'Financial Type' => 'Event Fee',
121 'Total Amount' => '$ 800.00',
122 'Contribution Status' => 'Completed',
123 'Paid By' => 'Check',
124 'Check Number' => '1044',
125 )
126 );
127 }
128
129 function testEventParticipationAddWithMultipleRoles() {
130
6a488035
TO
131 // Log in using webtestLogin() method
132 $this->webtestLogin();
133
134 // Adding contact with randomized first name (so we can then select that contact when creating event registration)
135 // We're using Quick Add block on the main page for this.
136 $firstName = substr(sha1(rand()), 0, 7);
137 $this->webtestAddContact($firstName, 'Anderson', TRUE);
138 $contactName = "Anderson, $firstName";
139 $displayName = "$firstName Anderson";
140
141 // add custom data for participant role
c038a4f0 142 $this->openCiviPage("admin/custom/group", "reset=1");
6a488035
TO
143
144 //add new custom data
145 $this->click("//a[@id='newCustomDataGroup']/span");
146 $this->waitForPageToLoad($this->getTimeoutMsec());
147
148 //fill custom group title
149 $customGroupTitle = 'custom_' . substr(sha1(rand()), 0, 7);
150 $this->click('title');
151 $this->type('title', $customGroupTitle);
152
153 //custom group extends
154 $this->click('extends[0]');
155 $this->select('extends[0]', 'value=ParticipantRole');
156
157 $this->click('extends[1][]');
158 $this->select('extends[1][]', 'value=2');
159
160 $this->click("//option[@value='Contact']");
161 $this->click('_qf_Group_next');
162 $this->waitForPageToLoad($this->getTimeoutMsec());
163
164 //Is custom group created?
6c5f7368 165 $this->waitForText('crm-notification-container', "Your custom field set '$customGroupTitle' has been added. You can add custom fields now.");
6a488035
TO
166
167 //add custom field - alphanumeric checkbox
168 $checkboxFieldLabel = 'custom_field' . substr(sha1(rand()), 0, 4);
169 $this->click('label');
170 $this->type('label', $checkboxFieldLabel);
171 $this->click('data_type[1]');
172 $this->select('data_type[1]', 'value=CheckBox');
173 $this->click("//option[@value='CheckBox']");
174 $checkboxOptionLabel1 = 'optionLabel_' . substr(sha1(rand()), 0, 5);
175 $this->type('option_label_1', $checkboxOptionLabel1);
176 $this->type('option_value_1', '1');
177 $checkboxOptionLabel2 = 'optionLabel_' . substr(sha1(rand()), 0, 5);
178 $this->type('option_label_2', $checkboxOptionLabel2);
179 $this->type('option_value_2', '2');
180 $this->click('link=another choice');
181 $checkboxOptionLabel3 = 'optionLabel_' . substr(sha1(rand()), 0, 5);
182 $this->type('option_label_3', $checkboxOptionLabel3);
183 $this->type('option_value_3', '3');
184
6a488035
TO
185 //enter options per line
186 $this->type('options_per_line', '2');
187
188 //enter pre help message
189 $this->type('help_pre', 'this is field pre help');
190
191 //enter post help message
192 $this->type('help_post', 'this field post help');
193
194 //Is searchable?
195 $this->click('is_searchable');
196
197 //clicking save
60709d21 198 $this->click('_qf_Field_done-bottom');
6a488035
TO
199 $this->waitForPageToLoad($this->getTimeoutMsec());
200
201 //Is custom field created?
2861538e 202 $this->waitForText('crm-notification-container', "Custom field '$checkboxFieldLabel' has been saved.");
6a488035
TO
203
204 //create another custom field - Integer Radio
2861538e 205 $this->clickLink("//a[@id='newCustomField']/span", '_qf_Field_cancel', FALSE);
6a488035
TO
206 $this->click('data_type[0]');
207 $this->select('data_type[0]', 'value=1');
208 $this->click("//option[@value='1']");
209 $this->click('data_type[1]');
210 $this->select('data_type[1]', 'value=Radio');
211 $this->click("//option[@value='Radio']");
212
213 $radioFieldLabel = 'custom_field' . substr(sha1(rand()), 0, 4);
214 $this->type('label', $radioFieldLabel);
215 $radioOptionLabel1 = 'optionLabel_' . substr(sha1(rand()), 0, 5);
216 $this->type('option_label_1', $radioOptionLabel1);
217 $this->type('option_value_1', '1');
218 $radioOptionLabel2 = 'optionLabel_' . substr(sha1(rand()), 0, 5);
219 $this->type('option_label_2', $radioOptionLabel2);
220 $this->type('option_value_2', '2');
221 $this->click('link=another choice');
222 $radioOptionLabel3 = 'optionLabel_' . substr(sha1(rand()), 0, 5);
223 $this->type('option_label_3', $radioOptionLabel3);
224 $this->type('option_value_3', '3');
225
226 //select options per line
227 $this->type('options_per_line', '3');
228
229 //enter pre help msg
230 $this->type('help_pre', 'this is field pre help');
231
232 //enter post help msg
233 $this->type('help_post', 'this is field post help');
234
235 //Is searchable?
236 $this->click('is_searchable');
237
238 //clicking save
60709d21 239 $this->click('_qf_Field_done-bottom');
6a488035 240
c038a4f0 241 $this->openCiviPage("participant/add", "reset=1&action=add&context=standalone", "_qf_Participant_upload-bottom");
6a488035 242
6a488035
TO
243 // Type contact last name in contact auto-complete, wait for dropdown and click first result
244 $this->webtestFillAutocomplete($firstName);
245
246 // Select event. Based on label for now.
33cf86bd 247 $this->select2('event_id', "Rain-forest Cup Youth Soccer Tournament");
6a488035
TO
248
249 // Select roles
673c7418 250 $this->multiselect2('role_id', array('Volunteer', 'Host'));
6a488035 251
1d4d99e9 252 $this->waitForElementPresent("xpath=//div[@class='crm-customData-block']//div[@class='custom-group custom-group-$customGroupTitle crm-accordion-wrapper collapsed']");
253 $this->click("xpath=//div[@class='crm-customData-block']//div[@class='custom-group custom-group-$customGroupTitle crm-accordion-wrapper collapsed']//div[1]");
254 $this->click("xpath=//div[@class='crm-customData-block']//div[@class='custom-group custom-group-$customGroupTitle crm-accordion-wrapper']//div[2]//table//tbody//tr[2]//td[2]//table//tbody//tr[1]//td[1]//label");
c900afb1 255 $this->click("xpath=//div[@class='crm-customData-block']//div[@class='custom-group custom-group-$customGroupTitle crm-accordion-wrapper']//div[2]//table//tbody//tr[4]//td[2]//table//tbody//tr[1]//td[1]//label");
6a488035
TO
256
257 // Choose Registration Date.
258 // Using helper webtestFillDate function.
259 $this->webtestFillDate('register_date', 'now');
260 $today = date('F jS, Y', strtotime('now'));
261 // May 5th, 2010
262
263 // Select participant status
33cf86bd 264 $this->select('status_id', 'value=1');
6a488035
TO
265
266 // Setting registration source
267 $this->type('source', 'Event StandaloneAddTest Webtest');
268
269 // Since we're here, let's check of screen help is being displayed properly
270 $this->assertTrue($this->isTextPresent('Source for this registration (if applicable).'));
271
272 // Select an event fee
273 $this->waitForElementPresent('priceset');
274
2861538e 275 $this->click("xpath=//input[@class='crm-form-radio']");
6a488035
TO
276
277 // Enter amount to be paid (note: this should default to selected fee level amount, s/b fixed during 3.2 cycle)
278 $this->type('total_amount', '800');
279
280 // Select payment method = Check and enter chk number
281 $this->select('payment_instrument_id', 'value=4');
282 $this->waitForElementPresent('check_number');
283 $this->type('check_number', '1044');
284
285 // Clicking save.
286 $this->click('_qf_Participant_upload-bottom');
287 $this->waitForPageToLoad($this->getTimeoutMsec());
288
289 // Is status message correct?
6c5f7368 290 $this->waitForText('crm-notification-container', "Event registration for $displayName has been added");
6a488035 291
2861538e 292 $this->waitForElementPresent("xpath=//*[@id='Search']//table/tbody/tr[1]/td[8]/span/a[text()='View']");
6a488035 293 //click through to the participant view screen
2861538e 294 $this->click("xpath=//*[@id='Search']//table/tbody/tr[1]/td[8]/span/a[text()='View']");
6a488035
TO
295 $this->waitForElementPresent('_qf_ParticipantView_cancel-bottom');
296
297 $this->webtestVerifyTabularData(
298 array(
299 'Event' => 'Rain-forest Cup Youth Soccer Tournament',
300 'Participant Role' => 'Attendee, Volunteer, Host',
301 'Status' => 'Registered',
302 'Event Source' => 'Event StandaloneAddTest Webtest',
2861538e 303 'Fees' => '$ 800.00',
6a488035
TO
304 )
305 );
306
307 $this->assertTrue($this->isTextPresent("$customGroupTitle"));
308 $this->assertTrue($this->isTextPresent("$checkboxOptionLabel1"));
309 $this->assertTrue($this->isTextPresent("$radioOptionLabel1"));
310
311 // check contribution record as well
312 //click through to the contribution view screen
2861538e 313 $this->click("xpath=id('ParticipantView')/div[2]/table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='View']");
6a488035
TO
314 $this->waitForElementPresent('_qf_ContributionView_cancel-bottom');
315
316 $this->webtestVerifyTabularData(
317 array(
318 'From' => $displayName,
319 'Financial Type' => 'Event Fee',
6a488035
TO
320 'Contribution Status' => 'Completed',
321 'Paid By' => 'Check',
322 'Check Number' => '1044',
323 )
324 );
c900afb1 325 $this->verifyText("xpath=//table/tbody/tr/td[text()='Total Amount']/following-sibling::td/strong", preg_quote('$ 800.00'), 'In line ' . __LINE__);
6a488035
TO
326 }
327
76e86fd8
CW
328 function testEventAddMultipleParticipants() {
329
6a488035
TO
330 // Log in using webtestLogin() method
331 $this->webtestLogin();
76e86fd8 332
6a488035
TO
333 $processorId = $this->webtestAddPaymentProcessor('dummy' . substr(sha1(rand()), 0, 7));
334 $rand = substr(sha1(rand()), 0, 7);
335 $firstName = 'First' . $rand;
336 $lastName = 'Last' . $rand;
337 $rand = substr(sha1(rand()), 0, 7);
338 $lastName2 = 'Last' . $rand;
42daf119 339
c038a4f0 340 $this->openCiviPage("participant/add", "reset=1&action=add&context=standalone&mode=test&eid=3");
76e86fd8 341
6a488035
TO
342 $this->assertTrue($this->isTextPresent("Register New Participant"), "Page title 'Register New Participant' missing");
343 $this->assertTrue($this->isTextPresent("A TEST transaction will be submitted"), "test mode status 'A TEST transaction will be submitted' missing");
344 $this->_fillParticipantDetails($firstName, $lastName, $processorId);
345 $this->click('_qf_Participant_upload_new-bottom');
346 $this->waitForPageToLoad($this->getTimeoutMsec());
76e86fd8 347
6a488035
TO
348 $this->assertTrue($this->isTextPresent("Register New Participant"), "Page title 'Register New Participant' missing");
349 $this->assertTrue($this->isTextPresent("A TEST transaction will be submitted"), "test mode status 'A TEST transaction will be submitted' missing");
350 $this->_fillParticipantDetails($firstName, $lastName2, $processorId);
351 $this->click('_qf_Participant_upload_new-bottom');
352 $this->waitForPageToLoad($this->getTimeoutMsec());
76e86fd8 353
6a488035 354 //searching the paricipants
c038a4f0 355 $this->openCiviPage("event/search", "reset=1");
6a488035
TO
356 $this->type('sort_name', $firstName);
357 $eventName = "Rain-forest Cup Youth Soccer Tournament";
e9322446 358 $this->select2("event_id", $eventName, FALSE, FALSE);
6a488035
TO
359 $this->check('participant_test');
360 $this->click("_qf_Search_refresh");
361 $this->waitForElementPresent("participantSearch");
76e86fd8 362
6a488035
TO
363 //verifying the registered participants
364 $names = array( "{$lastName}, {$firstName}", "{$lastName2}, {$firstName}" );
365 $status = "Registered (test)";
76e86fd8 366
6a488035
TO
367 foreach($names as $name) {
368 $this->verifyText("xpath=//div[@id='participantSearch']//table//tbody//tr/td[@class='crm-participant-sort_name']/a[text()='{$name}']/../../td[9]", preg_quote($status));
369 $this->verifyText("xpath=//div[@id='participantSearch']//table//tbody//tr/td[@class='crm-participant-sort_name']/a[text()='{$name}']/../../td[4]/a", preg_quote($eventName));
370}
371 }
372
c4e6d4e8
PJ
373 function testAjaxCustomGroupLoad() {
374 $this->webtestLogin();
375
376 $customSets = array(
377 array('entity' => 'ParticipantEventName', 'subEntity' => 'Fall Fundraiser Dinner',
16345393 378 'triggerElement' => array('name' => "event_id", 'type' => "select2")),
60709d21 379 array('entity' => 'ParticipantRole', 'subEntity' => 'Attendee','triggerElement' => array('name' => 'role_id', 'type' => "select"))
c4e6d4e8
PJ
380 );
381 $pageUrl = array('url' => "participant/add", 'args' => "reset=1&action=add&context=standalone");
382 $this->customFieldSetLoadOnTheFlyCheck($customSets, $pageUrl);
383 }
384
63dbed83 385 /*
386 * Webtest for CRM-10983
387 *
388 */
389 function testCheckDuplicateCustomDataLoad() {
390 $this->webtestLogin();
391
392 $customSets = array(
393 array('entity' => 'ParticipantEventType', 'subEntity' => '- Any -',
394 'triggerElement' => array('name' => "event_id", 'type' => "select")),
395 array('entity' => 'ParticipantEventName', 'subEntity' => '- Any -',
396 'triggerElement' => array('name' => "event_id", 'type' => "select")),
397 array('entity' => 'ParticipantEventName', 'subEntity' => 'Rain-forest Cup Youth Soccer Tournament',
398 'triggerElement' => array('name' => "event_id", 'type' => "select")),
399 array('entity' => 'ParticipantRole', 'subEntity' => '- Any -','triggerElement' => array('type' => "checkbox")),
400 array('entity' => 'ParticipantRole', 'subEntity' => 'Volunteer','triggerElement' => array('type' => "checkbox"))
401 );
402
403 $return = $this->addCustomGroupField($customSets);
404
405 $this->openCiviPage("participant/add", "reset=1&action=add&context=standalone", "_qf_Participant_upload-bottom");
406
407 // Select event.
33cf86bd 408 $this->select2('event_id', "Rain-forest Cup Youth Soccer Tournament");
63dbed83 409
410 // Select role.
673c7418 411 $this->multiselect2('role_id', array('Volunteer'));
63dbed83 412
413 foreach($return as $values) {
414 foreach ($values as $entityType => $customData) {
415 //checking for duplicate custom data present or not
673c7418 416 $this->assertElementPresent("xpath=//*[@class='crm-customData-block']/div[@class='custom-group custom-group-{$customData['cgtitle']} crm-accordion-wrapper ']");
417 $this->assertEquals(1, $this->getXpathCount("//*[@class='crm-customData-block']/div[@class='custom-group custom-group-{$customData['cgtitle']} crm-accordion-wrapper ']"));
63dbed83 418 }
419 }
420 }
421
4cbe18b8
EM
422 /**
423 * @param $firstName
424 * @param $lastName
425 * @param $processorId
426 */
6a488035 427 function _fillParticipantDetails($firstName, $lastName, $processorId) {
2861538e 428 $this->webtestNewDialogContact($firstName, $lastName);
76e86fd8 429
6a488035 430 $this->select('payment_processor_id', "value={$processorId}");
e9322446 431 $event_id = $this->getAttribute("xpath=//*[@id='event_id']@value");
dd1e47de 432 //check if it is the selected event
e9322446 433 $this->assertEquals($event_id, 3);
434 $this->select("role_id", "value=1");
6a488035
TO
435 $this->webtestAddCreditCardDetails();
436 $this->webtestAddBillingDetails();
437 }
232624b1 438}