CRM-15031 Event Webtest Fix
[civicrm-core.git] / tests / phpunit / WebTest / Event / AddParticipationTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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
29 /**
30 * Class WebTest_Event_AddParticipationTest
31 */
32 class WebTest_Event_AddParticipationTest extends CiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
38 function testEventParticipationAdd() {
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
49 $this->openCiviPage("participant/add", "reset=1&action=add&context=standalone", "_qf_Participant_upload-bottom");
50
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.
55 $this->select2('event_id', "Rain-forest Cup Youth Soccer Tournament");
56
57 // Select role
58 $this->multiselect2('role_id', array('Volunteer'));
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
67 $this->select('status_id', 'value=1');
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
78 $this->click("xpath=//input[@class='crm-form-radio']");
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?
96 $this->waitForText('crm-notification-container', "Event registration for $displayName has been added");
97
98 $this->waitForElementPresent("xpath=//*[@id='Search']//table/tbody/tr[1]/td[8]/span/a[text()='View']");
99 //click through to the participant view screen
100 $this->click("xpath=//*[@id='Search']//table/tbody/tr[1]/td[8]/span/a[text()='View']");
101 $this->waitForElementPresent('_qf_ParticipantView_cancel-bottom');
102
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',
109 'Fees' => '$ 800.00',
110 )
111 );
112 // check contribution record as well
113 //click through to the contribution view screen
114 $this->click("xpath=id('ParticipantView')/div[2]/table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='View']");
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
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
142 $this->openCiviPage("admin/custom/group", "reset=1");
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?
165 $this->waitForText('crm-notification-container', "Your custom field set '$customGroupTitle' has been added. You can add custom fields now.");
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
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
198 $this->click('_qf_Field_done-bottom');
199 $this->waitForPageToLoad($this->getTimeoutMsec());
200
201 //Is custom field created?
202 $this->waitForText('crm-notification-container', "Custom field '$checkboxFieldLabel' has been saved.");
203
204 //create another custom field - Integer Radio
205 $this->clickLink("//a[@id='newCustomField']/span", '_qf_Field_cancel', FALSE);
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
239 $this->click('_qf_Field_done-bottom');
240
241 $this->openCiviPage("participant/add", "reset=1&action=add&context=standalone", "_qf_Participant_upload-bottom");
242
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.
247 $this->select2('event_id', "Rain-forest Cup Youth Soccer Tournament");
248
249 // Select roles
250 $this->multiselect2('role_id', array('Volunteer', 'Host'));
251
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");
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");
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
264 $this->select('status_id', 'value=1');
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
275 $this->click("xpath=//input[@class='crm-form-radio']");
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?
290 $this->waitForText('crm-notification-container', "Event registration for $displayName has been added");
291
292 $this->waitForElementPresent("xpath=//*[@id='Search']//table/tbody/tr[1]/td[8]/span/a[text()='View']");
293 //click through to the participant view screen
294 $this->click("xpath=//*[@id='Search']//table/tbody/tr[1]/td[8]/span/a[text()='View']");
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',
303 'Fees' => '$ 800.00',
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
313 $this->click("xpath=id('ParticipantView')/div[2]/table[@class='selector row-highlight']/tbody/tr[1]/td[8]/span/a[text()='View']");
314 $this->waitForElementPresent('_qf_ContributionView_cancel-bottom');
315
316 $this->webtestVerifyTabularData(
317 array(
318 'From' => $displayName,
319 'Financial Type' => 'Event Fee',
320 'Contribution Status' => 'Completed',
321 'Paid By' => 'Check',
322 'Check Number' => '1044',
323 )
324 );
325 $this->verifyText("xpath=//table/tbody/tr/td[text()='Total Amount']/following-sibling::td/strong", preg_quote('$ 800.00'), 'In line ' . __LINE__);
326 }
327
328 function testEventAddMultipleParticipants() {
329
330 // Log in using webtestLogin() method
331 $this->webtestLogin();
332
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;
339
340 $this->openCiviPage("participant/add", "reset=1&action=add&context=standalone&mode=test&eid=3");
341
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());
347
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());
353
354 //searching the paricipants
355 $this->openCiviPage("event/search", "reset=1");
356 $this->type('sort_name', $firstName);
357 $eventName = "Rain-forest Cup Youth Soccer Tournament";
358 $this->select2("event_id", $eventName, FALSE, FALSE);
359 $this->check('participant_test');
360 $this->click("_qf_Search_refresh");
361 $this->waitForElementPresent("participantSearch");
362
363 //verifying the registered participants
364 $names = array( "{$lastName}, {$firstName}", "{$lastName2}, {$firstName}" );
365 $status = "Registered (test)";
366
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
373 function testAjaxCustomGroupLoad() {
374 $this->webtestLogin();
375
376 $customSets = array(
377 array('entity' => 'ParticipantEventName', 'subEntity' => 'Fall Fundraiser Dinner',
378 'triggerElement' => array('name' => "event_id", 'type' => "select2")),
379 array('entity' => 'ParticipantRole', 'subEntity' => 'Attendee','triggerElement' => array('name' => 'role_id', 'type' => "select"))
380 );
381 $pageUrl = array('url' => "participant/add", 'args' => "reset=1&action=add&context=standalone");
382 $this->customFieldSetLoadOnTheFlyCheck($customSets, $pageUrl);
383 }
384
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.
408 $this->select2('event_id', "Rain-forest Cup Youth Soccer Tournament");
409
410 // Select role.
411 $this->multiselect2('role_id', array('Volunteer'));
412
413 foreach($return as $values) {
414 foreach ($values as $entityType => $customData) {
415 //checking for duplicate custom data present or not
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 ']"));
418 }
419 }
420 }
421
422 /**
423 * @param $firstName
424 * @param $lastName
425 * @param $processorId
426 */
427 function _fillParticipantDetails($firstName, $lastName, $processorId) {
428 $this->webtestNewDialogContact($firstName, $lastName);
429
430 $this->select('payment_processor_id', "value={$processorId}");
431 $event_id = $this->getAttribute("xpath=//*[@id='event_id']@value");
432 //check if it is the selected event
433 $this->assertEquals($event_id, 3);
434 $this->select("role_id", "value=1");
435 $this->webtestAddCreditCardDetails();
436 $this->webtestAddBillingDetails();
437 }
438 }