webtest cleanup and code improvement(using helper function)
[civicrm-core.git] / tests / phpunit / WebTest / Campaign / OnlineEventRegistrationTest.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_Campaign_OnlineEventRegistrationTest extends CiviSeleniumTestCase {
30
31 protected function setUp() {
32 parent::setUp();
33 }
34
35 function testCreateCampaign() {
36 // This is the path where our testing install resides.
37 // The rest of URL is defined in CiviSeleniumTestCase base class, in
38 // class attributes.
39 $this->open($this->sboxPath);
40
41 // Logging in. Remember to wait for page to load. In most cases,
42 // you can rely on 30000 as the value that allows your test to pass, however,
43 // sometimes your test might fail because of this. In such cases, it's better to pick one element
44 // somewhere at the end of page and use waitForElementPresent on it - this assures you, that whole
45 // page contents loaded and you can continue your test execution.
46 $this->webtestLogin();
47
48 // Create new group
49 $title = substr(sha1(rand()), 0, 7);
50 $groupName = $this->WebtestAddGroup();
51
52 // Adding contact
53 // We're using Quick Add block on the main page for this.
54 $firstName1 = substr(sha1(rand()), 0, 7);
55 $this->webtestAddContact($firstName1, "Smith", "$firstName1.smith@example.org");
56
57 // add contact to group
58 // visit group tab
59 $this->click("css=li#tab_group a");
60 $this->waitForElementPresent("group_id");
61
62 // add to group
63 $this->select("group_id", "label=$groupName");
64 $this->click("_qf_GroupContact_next");
65 $this->waitForPageToLoad($this->getTimeoutMsec());
66
67 $firstName2 = substr(sha1(rand()), 0, 7);
68 $this->webtestAddContact($firstName2, "John", "$firstName2.john@example.org");
69
70 // add contact to group
71 // visit group tab
72 $this->click("css=li#tab_group a");
73 $this->waitForElementPresent("group_id");
74
75 // add to group
76 $this->select("group_id", "label=$groupName");
77 $this->click("_qf_GroupContact_next");
78 $this->waitForPageToLoad($this->getTimeoutMsec());
79
80 // Enable CiviCampaign module if necessary
9042f10e 81 $this->enableComponents(array('CiviCampaign'));
6a488035
TO
82
83 // add the required Drupal permission
84 $permissions = array('edit-2-administer-civicampaign', 'edit-1-register-for-events');
85 $this->changePermissions($permissions);
86
87 // Go directly to the URL of the screen that you will be testing
9042f10e 88 $this->openCiviPage("campaign/add", "reset=1", "_qf_Campaign_upload-bottom");
6a488035
TO
89
90 // Let's start filling the form with values.
91 $campaignTitle = "Campaign $title";
92 $this->type("title", $campaignTitle);
93
94 // select the campaign type
95 $this->select("campaign_type_id", "value=2");
96
97 // fill in the description
98 $this->type("description", "This is a test campaign");
99
100 // include groups for the campaign
101 $this->addSelection("includeGroups-f", "label=$groupName");
102 $this->click("//option[@value=4]");
103 $this->click("add");
104
105 // fill the end date for campaign
106 $this->webtestFillDate("end_date", "+1 year");
107
108 // select campaign status
109 $this->select("status_id", "value=2");
110
111 // click save
112 $this->click("_qf_Campaign_upload-bottom");
113 $this->waitForPageToLoad($this->getTimeoutMsec());
114
9042f10e 115 $this->assertElementContainsText('crm-notification-container', "Campaign Campaign $title has been saved.",
6a488035
TO
116 "Status message didn't show up after saving campaign!"
117 );
118
119 $this->waitForElementPresent("//div[@id='campaignList']/div[@class='dataTables_wrapper']/table/tbody/tr/td[text()='{$campaignTitle}']/../td[1]");
120 $id = (int) $this->getText("//div[@id='campaignList']/div[@class='dataTables_wrapper']/table/tbody/tr/td[text()='{$campaignTitle}']/../td[1]");
9042f10e 121
6a488035
TO
122 $this->onlineParticipantAddTest($campaignTitle, $id);
123 }
124
125 function onlineParticipantAddTest($campaignTitle, $id) {
126 // We need a payment processor
127 $processorName = "Webtest Dummy" . substr(sha1(rand()), 0, 7);
128 $paymentProcessorId = $this->webtestAddPaymentProcessor($processorName);
129
130 // Go directly to the URL of the screen that you will be testing (New Event).
9042f10e 131 $this->openCiviPage("event/add", "reset=1&action=add");
6a488035
TO
132
133 $eventTitle = 'My Conference - ' . substr(sha1(rand()), 0, 7);
134 $eventDescription = "Here is a description for this conference.";
135 $this->_testAddEventInfo($id, $eventTitle, $eventDescription);
136
137 $streetAddress = "100 Main Street";
138 $this->_testAddLocation($streetAddress);
139
140 $this->_testAddFees(FALSE, FALSE, $paymentProcessorId);
141
142 // intro text for registration page
143 $registerIntro = "Fill in all the fields below and click Continue.";
144 $multipleRegistrations = TRUE;
145 $this->_testAddOnlineRegistration($registerIntro, $multipleRegistrations);
146
147 $eventInfoStrings = array($eventTitle, $eventDescription, $streetAddress);
148 $this->_testVerifyEventInfo($eventTitle, $eventInfoStrings);
149
150 $registerStrings = array("$ 250.00 Member", "$ 325.00 Non-member", $registerIntro);
151 $registerUrl = $this->_testVerifyRegisterPage($registerStrings);
152
153 $numberRegistrations = 3;
154 $anonymous = TRUE;
9042f10e 155
6a488035
TO
156 $this->_testOnlineRegistration($campaignTitle, $registerUrl, $numberRegistrations, $anonymous);
157 }
158
159 function _testAddEventInfo($id, $eventTitle, $eventDescription) {
160 // As mentioned before, waitForPageToLoad is not always reliable. Below, we're waiting for the submit
161 // button at the end of this page to show up, to make sure it's fully loaded.
162 $this->waitForElementPresent("_qf_EventInfo_upload-bottom");
163
164 // Let's start filling the form with values.
165 $this->select("event_type_id", "value=1");
166
167 // select campaign
168 $this->click("campaign_id");
169 $this->select("campaign_id", "value=$id");
170
171 // Attendee role s/b selected now.
172 $this->select("default_role_id", "value=1");
173
174 // Enter Event Title, Summary and Description
175 $this->type("title", $eventTitle);
176 $this->type("summary", "This is a great conference. Sign up now!");
177
178 // Type description in ckEditor (fieldname, text to type, editor)
179 $this->fillRichTextField("description", $eventDescription, 'CKEditor');
180
181 // Choose Start and End dates.
182 // Using helper webtestFillDate function.
183 $this->webtestFillDateTime("start_date", "+1 week");
184 $this->webtestFillDateTime("end_date", "+1 week 1 day 8 hours ");
185
186 $this->type("max_participants", "50");
187 $this->click("is_map");
188 $this->click("_qf_EventInfo_upload-bottom");
189 }
190
191 function _testAddLocation($streetAddress) {
192 // Wait for Location tab form to load
193 $this->waitForPageToLoad($this->getTimeoutMsec());
194 $this->waitForElementPresent("_qf_Location_upload-bottom");
195
196 // Fill in address fields
197 $streetAddress = "100 Main Street";
198 $this->type("address_1_street_address", $streetAddress);
199 $this->type("address_1_city", "San Francisco");
200 $this->type("address_1_postal_code", "94117");
201 $this->select("address_1_state_province_id", "value=1004");
202 $this->type("email_1_email", "info@civicrm.org");
203
204 $this->click("_qf_Location_upload-bottom");
205
206 // Wait for "saved" status msg
207 $this->waitForPageToLoad($this->getTimeoutMsec());
208 $this->waitForTextPresent("'Location' information has been saved.");
209 }
210
211 function _testAddFees($discount = FALSE, $priceSet = FALSE, $processorId) {
212 // Go to Fees tab
213 $this->click("link=Fees");
214 $this->waitForElementPresent("_qf_Fee_upload-bottom");
215 $this->click("CIVICRM_QFID_1_is_monetary");
216 $this->check("payment_processor[$processorId]");
217 $this->select("financial_type_id", "value=4");
218 if ($priceSet) {
219 // get one - TBD
220 }
221 else {
222 $this->type("label_1", "Member");
223 $this->type("value_1", "250.00");
224 $this->type("label_2", "Non-member");
225 $this->type("value_2", "325.00");
226 //add a default fee
227 $this->check("xpath=//table[@id='map-field-table']/tbody/tr[2]/td[3]/input[@name='default']");
228 }
229
230 if ($discount) {
231 // enter early bird discounts TBD
232 }
233
234 $this->click("_qf_Fee_upload-bottom");
235
236 // Wait for "saved" status msg
237 $this->waitForPageToLoad($this->getTimeoutMsec());
238 $this->waitForTextPresent("'Fee' information has been saved.");
239 }
240
241 function _testAddOnlineRegistration($registerIntro, $multipleRegistrations = FALSE) {
242 // Go to Online Registration tab
243 $this->click("link=Online Registration");
244 $this->waitForElementPresent("_qf_Registration_upload-bottom");
245
246 $this->check("is_online_registration");
247 $this->assertChecked("is_online_registration");
248 if ($multipleRegistrations) {
249 $this->check("is_multiple_registrations");
250 $this->assertChecked("is_multiple_registrations");
251 }
252
253 $this->fillRichTextField("intro_text", $registerIntro);
254
255 // enable confirmation email
256 $this->click("CIVICRM_QFID_1_is_email_confirm");
257 $this->type("confirm_from_name", "Jane Doe");
258 $this->type("confirm_from_email", "jane.doe@example.org");
259
260 $this->click("_qf_Registration_upload-bottom");
261 $this->waitForPageToLoad($this->getTimeoutMsec());
262 $this->waitForTextPresent("'Registration' information has been saved.");
263 }
264
265 function _testVerifyEventInfo($eventTitle, $eventInfoStrings) {
266 // verify event input on info page
267 // start at Manage Events listing
9042f10e 268 $this->openCiviPage("event/manage", "reset=1");
6a488035
TO
269 $this->click("link=$eventTitle");
270
271 $this->waitForPageToLoad($this->getTimeoutMsec());
272 // Look for Register button
273 $this->waitForElementPresent("link=Register Now");
274
275 // Check for correct event info strings
276 $this->assertStringsPresent($eventInfoStrings);
277 }
278
279 function _testVerifyRegisterPage($registerStrings) {
280 // Go to Register page and check for intro text and fee levels
281 $this->click("link=Register Now");
282 $this->waitForElementPresent("_qf_Register_upload-bottom");
283 $this->assertStringsPresent($registerStrings);
284 return $this->getLocation();
285 }
286
287 function _testOnlineRegistration($campaignTitle, $registerUrl, $numberRegistrations = 1, $anonymous = TRUE) {
288 if ($anonymous) {
9042f10e 289 $this->openCiviPage("logout", "reset=1");
6a488035
TO
290 }
291 $this->open($registerUrl);
292
293 $this->select("additional_participants", "value=" . $numberRegistrations);
294 $email = "smith" . substr(sha1(rand()), 0, 7) . "@example.org";
295
296 $this->type("email-Primary", $email);
297
298 $this->select("credit_card_type", "value=Visa");
299 $this->type("credit_card_number", "4111111111111111");
300 $this->type("cvv2", "000");
301 $this->select("credit_card_exp_date[M]", "value=1");
302 $this->select("credit_card_exp_date[Y]", "value=2020");
303 $this->type("billing_first_name", "Jane");
304 $this->type("billing_last_name", "Smith" . substr(sha1(rand()), 0, 7));
305 $this->type("billing_street_address-5", "15 Main St.");
306 $this->type(" billing_city-5", "San Jose");
307 $this->select("billing_country_id-5", "value=1228");
308 $this->select("billing_state_province_id-5", "value=1004");
309 $this->type("billing_postal_code-5", "94129");
310
311 $this->click("_qf_Register_upload-bottom");
312
313 if ($numberRegistrations > 1) {
314 for ($i = 1; $i <= $numberRegistrations; $i++) {
315 $this->waitForPageToLoad($this->getTimeoutMsec());
316 // Look for Skip button
317 $this->waitForElementPresent("_qf_Participant_{$i}_next_skip-Array");
318 $this->type("email-Primary", "smith" . substr(sha1(rand()), 0, 7) . "@example.org");
319 $this->click("_qf_Participant_{$i}_next");
320 }
321 }
322
323 $this->waitForPageToLoad($this->getTimeoutMsec());
324 $this->waitForElementPresent("_qf_Confirm_next-bottom");
325 $confirmStrings = array("Event Fee(s)", "Billing Name and Address", "Credit Card Information");
326 $this->assertStringsPresent($confirmStrings);
327 $this->click("_qf_Confirm_next-bottom");
328 $this->waitForPageToLoad($this->getTimeoutMsec());
329 $thankStrings = array("Thank You for Registering", "Event Total", "Transaction Date");
330 $this->assertStringsPresent($thankStrings);
331
332 $this->open($this->sboxPath);
333 $this->webtestLogin();
9042f10e 334 $this->openCiviPage('event/search', 'reset=1', '_qf_Search_refresh');
6a488035
TO
335
336 $this->type('sort_name', $email);
337 $this->click("_qf_Search_refresh");
338 $this->waitForElementPresent("_qf_Search_next_print");
339 $this->click("xpath=//div[@id='participantSearch']/table/tbody/tr/td[11]/span/a[text()='Edit']");
340 $this->waitForElementPresent("_qf_Participant_cancel-bottom");
9042f10e 341 $this->assertElementContainsText('crm-container', "$campaignTitle");
6a488035 342 }
9042f10e 343}