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