Merge remote-tracking branch 'upstream/4.5' into 4.5-master-2015-01-12-16-09-32
[civicrm-core.git] / tests / phpunit / WebTest / Event / EventWaitListTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC (c) 2004-2014 |
5 +--------------------------------------------------------------------+
6 | This file is a part of CiviCRM. |
7 | |
8 | CiviCRM is free software; you can copy, modify, and distribute it |
9 | under the terms of the GNU Affero General Public License |
10 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
11 | |
12 | CiviCRM is distributed in the hope that it will be useful, but |
13 | WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
15 | See the GNU Affero General Public License for more details. |
16 | |
17 | You should have received a copy of the GNU Affero General Public |
18 | License along with this program; if not, contact CiviCRM LLC |
19 | at info[AT]civicrm[DOT]org. If you have questions about the |
20 | GNU Affero General Public License or the licensing of CiviCRM, |
21 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
22 +--------------------------------------------------------------------+
23 */
24
25 require_once 'CiviTest/CiviSeleniumTestCase.php';
26
27 /**
28 * Class WebTest_Event_EventWaitListTest
29 */
30 class WebTest_Event_EventWaitListTest extends CiviSeleniumTestCase {
31
32 protected function setUp() {
33 parent::setUp();
34 }
35
36 public function testEventWaitList() {
37 // Log in using webtestLogin() method
38 $this->webtestLogin();
39
40 // Use default payment processor
41 $processorName = 'Test Processor';
42 $this->webtestAddPaymentProcessor($processorName);
43
44 $this->openCiviPage("event/add", "reset=1&action=add");
45
46 $eventTitle = 'My Conference - ' . substr(sha1(rand()), 0, 7);
47 $eventDescription = "Here is a description for this conference.";
48 $this->waitForElementPresent("_qf_EventInfo_upload-bottom");
49
50 $this->select("event_type_id", "value=1");
51
52 // Attendee role s/b selected now.
53 $this->select("default_role_id", "value=1");
54
55 // Enter Event Title, Summary and Description
56 $this->type("title", $eventTitle);
57 $this->type("summary", "This is a great conference. Sign up now!");
58
59 // Type description in ckEditor (fieldname, text to type, editor)
60 $this->fillRichTextField("description", $eventDescription, 'CKEditor');
61
62 // Choose Start and End dates.
63 // Using helper webtestFillDate function.
64 $this->webtestFillDateTime("start_date", "+1 week");
65 $this->webtestFillDateTime("end_date", "+1 week 1 day 8 hours ");
66
67 $this->type("max_participants", "6");
68 $this->click("is_map");
69 $this->click("_qf_EventInfo_upload-bottom");
70
71 $streetAddress = "100 Main Street";
72
73 // Wait for Location tab form to load
74 $this->waitForPageToLoad($this->getTimeoutMsec());
75 $this->waitForElementPresent("_qf_Location_upload-bottom");
76
77 // Fill in address fields
78 $streetAddress = "100 Main Street";
79 $this->type("address_1_street_address", $streetAddress);
80 $this->type("address_1_city", "San Francisco");
81 $this->type("address_1_postal_code", "94117");
82 $this->select('address_1_country_id', 'United States');
83 $this->select("address_1_state_province_id", "value=1004");
84 $this->type("email_1_email", "info@civicrm.org");
85
86 $this->click("_qf_Location_upload-bottom");
87
88 // Wait for "saved" status msg
89 $this->waitForElementPresent("_qf_Location_upload-bottom");
90 $this->waitForTextPresent("'Event Location' information has been saved.");
91
92 // Go to Fees tab
93 $this->click("link=Fees");
94 $this->waitForElementPresent("_qf_Fee_upload-bottom");
95 $this->click("CIVICRM_QFID_1_is_monetary");
96 $this->click("xpath=//tr[@class='crm-event-manage-fee-form-block-payment_processor']/td[2]/label[text()='$processorName']");
97
98 $this->select("financial_type_id", "Donation");
99 $this->type("label_1", "Member");
100 $this->type("value_1", "250.00");
101 $this->type("label_2", "Non-member");
102 $this->type("value_2", "325.00");
103 //set default
104 $this->click("xpath=//table[@id='map-field-table']/tbody/tr[2]/td[3]/input");
105
106 $this->click("_qf_Fee_upload-bottom");
107
108 // Wait for "saved" status msg
109 $this->waitForElementPresent("_qf_Fee_upload-bottom");
110 $this->waitForTextPresent("'Fees' information has been saved.");
111
112 // intro text for registration page
113 $registerIntro = "Fill in all the fields below and click Continue.";
114 $multipleRegistrations = TRUE;
115
116 // Go to Online Registration tab
117 $this->click("link=Online Registration");
118 $this->waitForElementPresent("_qf_Registration_upload-bottom");
119 $this->isTextPresent("BCC Confirmation To");
120 $this->check("is_online_registration");
121 $this->assertChecked("is_online_registration");
122 if ($multipleRegistrations) {
123 $this->check("is_multiple_registrations");
124 $this->assertChecked("is_multiple_registrations");
125 }
126
127 $this->click('intro_text-plain');
128 $this->fillRichTextField("intro_text", $registerIntro);
129
130 // enable confirmation email
131 $this->click("CIVICRM_QFID_1_is_email_confirm");
132 $this->type("confirm_from_name", "Jane Doe");
133 $this->type("confirm_from_email", "jane.doe@example.org");
134
135 $this->click("_qf_Registration_upload-bottom");
136 $this->waitForElementPresent("_qf_Registration_upload-bottom");
137 $this->waitForTextPresent("'Online Registration' information has been saved.");
138
139 $eventInfoStrings = array($eventTitle, $eventDescription, $streetAddress);
140 $this->_testVerifyEventInfo($eventTitle, $eventInfoStrings);
141
142 $registerStrings = array("250.00", "Member", "325.00", "Non-member");
143 $registerUrl = $this->_testVerifyRegisterPage($registerStrings);
144
145 $numberRegistrations = 2;
146 $anonymous = TRUE;
147 $this->_testOnlineRegistration($registerUrl, $numberRegistrations, $anonymous);
148
149 $numberRegistrations = 2;
150 $anonymous = TRUE;
151 $this->_testOnlineRegistration($registerUrl, $numberRegistrations, $anonymous);
152
153 //check whether event is full
154 $this->open($registerUrl);
155 $this->assertStringsPresent("This event is currently full.");
156 }
157
158 /**
159 * @param $eventTitle
160 * @param $eventInfoStrings
161 */
162 public function _testVerifyEventInfo($eventTitle, $eventInfoStrings) {
163 // verify event input on info page
164 // start at Manage Events listing
165 $this->openCiviPage("event/manage", "reset=1");
166 $this->clickLink("link=$eventTitle", "link=Register Now");
167
168 // Check for correct event info strings
169 $this->assertStringsPresent($eventInfoStrings);
170 }
171
172 /**
173 * @param $registerStrings
174 *
175 * @return string
176 */
177 public function _testVerifyRegisterPage($registerStrings) {
178 // Go to Register page and check for intro text and fee levels
179 $this->click("link=Register Now");
180 $this->waitForElementPresent("_qf_Register_upload-bottom");
181 $this->assertStringsPresent($registerStrings);
182 return $this->getLocation();
183 }
184
185 /**
186 * @param $registerUrl
187 * @param int $numberRegistrations
188 * @param bool $anonymous
189 */
190 public function _testOnlineRegistration($registerUrl, $numberRegistrations = 1, $anonymous = TRUE) {
191 if ($anonymous) {
192 $this->webtestLogout();
193 }
194 $this->open($registerUrl);
195
196 $this->select("additional_participants", "value=" . $numberRegistrations);
197 $this->type("first_name", "Jane");
198 $lastName = "Smith" . substr(sha1(rand()), 0, 7);
199 $this->type("last_name", $lastName);
200 $this->type("email-Primary", "smith" . substr(sha1(rand()), 0, 7) . "@example.org");
201
202 $this->select("credit_card_type", "value=Visa");
203 $this->type("credit_card_number", "4111111111111111");
204 $this->type("cvv2", "000");
205 $this->select("credit_card_exp_date[M]", "value=1");
206 $this->select("credit_card_exp_date[Y]", "value=2020");
207 $this->type("billing_first_name", "Jane");
208 $this->type("billing_last_name", $lastName);
209 $this->type("billing_street_address-5", "15 Main St.");
210 $this->type(" billing_city-5", "San Jose");
211 $this->select("billing_country_id-5", "value=1228");
212 $this->select("billing_state_province_id-5", "value=1004");
213 $this->type("billing_postal_code-5", "94129");
214
215 $this->click("_qf_Register_upload-bottom");
216
217 if ($numberRegistrations > 1) {
218 for ($i = 1; $i <= $numberRegistrations; $i++) {
219 $this->waitForPageToLoad($this->getTimeoutMsec());
220 // Look for continue button
221 $this->waitForElementPresent("_qf_Participant_{$i}_next");
222 $this->type("first_name", "Jane Add {$i}");
223 $lastName = "Smith" . substr(sha1(rand()), 0, 7);
224 $this->type("last_name", $lastName);
225 $this->type("email-Primary", "smith" . substr(sha1(rand()), 0, 7) . "@example.org");
226 $this->click("_qf_Participant_{$i}_next");
227 }
228 }
229 $this->waitForPageToLoad($this->getTimeoutMsec());
230 $this->waitForElementPresent("_qf_Confirm_next-bottom");
231 $confirmStrings = array("Event Fee(s)", "Billing Name and Address", "Credit Card Information");
232 $this->assertStringsPresent($confirmStrings);
233 $this->click("_qf_Confirm_next-bottom");
234 $this->waitForPageToLoad($this->getTimeoutMsec());
235 $thankStrings = array("Thank You for Registering", "Event Total", "Transaction Date");
236 $this->assertStringsPresent($thankStrings);
237
238 if ($anonymous) {
239 // log back in so we're in the same state
240 $this->webtestLogin();
241 }
242 }
243 }