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