Fix some uses of sleep, comment the rest
[civicrm-core.git] / tests / phpunit / WebTest / Contact / CustomDataAddTest.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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
28require_once 'CiviTest/CiviSeleniumTestCase.php';
29class WebTest_Contact_CustomDataAddTest extends CiviSeleniumTestCase {
30
31 protected function setUp() {
32 parent::setUp();
33 }
34
35 function testCustomDataAdd() {
6a488035
TO
36 $this->webtestLogin();
37
d8bd5fb9 38 $this->openCiviPage('admin/custom/group', 'action=add&reset=1');
6a488035
TO
39
40 //fill custom group title
41 $customGroupTitle = 'custom_' . substr(sha1(rand()), 0, 7);
42 $this->click("title");
43 $this->type("title", $customGroupTitle);
44
45 //custom group extends
46 $this->click("extends[0]");
47 $this->select("extends[0]", "value=Contact");
48 $this->click("//option[@value='Contact']");
49 $this->click("_qf_Group_next-bottom");
50 $this->waitForElementPresent("_qf_Field_cancel-bottom");
51
52 //Is custom group created?
d8bd5fb9 53 $this->assertElementContainsText('crm-notification-container', "Your custom field set '{$customGroupTitle}' has been added. You can add custom fields now.");
6a488035
TO
54
55 //add custom field - alphanumeric checkbox
56 $checkboxFieldLabel = 'custom_field' . substr(sha1(rand()), 0, 4);
57 $this->click("label");
58 $this->type("label", $checkboxFieldLabel);
59 $this->click("data_type[1]");
60 $this->select("data_type[1]", "value=CheckBox");
61 $this->click("//option[@value='CheckBox']");
62 $checkboxOptionLabel1 = 'optionLabel_' . substr(sha1(rand()), 0, 5);
63 $this->type("option_label_1", $checkboxOptionLabel1);
64 $this->type("option_value_1", "1");
65 $checkboxOptionLabel2 = 'optionLabel_' . substr(sha1(rand()), 0, 5);
66 $this->type("option_label_2", $checkboxOptionLabel2);
67 $this->type("option_value_2", "2");
68 $this->click("link=another choice");
69 $checkboxOptionLabel3 = 'optionLabel_' . substr(sha1(rand()), 0, 5);
70 $this->type("option_label_3", $checkboxOptionLabel3);
71 $this->type("option_value_3", "3");
72
73
74 //enter options per line
75 $this->type("options_per_line", "2");
76
77 //enter pre help message
78 $this->type("help_pre", "this is field pre help");
79
80 //enter post help message
81 $this->type("help_post", "this field post help");
82
83 //Is searchable?
84 $this->click("is_searchable");
85
86 //clicking save
87 $this->click("_qf_Field_next");
88 $this->waitForPageToLoad($this->getTimeoutMsec());
89
90 //Is custom field created?
d8bd5fb9 91 $this->assertElementContainsText('crm-notification-container', "Your custom field '$checkboxFieldLabel' has been saved.");
6a488035
TO
92
93 //create another custom field - Integer Radio
94 $this->click("//a[@id='newCustomField']/span");
95 $this->waitForPageToLoad($this->getTimeoutMsec());
96 $this->click("data_type[0]");
97 $this->select("data_type[0]", "value=1");
98 $this->click("//option[@value='1']");
99 $this->click("data_type[1]");
100 $this->select("data_type[1]", "value=Radio");
101 $this->click("//option[@value='Radio']");
102
103 $radioFieldLabel = 'custom_field' . substr(sha1(rand()), 0, 4);
104 $this->type("label", $radioFieldLabel);
105 $radioOptionLabel1 = 'optionLabel_' . substr(sha1(rand()), 0, 5);
106 $this->type("option_label_1", $radioOptionLabel1);
107 $this->type("option_value_1", "1");
108 $radioOptionLabel2 = 'optionLabel_' . substr(sha1(rand()), 0, 5);
109 $this->type("option_label_2", $radioOptionLabel2);
110 $this->type("option_value_2", "2");
111 $this->click("link=another choice");
112 $radioOptionLabel3 = 'optionLabel_' . substr(sha1(rand()), 0, 5);
113 $this->type("option_label_3", $radioOptionLabel3);
114 $this->type("option_value_3", "3");
115
116 //select options per line
117 $this->type("options_per_line", "3");
118
119 //enter pre help msg
120 $this->type("help_pre", "this is field pre help");
121
122 //enter post help msg
123 $this->type("help_post", "this is field post help");
124
125 //Is searchable?
126 $this->click("is_searchable");
127
128 //clicking save
129 $this->click("_qf_Field_next");
130 $this->waitForPageToLoad($this->getTimeoutMsec());
131
132 //Is custom field created
d8bd5fb9 133 $this->assertElementContainsText('crm-notification-container', "Your custom field '$radioFieldLabel' has been saved.");
6a488035
TO
134
135 // Go to the URL to create an Individual contact.
136 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
137
138 //expand all tabs
139 $this->click("expand");
140 $this->waitForElementPresent("address_1_street_address");
141
142 //fill first name, last name, email id
143 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
144 $lastName = 'An' . substr(sha1(rand()), 0, 7);
145 $emailId = substr(sha1(rand()), 0, 7) . '@web.com';
146 $this->click("first_name");
147 $this->type("first_name", $firstName);
148 $this->type("last_name", $lastName);
149 $this->type("email_1_email", $emailId);
150
151 //fill custom values for the contact
152 $this->click("xpath=//table//tr/td/label[text()=\"$checkboxOptionLabel2\"]");
153 $this->click("xpath=//table//tr/td/label[text()=\"$radioOptionLabel3\"]");
154 $this->click("_qf_Contact_upload_view");
155 $this->waitForPageToLoad($this->getTimeoutMsec());
156 }
157
158 function testCustomDataMoneyAdd() {
6a488035
TO
159 $this->webtestLogin();
160 $this->waitForPageToLoad($this->getTimeoutMsec());
161
d8bd5fb9 162 $this->openCiviPage('admin/custom/group', 'action=add&reset=1');
6a488035
TO
163
164 //fill custom group title
165 $customGroupTitle = 'custom_' . substr(sha1(rand()), 0, 7);
166 $this->waitForElementPresent("title");
167 $this->click("title");
168 $this->type("title", $customGroupTitle);
169
170 //custom group extends
171 $this->click("extends[0]");
172 $this->select("extends[0]", "value=Contact");
173 $this->click("//option[@value='Contact']");
174 $this->click("_qf_Group_next-bottom");
175 $this->waitForElementPresent("_qf_Field_cancel-bottom");
176
177 //Is custom group created?
d8bd5fb9 178 $this->assertElementContainsText('crm-notification-container', "Your custom field set '{$customGroupTitle}' has been added. You can add custom fields now.");
6a488035
TO
179
180 //add custom field - money text
181 $moneyTextFieldLabel = 'money' . substr(sha1(rand()), 0, 4);
182 $this->click("label");
183 $this->type("label", $moneyTextFieldLabel);
184 $this->waitForElementPresent("data_type[0]");
185 $this->click("data_type[0]");
186 $this->select("data_type[0]", "label=Money");
187
188 $this->click("data_type[1]");
189 $this->select("data_type[1]", "value=Text");
190
191 //enter pre help message
192 $this->type("help_pre", "this is field pre help");
193
194 //enter post help message
195 $this->type("help_post", "this field post help");
196
197 //Is searchable?
198 $this->click("is_searchable");
199
200 //clicking save
201 $this->click("_qf_Field_next");
202 $this->waitForPageToLoad($this->getTimeoutMsec());
203
204 //Is custom field created?
d8bd5fb9 205 $this->assertElementContainsText('crm-notification-container', "Your custom field '$moneyTextFieldLabel' has been saved.");
6a488035
TO
206
207 //Get the customFieldsetID
d8bd5fb9 208 $this->openCiviPage('admin/custom/group', 'reset=1');
6a488035
TO
209 $customFieldsetId = explode('&gid=', $this->getAttribute("xpath=//div[@id='custom_group']//table/tbody//tr/td/span[text()='$customGroupTitle']/../../td[7]/span/a@href"));
210 $customFieldsetId = $customFieldsetId[1];
211
212 //create Individual contact
213 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
214
215 //expand all tabs
216 $this->click("expand");
217 $this->waitForElementPresent("address_1_street_address");
218
219 //fill first name, last name, email id
220 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
221 $lastName = 'An' . substr(sha1(rand()), 0, 7);
222 $emailId = substr(sha1(rand()), 0, 7) . '@web.com';
223 $this->click("first_name");
224 $this->type("first_name", $firstName);
225 $this->type("last_name", $lastName);
226 $this->type("email_1_email", $emailId);
227
228 //fill custom values for the contact
229 $this->click("xpath=//table//tr/td/label[text()=\"$moneyTextFieldLabel\"]");
230 $this->type("xpath=//table//tr/td/label[text()=\"$moneyTextFieldLabel\"]/../following-sibling::td/input", "12345678.98");
231 $this->click("_qf_Contact_upload_view");
232 $this->waitForPageToLoad($this->getTimeoutMsec());
233
234 //verify the money custom field value in the proper format
235 $this->assertTrue($this->isElementPresent("xpath=//div[@id='custom-set-content-{$customFieldsetId}']/div/div[2]/div[2]"));
236 $this->verifyText("xpath=//div[@id='custom-set-content-{$customFieldsetId}']/div/div[2]/div[2]", '12,345,678.98');
237 }
238
239 function testCustomDataChangeLog(){
6a488035
TO
240 $this->webtestLogin();
241
242 //enable logging
d8bd5fb9 243 $this->openCiviPage('admin/setting/misc', 'reset=1');
6a488035 244 $this->click("CIVICRM_QFID_1_logging");
6a488035 245 $this->click("_qf_Miscellaneous_next-top");
efb29358
CW
246
247 // Increase timeout by quadruple since enabling logging takes a long time
248 $this->waitForPageToLoad($this->getTimeoutMsec() * 4);
d8bd5fb9 249 $this->waitForTextPresent("Changes Saved");
6a488035
TO
250
251 // Create new Custom Field Set
d8bd5fb9 252 $this->openCiviPage('admin/custom/group', 'reset=1');
6a488035
TO
253 $this->click("css=#newCustomDataGroup > span");
254 $this->waitForElementPresent('_qf_Group_next-bottom');
255 $customFieldSet = 'Fieldset' . rand();
256 $this->type("id=title", $customFieldSet);
257 $this->select("id=extends_0", "label=Individual");
258 $this->click("id=collapse_display");
259 $this->click("id=_qf_Group_next-bottom");
260 $this->waitForElementPresent('_qf_Field_next-bottom');
d8bd5fb9 261 $this->assertElementContainsText('crm-notification-container', "Your custom field set '$customFieldSet' has been added.");
6a488035
TO
262
263 // Add field to fieldset
264 $customField = 'CustomField' . rand();
265 $this->type("id=label", $customField);
266 $this->select("id=data_type_0", "value=0");
267 $this->click("id=_qf_Field_next-bottom");
268 $this->waitForPageToLoad($this->getTimeoutMsec());
d8bd5fb9 269 $this->assertElementContainsText('crm-notification-container', "Your custom field '$customField' has been saved.");
6a488035 270
d8bd5fb9 271 $this->openCiviPage('contact/add', 'reset=1&ct=Individual');
6a488035
TO
272
273 //contact details section
274 //fill in first name
275 $firstName = 'Jimmy'.substr(sha1(rand()), 0, 7);
276 $this->type('first_name', $firstName);
277
278 //fill in last name
279 $lastName = 'Page'.substr(sha1(rand()), 0, 7);
280 $this->type('last_name', $lastName);
281
282 //fill in email id
283 $this->type('email_1_email', "{$firstName}.{$lastName}@example.com");
284
285 //fill in phone
286 $this->type("phone_1_phone", "2222-4444");
287
288 $this->click("xpath=//table//tr/td/label[text()=\"$customField\"]");
289 $value = "custom".rand();
290 $this->type("xpath=//table//tr/td/label[text()=\"$customField\"]/../following-sibling::td/input",$value);
291
292 //check for matching contact
293 $this->click("_qf_Contact_refresh_dedupe");
294 $this->waitForPageToLoad($this->getTimeoutMsec());
295
296 //address section
297 $this->click("addressBlock");
298 $this->waitForElementPresent("address_1_street_address");
299 //fill in address 1
300 $this->type("address_1_street_address", "902C El Camino Way SW");
301 $this->type("address_1_city", "Dumfries");
302 $this->type("address_1_postal_code", "1234");
303
304 $this->click("address_1_country_id");
305 $this->select("address_1_country_id", "value=1228");
306
d8bd5fb9 307 if ($this->assertElementContainsText("address_1", "Latitude")) {
6a488035
TO
308 $this->type("address_1_geo_code_1", "1234");
309 $this->type("address_1_geo_code_2", "5678");
310 }
311
312 // Clicking save.
313 $this->click("_qf_Contact_upload_view");
314 $this->waitForPageToLoad($this->getTimeoutMsec());
315
d8bd5fb9 316 $this->assertElementContainsText('crm-notification-container', "{$firstName} {$lastName} has been created.");
6a488035
TO
317
318 //Update the custom field
319 $this->click("css=a.edit.button");
320 $this->waitForPageToLoad($this->getTimeoutMsec());
321 $this->click("xpath=//table//tr/td/label[text()=\"$customField\"]");
322 $value1 = "custom_1".rand();
323 $this->type("xpath=//table//tr/td/label[text()=\"$customField\"]/../following-sibling::td/input",$value1);
324 $this->click("_qf_Contact_upload_view-bottom");
325 $this->waitForPageToLoad($this->getTimeoutMsec());
326 $this->click("css=#tab_log a");
327
328 //check the changed log
329 $this->waitForElementPresent("xpath=//div[@id='instance_data']/div[2]/table/tbody/tr[1]/td[4]/a[contains(text(), '$firstName $lastName')]");
330 $this->waitForElementPresent("xpath=//div[@id='instance_data']/div[2]/table/tbody/tr[1]/td/a[2]");
331 $this->click("xpath=//div[@id='instance_data']/div[2]/table/tbody/tr[1]/td/a[2]");
332 $this->waitForPageToLoad($this->getTimeoutMsec());
333 $this->assertTrue($this->isElementPresent("xpath=//form[@id='LoggingDetail']/div[2]/table/tbody/tr/td[2][contains(text(), '$value')]"));
334 $this->assertTrue($this->isElementPresent("xpath=//form[@id='LoggingDetail']/div[2]/table/tbody/tr/td[3][contains(text(), '$value1')]"));
335
336 //disable logging
d8bd5fb9 337 $this->openCiviPage('admin/setting/misc', 'reset=1');
6a488035
TO
338 $this->click("CIVICRM_QFID_0_logging");
339 $this->click("_qf_Miscellaneous_next-top");
efb29358
CW
340
341 // Increase timeout by triple since disabling logging takes a long time
342 $this->waitForPageToLoad($this->getTimeoutMsec() * 3);
6a488035
TO
343 $this->waitForTextPresent("Changes Saved");
344 }
345
346}
347
348