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_InlineFieldsEditTest extends CiviSeleniumTestCase { | |
30 | ||
31 | protected function setUp() { | |
32 | parent::setUp(); | |
33 | } | |
34 | ||
35 | function testAddAndEditField() { | |
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 | // Add a contact | |
49 | $firstName = 'WebTest' . substr(sha1(rand()), 0, 7); | |
50 | $lastName = 'InlineFieldsEdit' . substr(sha1(rand()), 0, 7); | |
51 | $this->webtestAddContact($firstName, $lastName); | |
52 | $this->waitForElementPresent('css=.crm-inline-edit-container.crm-edit-ready'); | |
53 | ||
54 | // Set Communication Prefs | |
55 | $this->inlineEdit('crm-communication-pref-content', array( | |
56 | 'css=#email_greeting_display a' => TRUE, | |
57 | 'privacy_do_not_email' => 1, | |
58 | 'preferred_communication_method_1' => 1, | |
59 | 'preferred_communication_method_2' => 1, | |
60 | ), 'keep_open'); | |
61 | $this->waitForElementPresent('css=.icon.privacy-flag.do-not-email'); | |
62 | $this->inlineEdit('crm-communication-pref-content', array( | |
63 | 'privacy_do_not_phone' => 1, | |
64 | 'privacy_do_not_email' => 0, | |
65 | 'preferred_communication_method_1' => 0, | |
66 | 'preferred_communication_method_2' => 0, | |
67 | ), 'keep_open'); | |
68 | $this->waitForElementPresent('css=.icon.privacy-flag.do-not-phone'); | |
69 | $this->inlineEdit('crm-communication-pref-content', array( | |
70 | 'email_greeting_custom' => 'Hey You!', | |
71 | ), 'no_open'); | |
72 | $this->assertElementNotPresent('css=.icon.privacy-flag.do-not-email'); | |
73 | ||
74 | // Custom data | |
75 | $this->click('css=div.crm-custom-set-block-1 .collapsible-title'); | |
76 | sleep(1); | |
77 | $this->openInlineForm('custom-set-content-1'); | |
78 | $dateFieldId = $this->getAttribute("xpath=//div[@id='constituent_information']/table/tbody/tr[3]/td[@class='html-adjust']/input@id"); | |
79 | $this->inlineEdit('custom-set-content-1', array( | |
80 | 'CIVICRM_QFID_Edu_2' => 1, | |
81 | "//div[@id='constituent_information']/table/tbody/tr[2]/td[@class='html-adjust']/select" => array('Single'), | |
82 | $dateFieldId => 'date: now - 10 years', | |
83 | )); | |
84 | ||
85 | // Edit contact info | |
86 | $params = array( | |
87 | 'job_title' => 'jobtest123', | |
88 | 'nick_name' => 'nicktest123', | |
89 | 'contact_source' => 'sourcetest123', | |
90 | ); | |
91 | $this->inlineEdit('crm-contactinfo-content', $params, 'keep_open'); | |
92 | // Clear fields and verify they are deleted | |
93 | $this->inlineEdit('crm-contactinfo-content', array( | |
94 | 'job_title' => '', | |
95 | 'nick_name' => '', | |
96 | 'contact_source' => '', | |
97 | ), 'no_open'); | |
98 | foreach ($params as $str) { | |
99 | $this->assertElementNotContainsText('crm-contactinfo-content', $str); | |
100 | } | |
101 | ||
102 | // Add a phone | |
103 | $this->inlineEdit('crm-phone-content', array( | |
104 | 'phone_1_phone' => '123-456-7890', | |
105 | 'phone_1_phone_ext' => '101', | |
106 | 'phone_1_location_type_id' => array('Work'), | |
107 | 'phone_1_phone_type_id' => array('Mobile'), | |
108 | )); | |
109 | ||
110 | // Add im | |
111 | $this->inlineEdit('crm-im-content', array( | |
112 | 'im_1_name' => 'testmeout', | |
113 | 'im_1_location_type_id' => array('Work'), | |
114 | 'im_1_provider_id' => array('Jabber'), | |
115 | )); | |
116 | ||
117 | // Add an address - should default to home | |
118 | $this->inlineEdit('address-block-1', array( | |
119 | 'address_1_street_address' => '123 St', | |
120 | 'address_1_city' => 'San Somewhere', | |
121 | ), 'keep_open'); | |
122 | // Try to uncheck is_primary, we should get an error and it should stay checked | |
123 | $this->click('address[1][is_primary]'); | |
124 | $this->waitForElementPresent('css=#crm-notification-container .error.ui-notify-message'); | |
125 | $this->assertChecked('address[1][is_primary]'); | |
126 | // Try to open another form while this one is still open - nothing should happen | |
127 | $this->waitForElementPresent('address-block-2'); | |
128 | $this->openInlineForm('address-block-2', FALSE); | |
129 | $this->assertElementNotPresent('css#address-block-2.form'); | |
130 | // Update address | |
131 | $this->inlineEdit('address-block-1', array( | |
132 | 'address_1_street_address' => '321 Other St', | |
133 | 'address_1_city' => 'Sans Nowhere', | |
134 | 'address_1_postal_code' => '99999', | |
135 | 'address_1_postal_code_suffix' => '99', | |
136 | ), 'no_open'); | |
137 | // Another address with same location type as first - should give an error | |
138 | $this->inlineEdit('address-block-2', array( | |
139 | 'address_2_street_address' => '123 Foo', | |
140 | 'address_2_city' => 'San Anywhere', | |
141 | 'address_2_location_type_id' => array('Home'), | |
142 | ), 'error'); | |
143 | $this->waitForTextPresent('required'); | |
144 | // Share address with a new org | |
145 | $this->click('address[2][use_shared_address]'); | |
146 | $this->select('profiles_2', 'label=New Organization'); | |
147 | $orgName = 'Test Org Inline' . substr(sha1(rand()), 0, 7); | |
148 | $this->waitForElementPresent('css=#contact-dialog-2 form'); | |
149 | $this->type('organization_name', $orgName); | |
150 | $this->type('street_address-1', 'Test Org Street'); | |
151 | $this->type('city-1', 'Test Org City'); | |
152 | $this->click('_qf_Edit_next'); | |
153 | sleep(2); | |
154 | $this->waitForElementPresent('selected_shared_address-2'); | |
155 | $this->waitForTextPresent('Test Org Street'); | |
156 | $this->inlineEdit('address-block-2', array( | |
157 | 'address_2_location_type_id' => array('Work'), | |
158 | ), 'no_open'); | |
159 | $this->waitForElementPresent('css=.crm-content.crm-contact-current_employer'); | |
160 | $this->assertElementContainsText('crm-contactinfo-content', $orgName); | |
161 | $this->assertElementContainsText('address-block-2', $orgName); | |
162 | $this->assertElementContainsText('address-block-2', 'Work Address'); | |
163 | ||
164 | // Edit demographics | |
165 | $this->inlineEdit('crm-demographic-content', array( | |
166 | 'civicrm_gender_Female_1' => 1, | |
167 | 'is_deceased' => 1, | |
168 | 'birth_date' => 'date: Jan 1 1970', | |
169 | ), 'no_open'); | |
170 | $this->assertElementContainsText('crm-demographic-content', 'Female'); | |
171 | $this->assertElementContainsText('crm-demographic-content', 'Contact is Deceased'); | |
172 | $this->inlineEdit('crm-demographic-content', array( | |
173 | 'is_deceased' => 0, | |
174 | ), 'no_open'); | |
175 | $age = date('Y') - 1970; | |
176 | $this->assertElementContainsText('crm-demographic-content', "$age years"); | |
177 | ||
178 | // Add emails | |
179 | $this->inlineEdit('crm-email-content', array( | |
180 | 'css=#crm-email-content a.add-more-inline' => TRUE, | |
181 | 'email_1_email' => 'test1@monkey.com', | |
182 | 'email_2_email' => 'test2@monkey.com', | |
183 | ), 'keep_open'); | |
184 | ||
185 | // Try an invalid email | |
186 | $this->inlineEdit('crm-email-content', array( | |
187 | 'email_2_email' => 'invalid@monkey,com', | |
188 | ), 'error'); | |
189 | ||
190 | // Delete email | |
191 | $this->inlineEdit('crm-email-content', array( | |
192 | 'css=#Email_Block_2 a.crm-delete-inline' => TRUE, | |
193 | )); | |
194 | $this->assertElementNotContainsText('crm-email-content', 'test2@monkey.com'); | |
195 | ||
196 | // Add website with invalid url | |
197 | $this->inlineEdit('crm-website-content', array( | |
198 | 'css=#crm-website-content a.add-more-inline' => TRUE, | |
199 | 'website_1_url' => 'http://example.com', | |
200 | 'website_2_url' => 'something.wrong', | |
201 | ), 'error'); | |
202 | ||
203 | // Correct invalid url and add a third website | |
204 | $this->inlineEdit('crm-website-content', array( | |
205 | 'css=#crm-website-content a.add-more-inline' => TRUE, | |
206 | 'website_2_url' => 'http://example.net', | |
207 | 'website_2_website_type_id' => array('Work'), | |
208 | 'website_3_url' => 'http://example.biz', | |
209 | 'website_3_website_type_id' => array('Main'), | |
210 | ), 'keep_open'); | |
211 | ||
212 | // Delete website | |
213 | $this->inlineEdit('crm-website-content', array( | |
214 | 'css=#Website_Block_2 a.crm-delete-inline' => TRUE, | |
215 | )); | |
216 | $this->assertElementNotContainsText('crm-website-content', 'http://example.net'); | |
217 | ||
218 | // Change contact name | |
219 | $this->inlineEdit('crm-contactname-content', array( | |
220 | 'first_name' => 'NewName', | |
221 | 'prefix_id' => array('Mr.'), | |
222 | )); | |
223 | // Page title should be updated with new name | |
224 | $this->assertElementContainsText('css=title', "Mr. NewName $lastName"); | |
225 | } | |
226 | ||
227 | /** | |
228 | * Click on an inline-edit block and wait for it to open | |
229 | * | |
230 | * @param $block string selector | |
231 | */ | |
232 | private function openInlineForm($block, $wait = TRUE) { | |
233 | $this->mouseDown($block); | |
234 | $this->mouseUp($block); | |
235 | if ($wait) { | |
236 | $this->waitForElementPresent("css=#$block .crm-container-snippet form"); | |
237 | } | |
238 | } | |
239 | ||
240 | /** | |
241 | * Enter values in an inline edit block and save | |
242 | * | |
243 | * @param $block string selector | |
244 | * @param $params array | |
245 | * @param $valid str: submit behavior | |
246 | * 'error' if we are expecting a form validation error, | |
247 | * 're_open' (default) after saving, opens the form and validate inputs | |
248 | * 'keep_open' same as 're_open' but doesn't automatically cancel at the end | |
249 | * 'no_open' do not re-open to validate | |
250 | */ | |
251 | private function inlineEdit($block, $params, $valid = 're_open') { | |
252 | $this->openInlineForm($block); | |
253 | foreach ($params as $item => $val) { | |
254 | switch(gettype($val)) { | |
255 | case 'boolean': | |
256 | $this->click($item); | |
257 | break; | |
258 | case 'string': | |
259 | if (substr($val, 0, 5) == 'date:') { | |
260 | $this->webtestFillDate($item, trim(substr($val, 5))); | |
261 | } | |
262 | else { | |
263 | $this->type($item, $val); | |
264 | } | |
265 | break; | |
266 | case 'integer': | |
267 | $method = $val ? 'check' : 'uncheck'; | |
268 | $this->$method($item); | |
269 | break; | |
270 | case 'array': | |
271 | foreach ($val as $option) { | |
272 | $selector = is_int($option) ? 'value' : 'label'; | |
273 | $this->select($item, "$selector=$option"); | |
274 | } | |
275 | break; | |
276 | } | |
277 | } | |
278 | $this->click("css=#$block input.form-submit"); | |
279 | if ($valid !== 'error') { | |
280 | // Verify the form saved | |
281 | $this->waitForElementPresent("css=#$block > .crm-inline-block-content"); | |
282 | $validate = FALSE; | |
283 | foreach ($params as $val) { | |
284 | if (is_string($val) && $val && substr($val, 0, 5) != 'date:') { | |
285 | $this->assertElementContainsText($block, $val); | |
286 | $validate = TRUE; | |
287 | } | |
288 | elseif (!is_bool($val)) { | |
289 | $validate = TRUE; | |
290 | } | |
291 | if (is_array($val)) { | |
292 | foreach ($val as $option) { | |
293 | if (!is_int($option)) { | |
294 | $this->assertElementContainsText($block, $option); | |
295 | } | |
296 | } | |
297 | } | |
298 | } | |
299 | // Open the form back up and check everything | |
300 | if ($validate && $valid !== 'no_open') { | |
301 | $this->openInlineForm($block); | |
302 | foreach ($params as $item => $val) { | |
303 | switch(gettype($val)) { | |
304 | case 'string': | |
305 | if ($val && substr($val, 0, 5) == 'date:') { | |
306 | $val = date('m/d/Y', strtotime(trim(substr($val, 5)))); | |
307 | $item .= '_display'; | |
308 | } | |
309 | if ($val) { | |
310 | $this->assertElementValueEquals($item, $val); | |
311 | } | |
312 | break; | |
313 | case 'integer': | |
314 | $method = $val ? 'assertChecked' : 'assertNotChecked'; | |
315 | $this->$method($item); | |
316 | break; | |
317 | case 'array': | |
318 | foreach ($val as $option) { | |
319 | $method = is_int($option) ? 'assertIsSelected' : 'assertSelected'; | |
320 | $this->$method($item, $option); | |
321 | } | |
322 | break; | |
323 | } | |
324 | } | |
325 | if ($valid !== 'keep_open') { | |
326 | $this->click("css=#$block input.cancel"); | |
327 | } | |
328 | } | |
329 | } | |
330 | // Verify there was a form error | |
331 | else { | |
332 | $this->waitForElementPresent('css=#crm-notification-container .error.ui-notify-message'); | |
333 | $this->click('css=#crm-notification-container .error .ui-notify-cross'); | |
334 | } | |
335 | } | |
336 | } |