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