3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
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 public 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->multiselect2("includeGroups", array("$groupName", "Advisory Board"));
97 // fill the end date for campaign
98 $this->webtestFillDate("end_date", "+1 year");
100 // select campaign status
101 $this->select("status_id", "value=2");
104 $this->click("_qf_Campaign_upload-bottom");
105 $this->waitForPageToLoad($this->getTimeoutMsec());
107 $this->waitForText('crm-notification-container', "Campaign $title");
109 $this->waitForElementPresent("//div[@id='campaignList']/div/table/tbody/tr/td[3]/div[text()='{$campaignTitle}']/../../td[1]");
110 $id = (int) $this->getText("//div[@id='campaignList']/div/table/tbody/tr/td[3]/div[text()='{$campaignTitle}']/../../td[1]");
112 $this->onlineParticipantAddTest($campaignTitle, $id);
116 * @param $campaignTitle
119 public function onlineParticipantAddTest($campaignTitle, $id) {
120 // Use default payment processor
121 $processorName = 'Test Processor';
122 $paymentProcessorId = $this->webtestAddPaymentProcessor($processorName);
124 $this->openCiviPage("event/add", "reset=1&action=add");
126 $eventTitle = 'My Conference - ' . substr(sha1(rand()), 0, 7);
127 $eventDescription = "Here is a description for this conference.";
128 $this->_testAddEventInfo($id, $eventTitle, $eventDescription);
130 $streetAddress = "100 Main Street";
131 $this->_testAddLocation($streetAddress);
133 $this->_testAddFees(FALSE, FALSE, $paymentProcessorId);
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);
140 $eventInfoStrings = array($eventTitle, $eventDescription, $streetAddress);
141 $this->_testVerifyEventInfo($eventTitle, $eventInfoStrings);
143 $registerStrings = array("Member - $ 250.00", "Non-member - $ 325.00", $registerIntro);
144 $registerUrl = $this->_testVerifyRegisterPage($registerStrings);
146 $numberRegistrations = 3;
149 $this->_testOnlineRegistration($campaignTitle, $registerUrl, $numberRegistrations, $anonymous);
155 * @param $eventDescription
157 public function _testAddEventInfo($id, $eventTitle, $eventDescription) {
158 $this->waitForElementPresent("_qf_EventInfo_upload-bottom");
160 $this->select("event_type_id", "value=1");
163 $this->click("campaign_id");
164 $this->select("campaign_id", "value=$id");
166 // Attendee role s/b selected now.
167 $this->select("default_role_id", "value=1");
169 // Enter Event Title, Summary and Description
170 $this->type("title", $eventTitle);
171 $this->type("summary", "This is a great conference. Sign up now!");
173 // Type description in ckEditor (fieldname, text to type, editor)
174 $this->fillRichTextField("description", $eventDescription, 'CKEditor');
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 ");
181 $this->type("max_participants", "50");
182 $this->click("is_map");
183 $this->click("_qf_EventInfo_upload-bottom");
187 * @param $streetAddress
189 public function _testAddLocation($streetAddress) {
190 // Wait for Location tab form to load
191 $this->waitForElementPresent("_qf_Location_upload-bottom");
193 // Fill in address fields
194 $streetAddress = "100 Main Street";
195 $this->waitForElementPresent('address_1_street_address');
196 $this->type("address_1_street_address", $streetAddress);
197 $this->waitForElementPresent('address_1_city');
198 $this->type("address_1_city", "San Francisco");
199 $this->type("address_1_postal_code", "94117");
200 $this->select('address_1_country_id', 'United States');
201 $this->select("address_1_state_province_id", "value=1004");
202 $this->type("email_1_email", "info@civicrm.org");
204 $this->clickLink("_qf_Location_upload-bottom", '', FALSE);
206 // Wait for "saved" status msg
207 $this->waitForText('crm-notification-container', "saved");
211 * @param bool $discount
212 * @param bool $priceSet
213 * @param int $processorId
215 public function _testAddFees($discount = FALSE, $priceSet = FALSE, $processorId) {
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]");
221 $this->select("financial_type_id", "value=4");
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");
231 $this->check("xpath=//table[@id='map-field-table']/tbody/tr[2]/td[3]/input[@name='default']");
235 // enter early bird discounts TBD
238 $this->click("_qf_Fee_upload-bottom");
240 // Wait for "saved" status msg
241 $this->waitForText('crm-notification-container', "saved");
245 * @param $registerIntro
246 * @param bool $multipleRegistrations
248 public function _testAddOnlineRegistration($registerIntro, $multipleRegistrations = FALSE) {
249 // Go to Online Registration tab
250 $this->click("link=Online Registration");
251 $this->waitForElementPresent("_qf_Registration_upload-bottom");
253 $this->click("is_online_registration");
254 $this->assertChecked("is_online_registration");
255 if ($multipleRegistrations) {
256 $this->check("is_multiple_registrations");
257 $this->assertChecked("is_multiple_registrations");
260 $this->click('intro_text-plain');
261 $this->fillRichTextField("intro_text", $registerIntro);
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");
268 $this->click("_qf_Registration_upload-bottom");
269 $this->waitForText('crm-notification-container', "saved");
274 * @param $eventInfoStrings
276 public function _testVerifyEventInfo($eventTitle, $eventInfoStrings) {
277 // verify event input on info page
278 // start at Manage Events listing
279 $this->openCiviPage("event/manage", "reset=1");
280 $this->clickLink("link=$eventTitle", "link=Register Now");
282 // Check for correct event info strings
283 $this->assertStringsPresent($eventInfoStrings);
287 * @param $registerStrings
291 public function _testVerifyRegisterPage($registerStrings) {
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();
300 * @param $campaignTitle
301 * @param $registerUrl
302 * @param int $numberRegistrations
303 * @param bool $anonymous
305 public function _testOnlineRegistration($campaignTitle, $registerUrl, $numberRegistrations = 1, $anonymous = TRUE) {
307 $this->webtestLogout();
309 $this->open($registerUrl);
311 $this->select("additional_participants", "value=" . $numberRegistrations);
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";
317 $this->type("email-Primary", $email);
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");
325 $this->type("billing_last_name", $lastName);
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");
332 $this->click("_qf_Register_upload-bottom");
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");
339 $this->type("first_name", "Jane Add $i");
340 $this->type("last_name", "Smith" . substr(sha1(rand()), 0, 7));
341 $this->type("email-Primary", "smith" . substr(sha1(rand()), 0, 7) . "@example.org");
342 $this->click("_qf_Participant_{$i}_next");
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);
355 $this->webtestLogin();
356 $this->openCiviPage('event/search', 'reset=1', '_qf_Search_refresh');
358 $this->type('sort_name', $email);
359 $this->click("_qf_Search_refresh");
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']");
362 $this->waitForElementPresent("_qf_Participant_cancel-bottom");
363 $this->assertElementContainsText("xpath=//form[@id='Participant']/div[2]/div/table[@class='form-layout-compressed']/tbody/tr[4]/td[2]/select", "$campaignTitle");