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