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