3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
27 require_once 'CiviTest/CiviSeleniumTestCase.php';
30 * Class WebTest_Campaign_OnlineEventRegistrationTest
32 class WebTest_Campaign_OnlineEventRegistrationTest
extends CiviSeleniumTestCase
{
34 protected function setUp() {
38 function testCreateCampaign() {
39 $this->webtestLogin('admin');
42 $title = substr(sha1(rand()), 0, 7);
43 $groupName = $this->WebtestAddGroup();
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");
50 // add contact to group
52 $this->click("css=li#tab_group a");
53 $this->waitForElementPresent("group_id");
56 $this->select("group_id", "label=$groupName");
57 $this->click("_qf_GroupContact_next");
58 $this->waitForElementPresent('link=Remove');
60 $firstName2 = substr(sha1(rand()), 0, 7);
61 $this->webtestAddContact($firstName2, "John", "$firstName2.john@example.org");
63 // add contact to group
65 $this->click("css=li#tab_group a");
66 $this->waitForElementPresent("group_id");
69 $this->select("group_id", "label=$groupName");
70 $this->click("_qf_GroupContact_next");
71 $this->waitForElementPresent('link=Remove');
73 // Enable CiviCampaign module if necessary
74 $this->enableComponents(array('CiviCampaign'));
76 // add the required permission
77 $permissions = array('edit-2-administer-civicampaign', 'edit-1-register-for-events');
78 $this->changePermissions($permissions);
80 // Log in as normal user
81 $this->webtestLogin();
83 $this->openCiviPage("campaign/add", "reset=1", "_qf_Campaign_upload-bottom");
85 $campaignTitle = "Campaign $title";
86 $this->type("title", $campaignTitle);
88 // select the campaign type
89 $this->select("campaign_type_id", "value=2");
91 // fill in the description
92 $this->type("description", "This is a test campaign");
94 // include groups for the campaign
95 $this->addSelection("includeGroups-f", "label=$groupName");
96 $this->click("//option[@value=4]");
99 // fill the end date for campaign
100 $this->webtestFillDate("end_date", "+1 year");
102 // select campaign status
103 $this->select("status_id", "value=2");
106 $this->click("_qf_Campaign_upload-bottom");
107 $this->waitForPageToLoad($this->getTimeoutMsec());
109 $this->waitForText('crm-notification-container', "Campaign $title");
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]");
114 $this->onlineParticipantAddTest($campaignTitle, $id);
118 * @param $campaignTitle
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);
126 $this->openCiviPage("event/add", "reset=1&action=add");
128 $eventTitle = 'My Conference - ' . substr(sha1(rand()), 0, 7);
129 $eventDescription = "Here is a description for this conference.";
130 $this->_testAddEventInfo($id, $eventTitle, $eventDescription);
132 $streetAddress = "100 Main Street";
133 $this->_testAddLocation($streetAddress);
135 $this->_testAddFees(FALSE, FALSE, $paymentProcessorId);
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);
142 $eventInfoStrings = array($eventTitle, $eventDescription, $streetAddress);
143 $this->_testVerifyEventInfo($eventTitle, $eventInfoStrings);
145 $registerStrings = array("$ 250.00 Member", "$ 325.00 Non-member", $registerIntro);
146 $registerUrl = $this->_testVerifyRegisterPage($registerStrings);
148 $numberRegistrations = 3;
151 $this->_testOnlineRegistration($campaignTitle, $registerUrl, $numberRegistrations, $anonymous);
157 * @param $eventDescription
159 function _testAddEventInfo($id, $eventTitle, $eventDescription) {
160 $this->waitForElementPresent("_qf_EventInfo_upload-bottom");
162 $this->select("event_type_id", "value=1");
165 $this->click("campaign_id");
166 $this->select("campaign_id", "value=$id");
168 // Attendee role s/b selected now.
169 $this->select("default_role_id", "value=1");
171 // Enter Event Title, Summary and Description
172 $this->type("title", $eventTitle);
173 $this->type("summary", "This is a great conference. Sign up now!");
175 // Type description in ckEditor (fieldname, text to type, editor)
176 $this->fillRichTextField("description", $eventDescription, 'CKEditor');
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 ");
183 $this->type("max_participants", "50");
184 $this->click("is_map");
185 $this->click("_qf_EventInfo_upload-bottom");
189 * @param $streetAddress
191 function _testAddLocation($streetAddress) {
192 // Wait for Location tab form to load
193 $this->waitForElementPresent("_qf_Location_upload-bottom");
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");
203 $this->clickLink("_qf_Location_upload-bottom", '', FALSE);
205 // Wait for "saved" status msg
206 $this->waitForText('crm-notification-container', "saved");
210 * @param bool $discount
211 * @param bool $priceSet
212 * @param $processorId
214 function _testAddFees($discount = FALSE, $priceSet = FALSE, $processorId) {
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");
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");
230 $this->check("xpath=//table[@id='map-field-table']/tbody/tr[2]/td[3]/input[@name='default']");
234 // enter early bird discounts TBD
237 $this->click("_qf_Fee_upload-bottom");
239 // Wait for "saved" status msg
240 $this->waitForText('crm-notification-container', "saved");
244 * @param $registerIntro
245 * @param bool $multipleRegistrations
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");
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");
259 $this->fillRichTextField("intro_text", $registerIntro);
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");
266 $this->click("_qf_Registration_upload-bottom");
267 $this->waitForText('crm-notification-container', "saved");
272 * @param $eventInfoStrings
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");
280 // Check for correct event info strings
281 $this->assertStringsPresent($eventInfoStrings);
285 * @param $registerStrings
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();
298 * @param $campaignTitle
299 * @param $registerUrl
300 * @param int $numberRegistrations
301 * @param bool $anonymous
303 function _testOnlineRegistration($campaignTitle, $registerUrl, $numberRegistrations = 1, $anonymous = TRUE) {
305 $this->webtestLogout();
307 $this->open($registerUrl);
309 $this->select("additional_participants", "value=" . $numberRegistrations);
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);
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");
330 $this->click("_qf_Register_upload-bottom");
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");
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);
353 $this->webtestLogin();
354 $this->openCiviPage('event/search', 'reset=1', '_qf_Search_refresh');
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");