Mass switch to openCiviPage method
[civicrm-core.git] / tests / phpunit / WebTest / Event / AddParticipationTest.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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
28require_once 'CiviTest/CiviSeleniumTestCase.php';
29class WebTest_Event_AddParticipationTest extends CiviSeleniumTestCase {
30
31 protected function setUp() {
32 parent::setUp();
33 }
34
35 function testEventParticipationAdd() {
6a488035
TO
36 // Log in using webtestLogin() method
37 $this->webtestLogin();
38
39 // Adding contact with randomized first name (so we can then select that contact when creating event registration)
40 // We're using Quick Add block on the main page for this.
41 $firstName = substr(sha1(rand()), 0, 7);
42 $this->webtestAddContact($firstName, 'Anderson', TRUE);
43 $contactName = "Anderson, $firstName";
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.
52 $this->select('event_id', "label=regexp:Rain-forest Cup Youth Soccer Tournament.");
53
54 // Select role
55 $this->click('role_id[2]');
56
57 // Choose Registration Date.
58 // Using helper webtestFillDate function.
59 $this->webtestFillDate('register_date', 'now');
60 $today = date('F jS, Y', strtotime('now'));
61 // May 5th, 2010
62
63 // Select participant status
64 $this->select('status_id', 'value=1');
65
66 // Setting registration source
67 $this->type('source', 'Event StandaloneAddTest Webtest');
68
69 // Since we're here, let's check of screen help is being displayed properly
70 $this->assertTrue($this->isTextPresent('Source for this registration (if applicable).'));
71
72 // Select an event fee
73 $this->waitForElementPresent('priceset');
74
75 $this->click("xpath=//input[@class='form-radio']");
76
77 // Enter amount to be paid (note: this should default to selected fee level amount, s/b fixed during 3.2 cycle)
78 $this->type('total_amount', '800');
79
80 // Select payment method = Check and enter chk number
81 $this->select('payment_instrument_id', 'value=4');
82 $this->waitForElementPresent('check_number');
83 $this->type('check_number', '1044');
84
85 // go for the chicken combo (obviously)
86 // $this->click('CIVICRM_QFID_chicken_Chicken');
87
88 // Clicking save.
89 $this->click('_qf_Participant_upload-bottom');
90 $this->waitForPageToLoad($this->getTimeoutMsec());
91
92 // Is status message correct?
c038a4f0 93 $this->assertElementContainsText("crm-notification-container", "Event registration for $displayName has been added", "Status message didn't show up after saving!");
6a488035
TO
94
95 $this->waitForElementPresent("xpath=//div[@id='Events']//table//tbody/tr[1]/td[8]/span/a[text()='View']");
96 //click through to the participant view screen
97 $this->click("xpath=//div[@id='Events']//table//tbody/tr[1]/td[8]/span/a[text()='View']");
98 $this->waitForElementPresent('_qf_ParticipantView_cancel-bottom');
99
100
101 $this->webtestVerifyTabularData(
102 array(
103 'Event' => 'Rain-forest Cup Youth Soccer Tournament',
104 'Participant Role' => 'Attendee',
105 'Status' => 'Registered',
106 'Event Source' => 'Event StandaloneAddTest Webtest',
107 'Event Fees' => '$ 800.00',
108 )
109 );
110 // check contribution record as well
111 //click through to the contribution view screen
112 $this->click("xpath=id('ParticipantView')/div[2]/table[@class='selector']/tbody/tr[1]/td[8]/span/a[text()='View']");
113 $this->waitForElementPresent('_qf_ContributionView_cancel-bottom');
114
115 $this->webtestVerifyTabularData(
116 array(
117 'From' => $displayName,
118 'Financial Type' => 'Event Fee',
119 'Total Amount' => '$ 800.00',
120 'Contribution Status' => 'Completed',
121 'Paid By' => 'Check',
122 'Check Number' => '1044',
123 )
124 );
125 }
126
127 function testEventParticipationAddWithMultipleRoles() {
128
6a488035
TO
129 // Log in using webtestLogin() method
130 $this->webtestLogin();
131
132 // Adding contact with randomized first name (so we can then select that contact when creating event registration)
133 // We're using Quick Add block on the main page for this.
134 $firstName = substr(sha1(rand()), 0, 7);
135 $this->webtestAddContact($firstName, 'Anderson', TRUE);
136 $contactName = "Anderson, $firstName";
137 $displayName = "$firstName Anderson";
138
139 // add custom data for participant role
c038a4f0 140 $this->openCiviPage("admin/custom/group", "reset=1");
6a488035
TO
141
142 //add new custom data
143 $this->click("//a[@id='newCustomDataGroup']/span");
144 $this->waitForPageToLoad($this->getTimeoutMsec());
145
146 //fill custom group title
147 $customGroupTitle = 'custom_' . substr(sha1(rand()), 0, 7);
148 $this->click('title');
149 $this->type('title', $customGroupTitle);
150
151 //custom group extends
152 $this->click('extends[0]');
153 $this->select('extends[0]', 'value=ParticipantRole');
154
155 $this->click('extends[1][]');
156 $this->select('extends[1][]', 'value=2');
157
158 $this->click("//option[@value='Contact']");
159 $this->click('_qf_Group_next');
160 $this->waitForPageToLoad($this->getTimeoutMsec());
161
162 //Is custom group created?
c038a4f0 163 $this->assertElementContainsText("crm-notification-container", "Your custom field set '$customGroupTitle' has been added. You can add custom fields now.");
6a488035
TO
164
165 //add custom field - alphanumeric checkbox
166 $checkboxFieldLabel = 'custom_field' . substr(sha1(rand()), 0, 4);
167 $this->click('label');
168 $this->type('label', $checkboxFieldLabel);
169 $this->click('data_type[1]');
170 $this->select('data_type[1]', 'value=CheckBox');
171 $this->click("//option[@value='CheckBox']");
172 $checkboxOptionLabel1 = 'optionLabel_' . substr(sha1(rand()), 0, 5);
173 $this->type('option_label_1', $checkboxOptionLabel1);
174 $this->type('option_value_1', '1');
175 $checkboxOptionLabel2 = 'optionLabel_' . substr(sha1(rand()), 0, 5);
176 $this->type('option_label_2', $checkboxOptionLabel2);
177 $this->type('option_value_2', '2');
178 $this->click('link=another choice');
179 $checkboxOptionLabel3 = 'optionLabel_' . substr(sha1(rand()), 0, 5);
180 $this->type('option_label_3', $checkboxOptionLabel3);
181 $this->type('option_value_3', '3');
182
183
184 //enter options per line
185 $this->type('options_per_line', '2');
186
187 //enter pre help message
188 $this->type('help_pre', 'this is field pre help');
189
190 //enter post help message
191 $this->type('help_post', 'this field post help');
192
193 //Is searchable?
194 $this->click('is_searchable');
195
196 //clicking save
197 $this->click('_qf_Field_next');
198 $this->waitForPageToLoad($this->getTimeoutMsec());
199
200 //Is custom field created?
c038a4f0 201 $this->assertElementContainsText("crm-notification-container", "Your custom field '$checkboxFieldLabel' has been saved.");
6a488035
TO
202
203 //create another custom field - Integer Radio
204 $this->click("//a[@id='newCustomField']/span");
205 $this->waitForPageToLoad($this->getTimeoutMsec());
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_next');
240 $this->waitForPageToLoad($this->getTimeoutMsec());
241
c038a4f0 242 $this->openCiviPage("participant/add", "reset=1&action=add&context=standalone", "_qf_Participant_upload-bottom");
6a488035 243
6a488035
TO
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->select('event_id', "label=regexp:Rain-forest Cup Youth Soccer Tournament.");
249
250 // Select roles
251 $this->click('role_id[2]');
252 $this->click('role_id[3]');
253
254 $this->waitForElementPresent("xpath=//div[@id='$customGroupTitle']//div");
255 $this->click("xpath=//div[@id='$customGroupTitle']//div[1]");
256 $this->click("xpath=//div[@id='$customGroupTitle']//div[2]//table//tbody//tr[2]//td[2]//table//tbody//tr[1]//td[1]//label");
257 $this->click("xpath=//div[@id='$customGroupTitle']//div[2]//table//tbody//tr[4]//td[2]//table//tbody//tr[1]//td[1]//label");
258
259 // Choose Registration Date.
260 // Using helper webtestFillDate function.
261 $this->webtestFillDate('register_date', 'now');
262 $today = date('F jS, Y', strtotime('now'));
263 // May 5th, 2010
264
265 // Select participant status
266 $this->select('status_id', 'value=1');
267
268 // Setting registration source
269 $this->type('source', 'Event StandaloneAddTest Webtest');
270
271 // Since we're here, let's check of screen help is being displayed properly
272 $this->assertTrue($this->isTextPresent('Source for this registration (if applicable).'));
273
274 // Select an event fee
275 $this->waitForElementPresent('priceset');
276
277 $this->click("xpath=//input[@class='form-radio']");
278
279 // Enter amount to be paid (note: this should default to selected fee level amount, s/b fixed during 3.2 cycle)
280 $this->type('total_amount', '800');
281
282 // Select payment method = Check and enter chk number
283 $this->select('payment_instrument_id', 'value=4');
284 $this->waitForElementPresent('check_number');
285 $this->type('check_number', '1044');
286
287 // Clicking save.
288 $this->click('_qf_Participant_upload-bottom');
289 $this->waitForPageToLoad($this->getTimeoutMsec());
290
291 // Is status message correct?
c038a4f0 292 $this->assertElementContainsText("crm-notification-container", "Event registration for $displayName has been added", "Status message didn't show up after saving!");
6a488035
TO
293
294 $this->waitForElementPresent("xpath=//div[@id='Events']//table//tbody/tr[1]/td[8]/span/a[text()='View']");
295 //click through to the participant view screen
296 $this->click("xpath=//div[@id='Events']//table//tbody/tr[1]/td[8]/span/a[text()='View']");
297 $this->waitForElementPresent('_qf_ParticipantView_cancel-bottom');
298
299 $this->webtestVerifyTabularData(
300 array(
301 'Event' => 'Rain-forest Cup Youth Soccer Tournament',
302 'Participant Role' => 'Attendee, Volunteer, Host',
303 'Status' => 'Registered',
304 'Event Source' => 'Event StandaloneAddTest Webtest',
305 'Event Fees' => '$ 800.00',
306 )
307 );
308
309 $this->assertTrue($this->isTextPresent("$customGroupTitle"));
310 $this->assertTrue($this->isTextPresent("$checkboxOptionLabel1"));
311 $this->assertTrue($this->isTextPresent("$radioOptionLabel1"));
312
313 // check contribution record as well
314 //click through to the contribution view screen
315 $this->click("xpath=id('ParticipantView')/div[2]/table[@class='selector']/tbody/tr[1]/td[8]/span/a[text()='View']");
316 $this->waitForElementPresent('_qf_ContributionView_cancel-bottom');
317
318 $this->webtestVerifyTabularData(
319 array(
320 'From' => $displayName,
321 'Financial Type' => 'Event Fee',
322 'Total Amount' => '$ 800.00',
323 'Contribution Status' => 'Completed',
324 'Paid By' => 'Check',
325 'Check Number' => '1044',
326 )
327 );
328 }
329
42daf119 330 function testEventAddMultipleParticipants() {
6a488035
TO
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;
42daf119 340
c038a4f0 341 $this->openCiviPage("participant/add", "reset=1&action=add&context=standalone&mode=test&eid=3");
6a488035
TO
342
343 $this->assertTrue($this->isTextPresent("Register New Participant"), "Page title 'Register New Participant' 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("Register New Participant"), "Page title 'Register New Participant' 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
c038a4f0 356 $this->openCiviPage("event/search", "reset=1");
6a488035
TO
357 $this->type('sort_name', $firstName);
358 $eventName = "Rain-forest Cup Youth Soccer Tournament";
359 $this->type("event_name", $eventName);
360 $this->click("event_name");
361 $this->waitForElementPresent("css=div.ac_results-inner li");
362 $this->click("css=div.ac_results-inner li");
363 $this->check('participant_test');
364 $this->click("_qf_Search_refresh");
365 $this->waitForElementPresent("participantSearch");
366
367 //verifying the registered participants
368 $names = array( "{$lastName}, {$firstName}", "{$lastName2}, {$firstName}" );
369 $status = "Registered (test)";
370
371 foreach($names as $name) {
372 $this->verifyText("xpath=//div[@id='participantSearch']//table//tbody//tr/td[@class='crm-participant-sort_name']/a[text()='{$name}']/../../td[9]", preg_quote($status));
373 $this->verifyText("xpath=//div[@id='participantSearch']//table//tbody//tr/td[@class='crm-participant-sort_name']/a[text()='{$name}']/../../td[4]/a", preg_quote($eventName));
374}
375 }
376
377 function _fillParticipantDetails($firstName, $lastName, $processorId) {
378 $this->select("id=profiles_1", "label=New Individual");
379 $this->waitForElementPresent('_qf_Edit_next');
380
381 $this->type("id=first_name", $firstName);
382 $this->type("id=last_name", $lastName);
383 $this->click("id=_qf_Edit_next");
384 $this->select('payment_processor_id', "value={$processorId}");
385 $this->verifySelectedValue("event_id", "3");
386 $this->check("role_id[1]");
387 $this->webtestAddCreditCardDetails();
388 $this->webtestAddBillingDetails();
389 }
390}
391