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