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