Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06a1bc01 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
6a488035 TO |
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 | ||
6a488035 | 27 | require_once 'CiviTest/CiviSeleniumTestCase.php'; |
e9479dcf EM |
28 | |
29 | /** | |
30 | * Class WebTest_Contact_CustomDataAddTest | |
31 | */ | |
6a488035 TO |
32 | class WebTest_Contact_CustomDataAddTest extends CiviSeleniumTestCase { |
33 | ||
34 | protected function setUp() { | |
35 | parent::setUp(); | |
36 | } | |
37 | ||
00be9182 | 38 | public function testCustomDataAdd() { |
6a488035 TO |
39 | $this->webtestLogin(); |
40 | ||
d8bd5fb9 | 41 | $this->openCiviPage('admin/custom/group', 'action=add&reset=1'); |
6a488035 TO |
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']"); | |
7df6dc24 | 52 | $this->clickLink("_qf_Group_next-bottom"); |
6a488035 TO |
53 | |
54 | //Is custom group created? | |
6c5f7368 | 55 | $this->waitForText('crm-notification-container', "Your custom field set '{$customGroupTitle}' has been added. You can add custom fields now."); |
60f44e0c | 56 | $this->waitForElementPresent("_qf_Field_cancel-bottom"); |
6a488035 TO |
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 | ||
6a488035 TO |
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 | |
60f44e0c | 89 | $this->click("_qf_Field_done"); |
6a488035 TO |
90 | |
91 | //Is custom field created? | |
e85b1a9c | 92 | $this->waitForText('crm-notification-container', "Custom field '$checkboxFieldLabel' has been saved."); |
60f44e0c | 93 | $this->waitForElementPresent('newCustomField'); |
6a488035 TO |
94 | |
95 | //create another custom field - Integer Radio | |
60f44e0c | 96 | $this->clickLink("newCustomField", '_qf_Field_cancel', FALSE); |
6a488035 TO |
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 | |
60f44e0c | 130 | $this->click("_qf_Field_done"); |
6a488035 TO |
131 | |
132 | //Is custom field created | |
e85b1a9c | 133 | $this->waitForText('crm-notification-container', "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 | ||
00be9182 | 158 | public 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']"); | |
7df6dc24 | 174 | $this->clickLink("_qf_Group_next-bottom"); |
6a488035 TO |
175 | |
176 | //Is custom group created? | |
6c5f7368 | 177 | $this->waitForText('crm-notification-container', "Your custom field set '{$customGroupTitle}' has been added. You can add custom fields now."); |
60f44e0c | 178 | $this->waitForElementPresent("_qf_Field_cancel-bottom"); |
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 | |
60f44e0c | 201 | $this->click("_qf_Field_done"); |
6a488035 TO |
202 | |
203 | //Is custom field created? | |
e85b1a9c | 204 | $this->waitForText('crm-notification-container', "Custom field '$moneyTextFieldLabel' has been saved."); |
6a488035 TO |
205 | |
206 | //Get the customFieldsetID | |
d8bd5fb9 | 207 | $this->openCiviPage('admin/custom/group', 'reset=1'); |
5c80555f | 208 | $customFieldsetId = explode('&gid=', $this->getAttribute("xpath=//div[@id='custom_group']/table/tbody//tr/td/div[text()='$customGroupTitle']/../../td[7]/span/a@href")); |
6c6e6187 | 209 | $customFieldsetId = $customFieldsetId[1]; |
6a488035 TO |
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 | ||
9b873358 | 238 | public function testCustomDataChangeLog() { |
6a488035 TO |
239 | $this->webtestLogin(); |
240 | ||
241 | //enable logging | |
d8bd5fb9 | 242 | $this->openCiviPage('admin/setting/misc', 'reset=1'); |
6a488035 | 243 | $this->click("CIVICRM_QFID_1_logging"); |
6a488035 | 244 | $this->click("_qf_Miscellaneous_next-top"); |
efb29358 CW |
245 | |
246 | // Increase timeout by quadruple since enabling logging takes a long time | |
247 | $this->waitForPageToLoad($this->getTimeoutMsec() * 4); | |
d8bd5fb9 | 248 | $this->waitForTextPresent("Changes Saved"); |
6a488035 TO |
249 | |
250 | // Create new Custom Field Set | |
d8bd5fb9 | 251 | $this->openCiviPage('admin/custom/group', 'reset=1'); |
6a488035 TO |
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"); | |
7df6dc24 | 258 | $this->clickLink("id=_qf_Group_next-bottom"); |
6c5f7368 | 259 | $this->waitForText('crm-notification-container', "Your custom field set '$customFieldSet' has been added."); |
60f44e0c | 260 | $this->waitForElementPresent('_qf_Field_done-bottom'); |
6a488035 TO |
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"); | |
60f44e0c | 266 | $this->click("id=_qf_Field_done-bottom"); |
e85b1a9c | 267 | $this->waitForText('crm-notification-container', "Custom field '$customField' has been saved."); |
6a488035 | 268 | |
d8bd5fb9 | 269 | $this->openCiviPage('contact/add', 'reset=1&ct=Individual'); |
6a488035 TO |
270 | |
271 | //contact details section | |
272 | //fill in first name | |
92fcb95f | 273 | $firstName = 'Jimmy' . substr(sha1(rand()), 0, 7); |
6a488035 TO |
274 | $this->type('first_name', $firstName); |
275 | ||
276 | //fill in last name | |
92fcb95f | 277 | $lastName = 'Page' . substr(sha1(rand()), 0, 7); |
6a488035 TO |
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\"]"); | |
92fcb95f | 287 | $value = "custom" . rand(); |
6c6e6187 | 288 | $this->type("xpath=//table//tr/td/label[text()=\"$customField\"]/../following-sibling::td/input", $value); |
6a488035 TO |
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 | ||
7df6dc24 | 305 | if ($this->assertElementContainsText("address_table_1", "Latitude")) { |
6a488035 TO |
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 | ||
6c5f7368 | 314 | $this->waitForText('crm-notification-container', "{$firstName} {$lastName} has been created."); |
6a488035 TO |
315 | |
316 | //Update the custom field | |
27c7ef42 RN |
317 | $this->waitForElementPresent("xpath=//ul[@id='actions']/li[2]/a/span"); |
318 | $this->clickLink("xpath=//ul[@id='actions']/li[2]/a/span"); | |
6a488035 | 319 | $this->click("xpath=//table//tr/td/label[text()=\"$customField\"]"); |
92fcb95f | 320 | $value1 = "custom_1" . rand(); |
6c6e6187 | 321 | $this->type("xpath=//table//tr/td/label[text()=\"$customField\"]/../following-sibling::td/input", $value1); |
6a488035 TO |
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 | |
1d4d99e9 | 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]"); | |
6a488035 TO |
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 | |
d8bd5fb9 | 335 | $this->openCiviPage('admin/setting/misc', 'reset=1'); |
6a488035 TO |
336 | $this->click("CIVICRM_QFID_0_logging"); |
337 | $this->click("_qf_Miscellaneous_next-top"); | |
efb29358 CW |
338 | |
339 | // Increase timeout by triple since disabling logging takes a long time | |
340 | $this->waitForPageToLoad($this->getTimeoutMsec() * 3); | |
6a488035 TO |
341 | $this->waitForTextPresent("Changes Saved"); |
342 | } | |
343 | ||
344 | } |