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