Commit | Line | Data |
---|---|---|
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 | ||
6a488035 TO |
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() { | |
42daf119 | 35 | $this->webtestLogin('admin'); |
6a488035 TO |
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 | |
9042f10e | 70 | $this->enableComponents(array('CiviCampaign')); |
6a488035 | 71 | |
42daf119 | 72 | // add the required permission |
6a488035 TO |
73 | $permissions = array('edit-2-administer-civicampaign', 'edit-1-register-for-events'); |
74 | $this->changePermissions($permissions); | |
75 | ||
42daf119 CW |
76 | // Log in as normal user |
77 | $this->webtestLogin(); | |
78 | ||
9042f10e | 79 | $this->openCiviPage("campaign/add", "reset=1", "_qf_Campaign_upload-bottom"); |
6a488035 | 80 | |
6a488035 TO |
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 | ||
6c5f7368 | 105 | $this->waitForText('crm-notification-container', "Campaign $title"); |
6a488035 TO |
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]"); | |
9042f10e | 109 | |
6a488035 TO |
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 | ||
9042f10e | 118 | $this->openCiviPage("event/add", "reset=1&action=add"); |
6a488035 TO |
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; | |
9042f10e | 142 | |
6a488035 TO |
143 | $this->_testOnlineRegistration($campaignTitle, $registerUrl, $numberRegistrations, $anonymous); |
144 | } | |
145 | ||
146 | function _testAddEventInfo($id, $eventTitle, $eventDescription) { | |
6a488035 TO |
147 | $this->waitForElementPresent("_qf_EventInfo_upload-bottom"); |
148 | ||
6a488035 TO |
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 | ||
6c5f7368 | 188 | $this->clickLink("_qf_Location_upload-bottom"); |
6a488035 TO |
189 | |
190 | // Wait for "saved" status msg | |
6c5f7368 | 191 | $this->waitForText('crm-notification-container', "saved"); |
6a488035 TO |
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()); | |
6c5f7368 | 221 | $this->waitForText('crm-notification-container', "saved"); |
6a488035 TO |
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()); | |
6c5f7368 | 245 | $this->waitForText('crm-notification-container', "saved"); |
6a488035 TO |
246 | } |
247 | ||
248 | function _testVerifyEventInfo($eventTitle, $eventInfoStrings) { | |
249 | // verify event input on info page | |
250 | // start at Manage Events listing | |
9042f10e | 251 | $this->openCiviPage("event/manage", "reset=1"); |
225a8648 | 252 | $this->clickLink("link=$eventTitle", "link=Register Now"); |
6a488035 TO |
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) { | |
42daf119 | 268 | $this->webtestLogout(); |
6a488035 TO |
269 | } |
270 | $this->open($registerUrl); | |
271 | ||
272 | $this->select("additional_participants", "value=" . $numberRegistrations); | |
273 | $email = "smith" . substr(sha1(rand()), 0, 7) . "@example.org"; | |
274 | ||
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", "Smith" . substr(sha1(rand()), 0, 7)); | |
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("email-Primary", "smith" . substr(sha1(rand()), 0, 7) . "@example.org"); | |
298 | $this->click("_qf_Participant_{$i}_next"); | |
299 | } | |
300 | } | |
301 | ||
302 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
303 | $this->waitForElementPresent("_qf_Confirm_next-bottom"); | |
304 | $confirmStrings = array("Event Fee(s)", "Billing Name and Address", "Credit Card Information"); | |
305 | $this->assertStringsPresent($confirmStrings); | |
306 | $this->click("_qf_Confirm_next-bottom"); | |
307 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
308 | $thankStrings = array("Thank You for Registering", "Event Total", "Transaction Date"); | |
309 | $this->assertStringsPresent($thankStrings); | |
310 | ||
6a488035 | 311 | $this->webtestLogin(); |
9042f10e | 312 | $this->openCiviPage('event/search', 'reset=1', '_qf_Search_refresh'); |
6a488035 TO |
313 | |
314 | $this->type('sort_name', $email); | |
315 | $this->click("_qf_Search_refresh"); | |
316 | $this->waitForElementPresent("_qf_Search_next_print"); | |
317 | $this->click("xpath=//div[@id='participantSearch']/table/tbody/tr/td[11]/span/a[text()='Edit']"); | |
318 | $this->waitForElementPresent("_qf_Participant_cancel-bottom"); | |
9042f10e | 319 | $this->assertElementContainsText('crm-container', "$campaignTitle"); |
6a488035 | 320 | } |
b9715b8a | 321 | } |