CRM-16876 Change country name to uppercase
[civicrm-core.git] / tests / phpunit / WebTest / Event / TellAFriendTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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
27 require_once 'CiviTest/CiviSeleniumTestCase.php';
28
29 /**
30 * Class WebTest_Event_TellAFriendTest
31 */
32 class WebTest_Event_TellAFriendTest extends CiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
38 public function testAddEvent() {
39 // Log in using webtestLogin() method
40 $this->webtestLogin('admin');
41
42 $this->openCiviPage("event/add", "reset=1&action=add");
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
62 $this->waitForElementPresent("xpath=//div[@id='event_status_id']//div[@id='option11_wrapper']/table/tbody//tr/td[1]/a[text()='$eventTitle']");
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
74 $this->webtestLogout();
75 $this->open($registerUrl);
76 $this->waitForElementPresent('_qf_Register_upload-bottom');
77
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");
83 $this->click('_qf_Register_upload-bottom');
84 $this->waitForPageToLoad($this->getTimeoutMsec());
85 $this->click('_qf_Confirm_next-bottom');
86 $this->waitForPageToLoad($this->getTimeoutMsec());
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
114 $this->waitForTextPresent($thankYouMsg);
115
116 // Log in using webtestLogin() method
117 $this->webtestLogin();
118
119 // get all friends contact id
120 $this->openCiviPage("contact/search", "reset=1", '_qf_Basic_refresh');
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
127 $this->openCiviPage("contact/search", "reset=1", '_qf_Basic_refresh');
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
134 $this->openCiviPage("contact/search", "reset=1", '_qf_Basic_refresh');
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
141 $this->openCiviPage("contact/search", "reset=1", '_qf_Basic_refresh');
142 $this->type('sort_name', $firstName);
143 $this->click('_qf_Basic_refresh ');
144 $this->waitForTextPresent('1 Contact');
145
146 // Verify Activity created
147 $this->openCiviPage("activity/search", "reset=1", '_qf_Search_refresh');
148 $this->type('sort_name', $firstName1);
149 $this->click('_qf_Search_refresh');
150 $this->waitForElementPresent("xpath=//div[@class='crm-search-results']//table[@class='selector row-highlight']/tbody/tr[2]/td[9]/span/a[text()='View']");
151 $this->click("xpath=//div[@class='crm-search-results']//table[@class='selector row-highlight']/tbody/tr[2]/td[9]/span/a[text()='View']");
152 $this->waitForElementPresent('_qf_Activity_cancel-bottom');
153 $this->verifyText("xpath=//table[@class='crm-info-panel']/tbody/tr[1]/td[2]/span/a[1]",
154 preg_quote("$lastName, $firstName")
155 );
156
157 $this->verifyText("xpath=//table[@class='crm-info-panel']/tbody/tr[2]/td[2]/span",
158 preg_quote("$lastName1, $firstName1")
159 );
160 $this->verifyText("xpath=//table[@class='crm-info-panel']/tbody/tr[2]/td[2]/span",
161 preg_quote("$lastName2, $firstName2")
162 );
163 $this->verifyText("xpath=//table[@class='crm-info-panel']/tbody/tr[2]/td[2]/span",
164 preg_quote("$lastName3, $firstName3")
165 );
166
167 $this->verifyText("xpath=//table[@class='crm-info-panel']/tbody/tr[4]/td[2]/span",
168 preg_quote("Tell a Friend:")
169 );
170 }
171
172 /**
173 * @param $eventTitle
174 * @param $eventDescription
175 */
176 public function _testAddEventInfo($eventTitle, $eventDescription) {
177 $this->waitForElementPresent("_qf_EventInfo_upload-bottom");
178
179 $this->select("event_type_id", "value=1");
180
181 // Attendee role s/b selected now.
182 $this->select("default_role_id", "value=1");
183
184 // Enter Event Title, Summary and Description
185 $this->type("title", $eventTitle);
186 $this->type("summary", "This is a great conference. Sign up now!");
187
188 // Type description in ckEditor (fieldname, text to type, editor)
189 $this->fillRichTextField("description", $eventDescription, 'CKEditor');
190
191 // Choose Start and End dates.
192 // Using helper webtestFillDate function.
193 $this->webtestFillDateTime("start_date", "+1 week");
194 $this->webtestFillDateTime("end_date", "+1 week 1 day 8 hours ");
195
196 $this->type("max_participants", "50");
197 $this->click("is_map");
198 $this->click("_qf_EventInfo_upload-bottom");
199 }
200
201 /**
202 * @param $streetAddress
203 */
204 public function _testAddLocation($streetAddress) {
205 // Wait for Location tab form to load
206 $this->waitForPageToLoad($this->getTimeoutMsec());
207 $this->waitForElementPresent("_qf_Location_upload-bottom");
208
209 // Fill in address fields
210 $streetAddress = "100 Main Street";
211 $this->type("address_1_street_address", $streetAddress);
212 $this->type("address_1_city", "San Francisco");
213 $this->type("address_1_postal_code", "94117");
214 $this->select('address_1_country_id', 'UNITED STATES');
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
221 $this->waitForElementPresent("_qf_Location_upload-bottom");
222 $this->waitForTextPresent("'Event Location' information has been saved.");
223 }
224
225 /**
226 * @param $registerIntro
227 * @param bool $multipleRegistrations
228 */
229 public 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->click('intro_text-plain');
242 $this->fillRichTextField("intro_text", $registerIntro);
243
244 // enable confirmation email
245 $this->click('xpath=//fieldset[@id="mail"]/div/table/tbody/tr/td[2]/label[contains(text(), "Yes")]');
246 $this->type("confirm_from_name", "Jane Doe");
247 $this->type("confirm_from_email", "jane.doe@example.org");
248
249 $this->click("_qf_Registration_upload-bottom");
250 $this->waitForElementPresent("_qf_Registration_upload-bottom");
251 $this->waitForTextPresent("'Online Registration' information has been saved.");
252 }
253
254 /**
255 * @param $subject
256 * @param $thankYouMsg
257 * @param $eventTitle
258 */
259 public function _testAddTellAFriend($subject, $thankYouMsg, $eventTitle) {
260 // Go to Tell A Friend Tab
261 $this->click('link=Tell a Friend');
262 $this->waitForElementPresent('_qf_Event_cancel-bottom');
263
264 // Enable tell a friend feature
265 $this->check('tf_is_active');
266 $this->waitForElementPresent('tf_thankyou_text');
267
268 // Modify the messages
269 $this->type('intro', "This is $subject Test intro text");
270 $this->type('suggested_message', "$subject Test Message. This is amazing!");
271
272 $this->type('tf_thankyou_title', 'Test thank you title');
273 $this->type('tf_thankyou_text', $thankYouMsg);
274
275 $this->click('_qf_Event_upload_done-bottom');
276 $this->waitForElementPresent("xpath=//div[@id='event_status_id']//div[@id='option11_wrapper']/table/tbody//tr/td[1]/a[text()='$eventTitle']");
277 }
278
279 }