3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
27 require_once 'CiviTest/CiviSeleniumTestCase.php';
28 class WebTest_Contact_CustomDataAddTest
extends CiviSeleniumTestCase
{
30 protected function setUp() {
34 function testCustomDataAdd() {
35 $this->webtestLogin();
37 $this->openCiviPage('admin/custom/group', 'action=add&reset=1');
39 //fill custom group title
40 $customGroupTitle = 'custom_' . substr(sha1(rand()), 0, 7);
41 $this->click("title");
42 $this->type("title", $customGroupTitle);
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");
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.");
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");
72 //enter options per line
73 $this->type("options_per_line", "2");
75 //enter pre help message
76 $this->type("help_pre", "this is field pre help");
78 //enter post help message
79 $this->type("help_post", "this field post help");
82 $this->click("is_searchable");
85 $this->click("_qf_Field_next");
86 $this->waitForPageToLoad($this->getTimeoutMsec());
88 //Is custom field created?
89 $this->waitForText('crm-notification-container', "Custom field '$checkboxFieldLabel' has been saved.");
91 //create another custom field - Integer Radio
92 $this->clickLink("//a[@id='newCustomField']/span", '_qf_Field_cancel', FALSE);
93 $this->click("data_type[0]");
94 $this->select("data_type[0]", "value=1");
95 $this->click("//option[@value='1']");
96 $this->click("data_type[1]");
97 $this->select("data_type[1]", "value=Radio");
98 $this->click("//option[@value='Radio']");
100 $radioFieldLabel = 'custom_field' . substr(sha1(rand()), 0, 4);
101 $this->type("label", $radioFieldLabel);
102 $radioOptionLabel1 = 'optionLabel_' . substr(sha1(rand()), 0, 5);
103 $this->type("option_label_1", $radioOptionLabel1);
104 $this->type("option_value_1", "1");
105 $radioOptionLabel2 = 'optionLabel_' . substr(sha1(rand()), 0, 5);
106 $this->type("option_label_2", $radioOptionLabel2);
107 $this->type("option_value_2", "2");
108 $this->click("link=another choice");
109 $radioOptionLabel3 = 'optionLabel_' . substr(sha1(rand()), 0, 5);
110 $this->type("option_label_3", $radioOptionLabel3);
111 $this->type("option_value_3", "3");
113 //select options per line
114 $this->type("options_per_line", "3");
117 $this->type("help_pre", "this is field pre help");
119 //enter post help msg
120 $this->type("help_post", "this is field post help");
123 $this->click("is_searchable");
126 $this->click("_qf_Field_next");
128 //Is custom field created
129 $this->waitForText('crm-notification-container', "Custom field '$radioFieldLabel' has been saved.");
131 // Go to the URL to create an Individual contact.
132 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
135 $this->click("expand");
136 $this->waitForElementPresent("address_1_street_address");
138 //fill first name, last name, email id
139 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
140 $lastName = 'An' . substr(sha1(rand()), 0, 7);
141 $emailId = substr(sha1(rand()), 0, 7) . '@web.com';
142 $this->click("first_name");
143 $this->type("first_name", $firstName);
144 $this->type("last_name", $lastName);
145 $this->type("email_1_email", $emailId);
147 //fill custom values for the contact
148 $this->click("xpath=//table//tr/td/label[text()=\"$checkboxOptionLabel2\"]");
149 $this->click("xpath=//table//tr/td/label[text()=\"$radioOptionLabel3\"]");
150 $this->click("_qf_Contact_upload_view");
151 $this->waitForPageToLoad($this->getTimeoutMsec());
154 function testCustomDataMoneyAdd() {
155 $this->webtestLogin();
156 $this->waitForPageToLoad($this->getTimeoutMsec());
158 $this->openCiviPage('admin/custom/group', 'action=add&reset=1');
160 //fill custom group title
161 $customGroupTitle = 'custom_' . substr(sha1(rand()), 0, 7);
162 $this->waitForElementPresent("title");
163 $this->click("title");
164 $this->type("title", $customGroupTitle);
166 //custom group extends
167 $this->click("extends[0]");
168 $this->select("extends[0]", "value=Contact");
169 $this->click("//option[@value='Contact']");
170 $this->click("_qf_Group_next-bottom");
171 $this->waitForElementPresent("_qf_Field_cancel-bottom");
173 //Is custom group created?
174 $this->waitForText('crm-notification-container', "Your custom field set '{$customGroupTitle}' has been added. You can add custom fields now.");
176 //add custom field - money text
177 $moneyTextFieldLabel = 'money' . substr(sha1(rand()), 0, 4);
178 $this->click("label");
179 $this->type("label", $moneyTextFieldLabel);
180 $this->waitForElementPresent("data_type[0]");
181 $this->click("data_type[0]");
182 $this->select("data_type[0]", "label=Money");
184 $this->click("data_type[1]");
185 $this->select("data_type[1]", "value=Text");
187 //enter pre help message
188 $this->type("help_pre", "this is field pre help");
190 //enter post help message
191 $this->type("help_post", "this field post help");
194 $this->click("is_searchable");
197 $this->click("_qf_Field_next");
198 $this->waitForPageToLoad($this->getTimeoutMsec());
200 //Is custom field created?
201 $this->waitForText('crm-notification-container', "Custom field '$moneyTextFieldLabel' has been saved.");
203 //Get the customFieldsetID
204 $this->openCiviPage('admin/custom/group', 'reset=1');
205 $customFieldsetId = explode('&gid=', $this->getAttribute("xpath=//div[@id='custom_group']//table/tbody//tr/td/span[text()='$customGroupTitle']/../../td[7]/span/a@href"));
206 $customFieldsetId = $customFieldsetId[1];
208 //create Individual contact
209 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
212 $this->click("expand");
213 $this->waitForElementPresent("address_1_street_address");
215 //fill first name, last name, email id
216 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
217 $lastName = 'An' . substr(sha1(rand()), 0, 7);
218 $emailId = substr(sha1(rand()), 0, 7) . '@web.com';
219 $this->click("first_name");
220 $this->type("first_name", $firstName);
221 $this->type("last_name", $lastName);
222 $this->type("email_1_email", $emailId);
224 //fill custom values for the contact
225 $this->click("xpath=//table//tr/td/label[text()=\"$moneyTextFieldLabel\"]");
226 $this->type("xpath=//table//tr/td/label[text()=\"$moneyTextFieldLabel\"]/../following-sibling::td/input", "12345678.98");
227 $this->click("_qf_Contact_upload_view");
228 $this->waitForPageToLoad($this->getTimeoutMsec());
230 //verify the money custom field value in the proper format
231 $this->assertTrue($this->isElementPresent("xpath=//div[@id='custom-set-content-{$customFieldsetId}']/div/div[2]/div[2]"));
232 $this->verifyText("xpath=//div[@id='custom-set-content-{$customFieldsetId}']/div/div[2]/div[2]", '12,345,678.98');
235 function testCustomDataChangeLog(){
236 $this->webtestLogin();
239 $this->openCiviPage('admin/setting/misc', 'reset=1');
240 $this->click("CIVICRM_QFID_1_logging");
241 $this->click("_qf_Miscellaneous_next-top");
243 // Increase timeout by quadruple since enabling logging takes a long time
244 $this->waitForPageToLoad($this->getTimeoutMsec() * 4);
245 $this->waitForTextPresent("Changes Saved");
247 // Create new Custom Field Set
248 $this->openCiviPage('admin/custom/group', 'reset=1');
249 $this->click("css=#newCustomDataGroup > span");
250 $this->waitForElementPresent('_qf_Group_next-bottom');
251 $customFieldSet = 'Fieldset' . rand();
252 $this->type("id=title", $customFieldSet);
253 $this->select("id=extends_0", "label=Individual");
254 $this->click("id=collapse_display");
255 $this->click("id=_qf_Group_next-bottom");
256 $this->waitForElementPresent('_qf_Field_next-bottom');
257 $this->waitForText('crm-notification-container', "Your custom field set '$customFieldSet' has been added.");
259 // Add field to fieldset
260 $customField = 'CustomField' . rand();
261 $this->type("id=label", $customField);
262 $this->select("id=data_type_0", "value=0");
263 $this->click("id=_qf_Field_next-bottom");
264 $this->waitForPageToLoad($this->getTimeoutMsec());
265 $this->waitForText('crm-notification-container', "Custom field '$customField' has been saved.");
267 $this->openCiviPage('contact/add', 'reset=1&ct=Individual');
269 //contact details section
271 $firstName = 'Jimmy'.substr(sha1(rand()), 0, 7);
272 $this->type('first_name', $firstName);
275 $lastName = 'Page'.substr(sha1(rand()), 0, 7);
276 $this->type('last_name', $lastName);
279 $this->type('email_1_email', "{$firstName}.{$lastName}@example.com");
282 $this->type("phone_1_phone", "2222-4444");
284 $this->click("xpath=//table//tr/td/label[text()=\"$customField\"]");
285 $value = "custom".rand();
286 $this->type("xpath=//table//tr/td/label[text()=\"$customField\"]/../following-sibling::td/input",$value);
288 //check for matching contact
289 $this->click("_qf_Contact_refresh_dedupe");
290 $this->waitForPageToLoad($this->getTimeoutMsec());
293 $this->click("addressBlock");
294 $this->waitForElementPresent("address_1_street_address");
296 $this->type("address_1_street_address", "902C El Camino Way SW");
297 $this->type("address_1_city", "Dumfries");
298 $this->type("address_1_postal_code", "1234");
300 $this->click("address_1_country_id");
301 $this->select("address_1_country_id", "value=1228");
303 if ($this->assertElementContainsText("address_1", "Latitude")) {
304 $this->type("address_1_geo_code_1", "1234");
305 $this->type("address_1_geo_code_2", "5678");
309 $this->click("_qf_Contact_upload_view");
310 $this->waitForPageToLoad($this->getTimeoutMsec());
312 $this->waitForText('crm-notification-container', "{$firstName} {$lastName} has been created.");
314 //Update the custom field
315 $this->waitForElementPresent("xpath=//ul[@id='actions']/li[2]/a/span");
316 $this->clickLink("xpath=//ul[@id='actions']/li[2]/a/span");
317 $this->click("xpath=//table//tr/td/label[text()=\"$customField\"]");
318 $value1 = "custom_1".rand();
319 $this->type("xpath=//table//tr/td/label[text()=\"$customField\"]/../following-sibling::td/input",$value1);
320 $this->click("_qf_Contact_upload_view-bottom");
321 $this->waitForPageToLoad($this->getTimeoutMsec());
322 $this->click("css=#tab_log a");
324 //check the changed log
325 $this->waitForElementPresent("xpath=//div[@id='changeLog']/div[2]/form/div[2]/table/tbody/tr[1]/td[4]/a[contains(text(), '$firstName $lastName')]");
326 $this->waitForElementPresent("xpath=//div[@id='changeLog']/div[2]/form/div[2]/table/tbody/tr[1]/td/a[2]");
327 $this->click("xpath=//div[@id='changeLog']/div[2]/form/div[2]/table/tbody/tr[1]/td/a[2]");
328 $this->waitForPageToLoad($this->getTimeoutMsec());
329 $this->assertTrue($this->isElementPresent("xpath=//form[@id='LoggingDetail']/div[2]/table/tbody/tr/td[2][contains(text(), '$value')]"));
330 $this->assertTrue($this->isElementPresent("xpath=//form[@id='LoggingDetail']/div[2]/table/tbody/tr/td[3][contains(text(), '$value1')]"));
333 $this->openCiviPage('admin/setting/misc', 'reset=1');
334 $this->click("CIVICRM_QFID_0_logging");
335 $this->click("_qf_Miscellaneous_next-top");
337 // Increase timeout by triple since disabling logging takes a long time
338 $this->waitForPageToLoad($this->getTimeoutMsec() * 3);
339 $this->waitForTextPresent("Changes Saved");