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