Merge remote-tracking branch 'upstream/4.4' into 4.4-master-2014-04-21-08-12-12
[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->waitForPageToLoad($this->getTimeoutMsec());
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->waitForPageToLoad($this->getTimeoutMsec());
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->waitForPageToLoad($this->getTimeoutMsec());
178 $this->waitForElementPresent("_qf_Location_upload-bottom");
179
180 // Fill in address fields
181 $streetAddress = "100 Main Street";
182 $this->type("address_1_street_address", $streetAddress);
183 $this->type("address_1_city", "San Francisco");
184 $this->type("address_1_postal_code", "94117");
185 $this->select("address_1_state_province_id", "value=1004");
186 $this->type("email_1_email", "info@civicrm.org");
187
188 $this->clickLink("_qf_Location_upload-bottom");
189
190 // Wait for "saved" status msg
191 $this->waitForText('crm-notification-container', "saved");
192 }
193
194 function _testAddFees($discount = FALSE, $priceSet = FALSE, $processorId) {
195 // Go to Fees tab
196 $this->click("link=Fees");
197 $this->waitForElementPresent("_qf_Fee_upload-bottom");
198 $this->click("CIVICRM_QFID_1_is_monetary");
199 $this->check("payment_processor[$processorId]");
200 $this->select("financial_type_id", "value=4");
201 if ($priceSet) {
202 // get one - TBD
203 }
204 else {
205 $this->type("label_1", "Member");
206 $this->type("value_1", "250.00");
207 $this->type("label_2", "Non-member");
208 $this->type("value_2", "325.00");
209 //add a default fee
210 $this->check("xpath=//table[@id='map-field-table']/tbody/tr[2]/td[3]/input[@name='default']");
211 }
212
213 if ($discount) {
214 // enter early bird discounts TBD
215 }
216
217 $this->click("_qf_Fee_upload-bottom");
218
219 // Wait for "saved" status msg
220 $this->waitForPageToLoad($this->getTimeoutMsec());
221 $this->waitForText('crm-notification-container', "saved");
222 }
223
224 function _testAddOnlineRegistration($registerIntro, $multipleRegistrations = FALSE) {
225 // Go to Online Registration tab
226 $this->click("link=Online Registration");
227 $this->waitForElementPresent("_qf_Registration_upload-bottom");
228
229 $this->check("is_online_registration");
230 $this->assertChecked("is_online_registration");
231 if ($multipleRegistrations) {
232 $this->check("is_multiple_registrations");
233 $this->assertChecked("is_multiple_registrations");
234 }
235
236 $this->fillRichTextField("intro_text", $registerIntro);
237
238 // enable confirmation email
239 $this->click("CIVICRM_QFID_1_is_email_confirm");
240 $this->type("confirm_from_name", "Jane Doe");
241 $this->type("confirm_from_email", "jane.doe@example.org");
242
243 $this->click("_qf_Registration_upload-bottom");
244 $this->waitForPageToLoad($this->getTimeoutMsec());
245 $this->waitForText('crm-notification-container', "saved");
246 }
247
248 function _testVerifyEventInfo($eventTitle, $eventInfoStrings) {
249 // verify event input on info page
250 // start at Manage Events listing
251 $this->openCiviPage("event/manage", "reset=1");
252 $this->clickLink("link=$eventTitle", "link=Register Now");
253
254 // Check for correct event info strings
255 $this->assertStringsPresent($eventInfoStrings);
256 }
257
258 function _testVerifyRegisterPage($registerStrings) {
259 // Go to Register page and check for intro text and fee levels
260 $this->click("link=Register Now");
261 $this->waitForElementPresent("_qf_Register_upload-bottom");
262 $this->assertStringsPresent($registerStrings);
263 return $this->getLocation();
264 }
265
266 function _testOnlineRegistration($campaignTitle, $registerUrl, $numberRegistrations = 1, $anonymous = TRUE) {
267 if ($anonymous) {
268 $this->webtestLogout();
269 }
270 $this->open($registerUrl);
271
272 $this->select("additional_participants", "value=" . $numberRegistrations);
273
274 $this->type("first_name", 'Jane');
275 $lastName = "Smith" . substr(sha1(rand()), 0, 7);
276 $this->type("last_name", $lastName);
277 $email = "smith" . substr(sha1(rand()), 0, 7) . "@example.org";
278 $this->type("email-Primary", $email);
279
280 $this->select("credit_card_type", "value=Visa");
281 $this->type("credit_card_number", "4111111111111111");
282 $this->type("cvv2", "000");
283 $this->select("credit_card_exp_date[M]", "value=1");
284 $this->select("credit_card_exp_date[Y]", "value=2020");
285 $this->type("billing_first_name", "Jane");
286 $this->type("billing_last_name", $lastName);
287 $this->type("billing_street_address-5", "15 Main St.");
288 $this->type(" billing_city-5", "San Jose");
289 $this->select("billing_country_id-5", "value=1228");
290 $this->select("billing_state_province_id-5", "value=1004");
291 $this->type("billing_postal_code-5", "94129");
292
293 $this->click("_qf_Register_upload-bottom");
294
295 if ($numberRegistrations > 1) {
296 for ($i = 1; $i <= $numberRegistrations; $i++) {
297 $this->waitForPageToLoad($this->getTimeoutMsec());
298 // Look for Skip button
299 $this->waitForElementPresent("_qf_Participant_{$i}_next_skip-Array");
300 $this->type("first_name", "Jane Add $i");
301 $this->type("last_name", "Smith" . substr(sha1(rand()), 0, 7));
302 $this->type("email-Primary", "smith" . substr(sha1(rand()), 0, 7) . "@example.org");
303 $this->click("_qf_Participant_{$i}_next");
304 }
305 }
306
307 $this->waitForPageToLoad($this->getTimeoutMsec());
308 $this->waitForElementPresent("_qf_Confirm_next-bottom");
309 $confirmStrings = array("Event Fee(s)", "Billing Name and Address", "Credit Card Information");
310 $this->assertStringsPresent($confirmStrings);
311 $this->click("_qf_Confirm_next-bottom");
312 $this->waitForPageToLoad($this->getTimeoutMsec());
313 $thankStrings = array("Thank You for Registering", "Event Total", "Transaction Date");
314 $this->assertStringsPresent($thankStrings);
315
316 $this->webtestLogin();
317 $this->openCiviPage('event/search', 'reset=1', '_qf_Search_refresh');
318
319 $this->type('sort_name', $email);
320 $this->click("_qf_Search_refresh");
321 $this->waitForElementPresent("_qf_Search_next_print");
322 $this->click("xpath=//div[@id='participantSearch']/table/tbody/tr/td[11]/span/a[text()='Edit']");
323 $this->waitForElementPresent("_qf_Participant_cancel-bottom");
324 $this->assertElementContainsText('crm-container', "$campaignTitle");
325 }
326 }