Merge pull request #2564 from jaapjansma/CRM-14276
[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[@class='dataTables_wrapper']/table/tbody/tr/td[text()='{$campaignTitle}']/../td[1]");
108 $id = (int) $this->getText("//div[@id='campaignList']/div[@class='dataTables_wrapper']/table/tbody/tr/td[text()='{$campaignTitle}']/../td[1]");
109
110 $this->onlineParticipantAddTest($campaignTitle, $id);
111 }
112
113 function onlineParticipantAddTest($campaignTitle, $id) {
114 // We need a payment processor
115 $processorName = "Webtest Dummy" . substr(sha1(rand()), 0, 7);
116 $paymentProcessorId = $this->webtestAddPaymentProcessor($processorName);
117
118 $this->openCiviPage("event/add", "reset=1&action=add");
119
120 $eventTitle = 'My Conference - ' . substr(sha1(rand()), 0, 7);
121 $eventDescription = "Here is a description for this conference.";
122 $this->_testAddEventInfo($id, $eventTitle, $eventDescription);
123
124 $streetAddress = "100 Main Street";
125 $this->_testAddLocation($streetAddress);
126
127 $this->_testAddFees(FALSE, FALSE, $paymentProcessorId);
128
129 // intro text for registration page
130 $registerIntro = "Fill in all the fields below and click Continue.";
131 $multipleRegistrations = TRUE;
132 $this->_testAddOnlineRegistration($registerIntro, $multipleRegistrations);
133
134 $eventInfoStrings = array($eventTitle, $eventDescription, $streetAddress);
135 $this->_testVerifyEventInfo($eventTitle, $eventInfoStrings);
136
137 $registerStrings = array("$ 250.00 Member", "$ 325.00 Non-member", $registerIntro);
138 $registerUrl = $this->_testVerifyRegisterPage($registerStrings);
139
140 $numberRegistrations = 3;
141 $anonymous = TRUE;
142
143 $this->_testOnlineRegistration($campaignTitle, $registerUrl, $numberRegistrations, $anonymous);
144 }
145
146 function _testAddEventInfo($id, $eventTitle, $eventDescription) {
147 $this->waitForElementPresent("_qf_EventInfo_upload-bottom");
148
149 $this->select("event_type_id", "value=1");
150
151 // select campaign
152 $this->click("campaign_id");
153 $this->select("campaign_id", "value=$id");
154
155 // Attendee role s/b selected now.
156 $this->select("default_role_id", "value=1");
157
158 // Enter Event Title, Summary and Description
159 $this->type("title", $eventTitle);
160 $this->type("summary", "This is a great conference. Sign up now!");
161
162 // Type description in ckEditor (fieldname, text to type, editor)
163 $this->fillRichTextField("description", $eventDescription, 'CKEditor');
164
165 // Choose Start and End dates.
166 // Using helper webtestFillDate function.
167 $this->webtestFillDateTime("start_date", "+1 week");
168 $this->webtestFillDateTime("end_date", "+1 week 1 day 8 hours ");
169
170 $this->type("max_participants", "50");
171 $this->click("is_map");
172 $this->click("_qf_EventInfo_upload-bottom");
173 }
174
175 function _testAddLocation($streetAddress) {
176 // Wait for Location tab form to load
177 $this->waitForElementPresent("_qf_Location_upload-bottom");
178
179 // Fill in address fields
180 $streetAddress = "100 Main Street";
181 $this->type("address_1_street_address", $streetAddress);
182 $this->type("address_1_city", "San Francisco");
183 $this->type("address_1_postal_code", "94117");
184 $this->select("address_1_state_province_id", "value=1004");
185 $this->type("email_1_email", "info@civicrm.org");
186
187 $this->clickLink("_qf_Location_upload-bottom", '', FALSE);
188
189 // Wait for "saved" status msg
190 $this->waitForText('crm-notification-container', "saved");
191 }
192
193 function _testAddFees($discount = FALSE, $priceSet = FALSE, $processorId) {
194 // Go to Fees tab
195 $this->click("link=Fees");
196 $this->waitForElementPresent("_qf_Fee_upload-bottom");
197 $this->click("CIVICRM_QFID_1_is_monetary");
198 $this->check("payment_processor[$processorId]");
199 $this->select("financial_type_id", "value=4");
200 if ($priceSet) {
201 // get one - TBD
202 }
203 else {
204 $this->type("label_1", "Member");
205 $this->type("value_1", "250.00");
206 $this->type("label_2", "Non-member");
207 $this->type("value_2", "325.00");
208 //add a default fee
209 $this->check("xpath=//table[@id='map-field-table']/tbody/tr[2]/td[3]/input[@name='default']");
210 }
211
212 if ($discount) {
213 // enter early bird discounts TBD
214 }
215
216 $this->click("_qf_Fee_upload-bottom");
217
218 // Wait for "saved" status msg
219 $this->waitForText('crm-notification-container', "saved");
220 }
221
222 function _testAddOnlineRegistration($registerIntro, $multipleRegistrations = FALSE) {
223 // Go to Online Registration tab
224 $this->click("link=Online Registration");
225 $this->waitForElementPresent("_qf_Registration_upload-bottom");
226
227 $this->check("is_online_registration");
228 $this->assertChecked("is_online_registration");
229 if ($multipleRegistrations) {
230 $this->check("is_multiple_registrations");
231 $this->assertChecked("is_multiple_registrations");
232 }
233
234 $this->fillRichTextField("intro_text", $registerIntro);
235
236 // enable confirmation email
237 $this->click("CIVICRM_QFID_1_is_email_confirm");
238 $this->type("confirm_from_name", "Jane Doe");
239 $this->type("confirm_from_email", "jane.doe@example.org");
240
241 $this->click("_qf_Registration_upload-bottom");
242 $this->waitForText('crm-notification-container', "saved");
243 }
244
245 function _testVerifyEventInfo($eventTitle, $eventInfoStrings) {
246 // verify event input on info page
247 // start at Manage Events listing
248 $this->openCiviPage("event/manage", "reset=1");
249 $this->clickLink("link=$eventTitle", "link=Register Now");
250
251 // Check for correct event info strings
252 $this->assertStringsPresent($eventInfoStrings);
253 }
254
255 function _testVerifyRegisterPage($registerStrings) {
256 // Go to Register page and check for intro text and fee levels
257 $this->click("link=Register Now");
258 $this->waitForElementPresent("_qf_Register_upload-bottom");
259 $this->assertStringsPresent($registerStrings);
260 return $this->getLocation();
261 }
262
263 function _testOnlineRegistration($campaignTitle, $registerUrl, $numberRegistrations = 1, $anonymous = TRUE) {
264 if ($anonymous) {
265 $this->webtestLogout();
266 }
267 $this->open($registerUrl);
268
269 $this->select("additional_participants", "value=" . $numberRegistrations);
270
271 $this->type("first_name", 'Jane');
272 $lastName = "Smith" . substr(sha1(rand()), 0, 7);
273 $this->type("last_name", $lastName);
274 $email = "smith" . substr(sha1(rand()), 0, 7) . "@example.org";
275 $this->type("email-Primary", $email);
276
277 $this->select("credit_card_type", "value=Visa");
278 $this->type("credit_card_number", "4111111111111111");
279 $this->type("cvv2", "000");
280 $this->select("credit_card_exp_date[M]", "value=1");
281 $this->select("credit_card_exp_date[Y]", "value=2020");
282 $this->type("billing_first_name", "Jane");
283 $this->type("billing_last_name", $lastName);
284 $this->type("billing_street_address-5", "15 Main St.");
285 $this->type(" billing_city-5", "San Jose");
286 $this->select("billing_country_id-5", "value=1228");
287 $this->select("billing_state_province_id-5", "value=1004");
288 $this->type("billing_postal_code-5", "94129");
289
290 $this->click("_qf_Register_upload-bottom");
291
292 if ($numberRegistrations > 1) {
293 for ($i = 1; $i <= $numberRegistrations; $i++) {
294 $this->waitForPageToLoad($this->getTimeoutMsec());
295 // Look for Skip button
296 $this->waitForElementPresent("_qf_Participant_{$i}_next_skip-Array");
297 $this->type("first_name", "Jane Add $i");
298 $this->type("last_name", "Smith" . substr(sha1(rand()), 0, 7));
299 $this->type("email-Primary", "smith" . substr(sha1(rand()), 0, 7) . "@example.org");
300 $this->click("_qf_Participant_{$i}_next");
301 }
302 }
303
304 $this->waitForPageToLoad($this->getTimeoutMsec());
305 $this->waitForElementPresent("_qf_Confirm_next-bottom");
306 $confirmStrings = array("Event Fee(s)", "Billing Name and Address", "Credit Card Information");
307 $this->assertStringsPresent($confirmStrings);
308 $this->click("_qf_Confirm_next-bottom");
309 $this->waitForPageToLoad($this->getTimeoutMsec());
310 $thankStrings = array("Thank You for Registering", "Event Total", "Transaction Date");
311 $this->assertStringsPresent($thankStrings);
312
313 $this->webtestLogin();
314 $this->openCiviPage('event/search', 'reset=1', '_qf_Search_refresh');
315
316 $this->type('sort_name', $email);
317 $this->click("_qf_Search_refresh");
318 $this->waitForElementPresent("//*[@id='participantSearch']");
319 $this->click("xpath=//div[@id='participantSearch']/table/tbody/tr/td[11]/span/a[text()='Edit']");
320 $this->waitForElementPresent("_qf_Participant_cancel-bottom");
321 $this->assertElementContainsText('crm-container', "$campaignTitle");
322 }
323 }