add a few remaining missing comment blocks (autogenerated)
[civicrm-core.git] / tests / phpunit / WebTest / Event / TellAFriendTest.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
06a1bc01 4 | CiviCRM version 4.5 |
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
TO
27require_once 'CiviTest/CiviSeleniumTestCase.php';
28class WebTest_Event_TellAFriendTest extends CiviSeleniumTestCase {
29
30 protected function setUp() {
31 parent::setUp();
32 }
33
34 function testAddEvent() {
6a488035 35 // Log in using webtestLogin() method
42daf119 36 $this->webtestLogin('admin');
6a488035 37
071a6d2e 38 $this->openCiviPage("event/add", "reset=1&action=add");
6a488035
TO
39
40 $eventTitle = 'My Conference - ' . substr(sha1(rand()), 0, 7);
41 $eventDescription = "Here is a description for this conference.";
42 $this->_testAddEventInfo($eventTitle, $eventDescription);
43
44 $streetAddress = "100 Main Street";
45 $this->_testAddLocation($streetAddress);
46
47 // intro text for registration page
48 $registerIntro = "Fill in all the fields below and click Continue.";
49 $multipleRegistrations = TRUE;
50 $this->_testAddOnlineRegistration($registerIntro, $multipleRegistrations);
51
52 // enable tell a friend
53 $subject = "$eventTitle Tell A Friend";
54 $thankYouMsg = "$eventTitle Tell A Friend Test Thankyou Message";
55 $this->_testAddTellAFriend($subject, $thankYouMsg, $eventTitle);
56
57 // get the url for registration
673c7418 58 $this->waitForElementPresent("xpath=//div[@id='event_status_id']//div[@id='option11_wrapper']/table/tbody//tr/td[1]/a[text()='$eventTitle']");
6a488035
TO
59 $this->click("link=$eventTitle");
60 $this->waitForElementPresent("link=Register Now");
61 $this->click("link=Register Now");
62 $this->waitForElementPresent("_qf_Register_upload-bottom");
63 $registerUrl = $this->getLocation();
64
65 // give permissions for event registration
66 $permission = array('edit-1-register-for-events');
67 $this->changePermissions($permission);
68
69 // register as an anonymous user
42daf119 70 $this->webtestLogout();
6a488035
TO
71 $this->open($registerUrl);
72 $this->waitForElementPresent('_qf_Register_upload-bottom');
73
2325644f 74 $firstName = 'Jane' .substr(sha1(rand()), 0, 7);
75 $lastName = 'Doe' . substr(sha1(rand()), 0, 7);
76 $this->type('first_name', "$firstName");
77 $this->type('last_name', "$lastName");
78 $this->type('email-Primary', "$firstName@$lastName.com");
6a488035
TO
79 $this->click('_qf_Register_upload-bottom');
80 $this->waitForPageToLoad($this->getTimeoutMsec());
673c7418 81 $this->click('_qf_Confirm_next-bottom');
82 $this->waitForPageToLoad($this->getTimeoutMsec());
6a488035
TO
83 $this->click("css=div.crm-event-thankyou-form-block div#tell-a-friend a");
84 $this->waitForElementPresent('_qf_Form_cancel');
85
86 $this->type('suggested_message', '$subject Test Message for the recipients');
87
88 // fill the recipients
89 $firstName1 = 'John' . substr(sha1(rand()), 0, 7);
90 $lastName1 = substr(sha1(rand()), 0, 7);
91 $this->type('friend_1_first_name', "$firstName1");
92 $this->type('friend_1_last_name', "$lastName1");
93 $this->type('friend_1_email', "$firstName1@$lastName1.com");
94
95 $firstName2 = 'Smith' . substr(sha1(rand()), 0, 7);
96 $lastName2 = substr(sha1(rand()), 0, 7);
97 $this->type('friend_2_first_name', "$firstName2");
98 $this->type('friend_2_last_name', "$lastName2");
99 $this->type('friend_2_email', "$firstName2@$lastName2.com");
100
101 $firstName3 = 'James' . substr(sha1(rand()), 0, 7);
102 $lastName3 = substr(sha1(rand()), 0, 7);
103 $this->type('friend_3_first_name', "$firstName3");
104 $this->type('friend_3_last_name', "$lastName3");
105 $this->type('friend_3_email', "$firstName3@$lastName3.com");
106
107 $this->click('_qf_Form_submit');
108 $this->waitForPageToLoad($this->getTimeoutMsec());
109
efb29358 110 $this->waitForTextPresent($thankYouMsg);
6a488035
TO
111
112 // Log in using webtestLogin() method
6a488035
TO
113 $this->webtestLogin();
114
115 // get all friends contact id
42daf119 116 $this->openCiviPage("contact/search", "reset=1", '_qf_Basic_refresh');
6a488035
TO
117 $this->type('sort_name', $firstName1);
118 $this->click('_qf_Basic_refresh ');
119 $this->waitForPageToLoad($this->getTimeoutMsec());
120 $this->click("xpath=//div[@class='crm-search-results']/table/tbody/tr/td[11]/span/a[text()='View']");
121 $this->waitForPageToLoad($this->getTimeoutMsec());
122
42daf119 123 $this->openCiviPage("contact/search", "reset=1", '_qf_Basic_refresh');
6a488035
TO
124 $this->type('sort_name', $firstName2);
125 $this->click('_qf_Basic_refresh ');
126 $this->waitForPageToLoad($this->getTimeoutMsec());
127 $this->click("xpath=//div[@class='crm-search-results']/table/tbody/tr/td[11]/span/a[text()='View']");
128 $this->waitForPageToLoad($this->getTimeoutMsec());
129
42daf119 130 $this->openCiviPage("contact/search", "reset=1", '_qf_Basic_refresh');
6a488035
TO
131 $this->type('sort_name', $firstName3);
132 $this->click('_qf_Basic_refresh ');
133 $this->waitForPageToLoad($this->getTimeoutMsec());
134 $this->click("xpath=//div[@class='crm-search-results']/table/tbody/tr/td[11]/span/a[text()='View']");
135 $this->waitForPageToLoad($this->getTimeoutMsec());
136
42daf119 137 $this->openCiviPage("contact/search", "reset=1", '_qf_Basic_refresh');
6a488035
TO
138 $this->type('sort_name', $firstName);
139 $this->click('_qf_Basic_refresh ');
ed174dea 140 $this->waitForElementPresent('Go');
6a488035
TO
141 $this->assertTrue($this->isTextPresent('1 Contact'));
142
143 // Verify Activity created
42daf119 144 $this->openCiviPage("activity/search", "reset=1", '_qf_Search_refresh');
6a488035
TO
145 $this->type('sort_name', $firstName1);
146 $this->click('_qf_Search_refresh');
ed174dea 147 $this->waitForElementPresent("Go");
148 $this->click("xpath=//div[@class='crm-search-results']//table[@class='selector row-highlight']/tbody/tr[2]/td[9]/span/a[text()='View']");
6a488035 149 $this->waitForElementPresent('_qf_Activity_cancel-bottom');
ed174dea 150 $this->verifyText("xpath=//table[@class='crm-info-panel']/tbody/tr[1]/td[2]/span/a[1]",
2325644f 151 preg_quote("$lastName, $firstName")
6a488035
TO
152 );
153
ed174dea 154 $this->verifyText("xpath=//table[@class='crm-info-panel']/tbody/tr[2]/td[2]/span/a[1]",
6a488035
TO
155 preg_quote("$lastName1, $firstName1")
156 );
ed174dea 157 $this->verifyText("xpath=//table[@class='crm-info-panel']/tbody/tr[2]/td[2]/span/a[2]",
6a488035
TO
158 preg_quote("$lastName2, $firstName2")
159 );
ed174dea 160 $this->verifyText("xpath=//table[@class='crm-info-panel']/tbody/tr[2]/td[2]/span/a[3]",
6a488035
TO
161 preg_quote("$lastName3, $firstName3")
162 );
163
ed174dea 164 $this->verifyText("xpath=//table[@class='crm-info-panel']/tbody/tr[4]/td[2]/span",
6a488035
TO
165 preg_quote("Tell a Friend:")
166 );
167 }
168
4cbe18b8
EM
169 /**
170 * @param $eventTitle
171 * @param $eventDescription
172 */
6a488035 173 function _testAddEventInfo($eventTitle, $eventDescription) {
6a488035
TO
174 $this->waitForElementPresent("_qf_EventInfo_upload-bottom");
175
6a488035
TO
176 $this->select("event_type_id", "value=1");
177
178 // Attendee role s/b selected now.
179 $this->select("default_role_id", "value=1");
180
181 // Enter Event Title, Summary and Description
182 $this->type("title", $eventTitle);
183 $this->type("summary", "This is a great conference. Sign up now!");
184
185 // Type description in ckEditor (fieldname, text to type, editor)
186 $this->fillRichTextField("description", $eventDescription, 'CKEditor');
187
188 // Choose Start and End dates.
189 // Using helper webtestFillDate function.
190 $this->webtestFillDateTime("start_date", "+1 week");
191 $this->webtestFillDateTime("end_date", "+1 week 1 day 8 hours ");
192
193 $this->type("max_participants", "50");
194 $this->click("is_map");
195 $this->click("_qf_EventInfo_upload-bottom");
196 }
197
4cbe18b8
EM
198 /**
199 * @param $streetAddress
200 */
6a488035
TO
201 function _testAddLocation($streetAddress) {
202 // Wait for Location tab form to load
203 $this->waitForPageToLoad($this->getTimeoutMsec());
204 $this->waitForElementPresent("_qf_Location_upload-bottom");
205
206 // Fill in address fields
207 $streetAddress = "100 Main Street";
208 $this->type("address_1_street_address", $streetAddress);
209 $this->type("address_1_city", "San Francisco");
210 $this->type("address_1_postal_code", "94117");
211 $this->select("address_1_state_province_id", "value=1004");
212 $this->type("email_1_email", "info@civicrm.org");
213
214 $this->click("_qf_Location_upload-bottom");
215
216 // Wait for "saved" status msg
ed174dea 217 $this->waitForElementPresent("_qf_Location_upload-bottom");
218 $this->waitForTextPresent("'Event Location' information has been saved.");
6a488035
TO
219 }
220
4cbe18b8
EM
221 /**
222 * @param $registerIntro
223 * @param bool $multipleRegistrations
224 */
6a488035
TO
225 function _testAddOnlineRegistration($registerIntro, $multipleRegistrations = FALSE) {
226 // Go to Online Registration tab
227 $this->click("link=Online Registration");
228 $this->waitForElementPresent("_qf_Registration_upload-bottom");
229
230 $this->check("is_online_registration");
231 $this->assertChecked("is_online_registration");
232 if ($multipleRegistrations) {
233 $this->check("is_multiple_registrations");
234 $this->assertChecked("is_multiple_registrations");
235 }
236
237 $this->fillRichTextField("intro_text", $registerIntro);
238
239 // enable confirmation email
240 $this->click('xpath=//fieldset[@id="mail"]/div/table/tbody/tr/td[2]/label[contains(text(), "Yes")]');
241 $this->type("confirm_from_name", "Jane Doe");
242 $this->type("confirm_from_email", "jane.doe@example.org");
243
244 $this->click("_qf_Registration_upload-bottom");
ed174dea 245 $this->waitForElementPresent("_qf_Registration_upload-bottom");
246 $this->waitForTextPresent("'Online Registration' information has been saved.");
6a488035
TO
247 }
248
4cbe18b8
EM
249 /**
250 * @param $subject
251 * @param $thankYouMsg
252 * @param $eventTitle
253 */
6a488035
TO
254 function _testAddTellAFriend($subject, $thankYouMsg, $eventTitle) {
255 // Go to Tell A Friend Tab
256 $this->click('link=Tell a Friend');
257 $this->waitForElementPresent('_qf_Event_cancel-bottom');
258
259 // Enable tell a friend feature
260 $this->check('tf_is_active');
261 $this->waitForElementPresent('tf_thankyou_text');
262
263 // Modify the messages
264 $this->type('intro', "This is $subject Test intro text");
265 $this->type('suggested_message', "$subject Test Message. This is amazing!");
266
267 $this->type('tf_thankyou_title', 'Test thank you title');
268 $this->type('tf_thankyou_text', $thankYouMsg);
269
270 $this->click('_qf_Event_upload_done-bottom');
673c7418 271 $this->waitForElementPresent("xpath=//div[@id='event_status_id']//div[@id='option11_wrapper']/table/tbody//tr/td[1]/a[text()='$eventTitle']");
6a488035
TO
272 }
273}
274