commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-old / civicrm / tests / phpunit / WebTest / Contact / CustomDataAddTest.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_Contact_CustomDataAddTest
31 */
32 class WebTest_Contact_CustomDataAddTest extends CiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
38 public function testCustomDataAdd() {
39 $this->webtestLogin();
40
41 $this->openCiviPage('admin/custom/group', 'action=add&reset=1');
42
43 //fill custom group title
44 $customGroupTitle = 'custom_' . substr(sha1(rand()), 0, 7);
45 $this->click("title");
46 $this->type("title", $customGroupTitle);
47
48 //custom group extends
49 $this->click("extends[0]");
50 $this->select("extends[0]", "value=Contact");
51 $this->click("//option[@value='Contact']");
52 $this->clickLink("_qf_Group_next-bottom");
53
54 //Is custom group created?
55 $this->waitForText('crm-notification-container', "Your custom field set '{$customGroupTitle}' has been added. You can add custom fields now.");
56 $this->waitForElementPresent("_qf_Field_cancel-bottom");
57
58 //add custom field - alphanumeric checkbox
59 $checkboxFieldLabel = 'custom_field' . substr(sha1(rand()), 0, 4);
60 $this->click("label");
61 $this->type("label", $checkboxFieldLabel);
62 $this->click("data_type[1]");
63 $this->select("data_type[1]", "value=CheckBox");
64 $this->click("//option[@value='CheckBox']");
65 $checkboxOptionLabel1 = 'optionLabel_' . substr(sha1(rand()), 0, 5);
66 $this->type("option_label_1", $checkboxOptionLabel1);
67 $this->type("option_value_1", "1");
68 $checkboxOptionLabel2 = 'optionLabel_' . substr(sha1(rand()), 0, 5);
69 $this->type("option_label_2", $checkboxOptionLabel2);
70 $this->type("option_value_2", "2");
71 $this->click("link=another choice");
72 $checkboxOptionLabel3 = 'optionLabel_' . substr(sha1(rand()), 0, 5);
73 $this->type("option_label_3", $checkboxOptionLabel3);
74 $this->type("option_value_3", "3");
75
76 //enter options per line
77 $this->type("options_per_line", "2");
78
79 //enter pre help message
80 $this->type("help_pre", "this is field pre help");
81
82 //enter post help message
83 $this->type("help_post", "this field post help");
84
85 //Is searchable?
86 $this->click("is_searchable");
87
88 //clicking save
89 $this->click("_qf_Field_done");
90
91 //Is custom field created?
92 $this->waitForText('crm-notification-container', "Custom field '$checkboxFieldLabel' has been saved.");
93 $this->waitForElementPresent('newCustomField');
94
95 //create another custom field - Integer Radio
96 $this->clickLink("newCustomField", '_qf_Field_cancel', FALSE);
97 $this->click("data_type[0]");
98 $this->select("data_type[0]", "value=1");
99 $this->click("//option[@value='1']");
100 $this->click("data_type[1]");
101 $this->select("data_type[1]", "value=Radio");
102 $this->click("//option[@value='Radio']");
103
104 $radioFieldLabel = 'custom_field' . substr(sha1(rand()), 0, 4);
105 $this->type("label", $radioFieldLabel);
106 $radioOptionLabel1 = 'optionLabel_' . substr(sha1(rand()), 0, 5);
107 $this->type("option_label_1", $radioOptionLabel1);
108 $this->type("option_value_1", "1");
109 $radioOptionLabel2 = 'optionLabel_' . substr(sha1(rand()), 0, 5);
110 $this->type("option_label_2", $radioOptionLabel2);
111 $this->type("option_value_2", "2");
112 $this->click("link=another choice");
113 $radioOptionLabel3 = 'optionLabel_' . substr(sha1(rand()), 0, 5);
114 $this->type("option_label_3", $radioOptionLabel3);
115 $this->type("option_value_3", "3");
116
117 //select options per line
118 $this->type("options_per_line", "3");
119
120 //enter pre help msg
121 $this->type("help_pre", "this is field pre help");
122
123 //enter post help msg
124 $this->type("help_post", "this is field post help");
125
126 //Is searchable?
127 $this->click("is_searchable");
128
129 //clicking save
130 $this->click("_qf_Field_done");
131
132 //Is custom field created
133 $this->waitForText('crm-notification-container', "Custom field '$radioFieldLabel' has been saved.");
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 public function testCustomDataMoneyAdd() {
159 $this->webtestLogin();
160 $this->waitForPageToLoad($this->getTimeoutMsec());
161
162 $this->openCiviPage('admin/custom/group', 'action=add&reset=1');
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->clickLink("_qf_Group_next-bottom");
175
176 //Is custom group created?
177 $this->waitForText('crm-notification-container', "Your custom field set '{$customGroupTitle}' has been added. You can add custom fields now.");
178 $this->waitForElementPresent("_qf_Field_cancel-bottom");
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_done");
202
203 //Is custom field created?
204 $this->waitForText('crm-notification-container', "Custom field '$moneyTextFieldLabel' has been saved.");
205
206 //Get the customFieldsetID
207 $this->openCiviPage('admin/custom/group', 'reset=1');
208 $customFieldsetId = explode('&gid=', $this->getAttribute("xpath=//div[@id='custom_group']/table/tbody//tr/td/div[text()='$customGroupTitle']/../../td[7]/span/a@href"));
209 $customFieldsetId = $customFieldsetId[1];
210
211 //create Individual contact
212 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
213
214 //expand all tabs
215 $this->click("expand");
216 $this->waitForElementPresent("address_1_street_address");
217
218 //fill first name, last name, email id
219 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
220 $lastName = 'An' . substr(sha1(rand()), 0, 7);
221 $emailId = substr(sha1(rand()), 0, 7) . '@web.com';
222 $this->click("first_name");
223 $this->type("first_name", $firstName);
224 $this->type("last_name", $lastName);
225 $this->type("email_1_email", $emailId);
226
227 //fill custom values for the contact
228 $this->click("xpath=//table//tr/td/label[text()=\"$moneyTextFieldLabel\"]");
229 $this->type("xpath=//table//tr/td/label[text()=\"$moneyTextFieldLabel\"]/../following-sibling::td/input", "12345678.98");
230 $this->click("_qf_Contact_upload_view");
231 $this->waitForPageToLoad($this->getTimeoutMsec());
232
233 //verify the money custom field value in the proper format
234 $this->assertTrue($this->isElementPresent("xpath=//div[@id='custom-set-content-{$customFieldsetId}']/div/div[2]/div[2]"));
235 $this->verifyText("xpath=//div[@id='custom-set-content-{$customFieldsetId}']/div/div[2]/div[2]", '12,345,678.98');
236 }
237
238 public function testCustomDataChangeLog() {
239 $this->webtestLogin();
240
241 //enable logging
242 $this->openCiviPage('admin/setting/misc', 'reset=1');
243 $this->click("CIVICRM_QFID_1_logging");
244 $this->click("_qf_Miscellaneous_next-top");
245
246 // Increase timeout by quadruple since enabling logging takes a long time
247 $this->waitForPageToLoad($this->getTimeoutMsec() * 4);
248 $this->waitForTextPresent("Changes Saved");
249
250 // Create new Custom Field Set
251 $this->openCiviPage('admin/custom/group', 'reset=1');
252 $this->click("css=#newCustomDataGroup > span");
253 $this->waitForElementPresent('_qf_Group_next-bottom');
254 $customFieldSet = 'Fieldset' . rand();
255 $this->type("id=title", $customFieldSet);
256 $this->select("id=extends_0", "label=Individual");
257 $this->click("id=collapse_display");
258 $this->clickLink("id=_qf_Group_next-bottom");
259 $this->waitForText('crm-notification-container', "Your custom field set '$customFieldSet' has been added.");
260 $this->waitForElementPresent('_qf_Field_done-bottom');
261
262 // Add field to fieldset
263 $customField = 'CustomField' . rand();
264 $this->type("id=label", $customField);
265 $this->select("id=data_type_0", "value=0");
266 $this->click("id=_qf_Field_done-bottom");
267 $this->waitForText('crm-notification-container', "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_table_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='changeLog']/div[2]/form/div[2]/table/tbody/tr[1]/td[4]/a[contains(text(), '$firstName $lastName')]");
328 $this->waitForElementPresent("xpath=//div[@id='changeLog']/div[2]/form/div[2]/table/tbody/tr[1]/td/a[2]");
329 $this->click("xpath=//div[@id='changeLog']/div[2]/form/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 }