3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
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';
30 * Class WebTest_Contact_InlineFieldsEditTest
32 class WebTest_Contact_InlineFieldsEditTest
extends CiviSeleniumTestCase
{
34 protected function setUp() {
38 public function testAddAndEditField() {
39 $this->webtestLogin();
42 $firstName = 'WebTest' . substr(sha1(rand()), 0, 7);
43 $lastName = 'InlineFieldsEdit' . substr(sha1(rand()), 0, 7);
44 $this->webtestAddContact($firstName, $lastName);
45 $contactId = $this->urlArg('cid');
46 $this->waitForElementPresent('css=.crm-inline-edit-container.crm-edit-ready');
48 // Set Communication Prefs
49 $this->inlineEdit('crm-communication-pref-content', array(
50 'css=#email_greeting_display a' => TRUE,
51 'privacy_do_not_email' => 1,
52 'preferred_communication_method_1' => 1,
53 'preferred_communication_method_2' => 1,
55 $this->waitForElementPresent('css=.icon.privacy-flag.do-not-email');
56 $this->inlineEdit('crm-communication-pref-content', array(
57 'privacy_do_not_phone' => 1,
58 'privacy_do_not_email' => 0,
59 'preferred_communication_method_1' => 0,
60 'preferred_communication_method_2' => 0,
62 $this->waitForElementPresent('css=.icon.privacy-flag.do-not-phone');
63 $this->inlineEdit('crm-communication-pref-content', array(
64 'email_greeting_custom' => 'Hey You!',
66 $this->assertElementNotPresent('css=.icon.privacy-flag.do-not-email');
69 $this->click('css=div.crm-custom-set-block-1 .collapsible-title');
70 // Because it tends to cause problems, all uses of sleep() must be justified in comments
71 // NOTE: Sleep should never be used for wait for anything to load from the server
72 // Justification for this instance: opening an accordion is predictable
74 $this->openInlineForm('custom-set-content-1');
75 $dateFieldId = $this->getAttribute("xpath=//div[@class='crm-accordion-body']/table/tbody/tr[3]/td[@class='html-adjust']/input@id");
76 $this->inlineEdit('custom-set-content-1', array(
77 'CIVICRM_QFID_Edu_2' => 1,
78 "//div[@class='crm-accordion-body']/table/tbody/tr[2]/td[@class='html-adjust']/select" => array('Single'),
79 $dateFieldId => 'date: now - 10 years',
84 'job_title' => 'jobtest123',
85 'nick_name' => 'nicktest123',
86 'contact_source' => 'sourcetest123',
88 $this->inlineEdit('crm-contactinfo-content', $params, 'keep_open');
89 // Clear fields and verify they are deleted
90 $this->inlineEdit('crm-contactinfo-content', array(
93 'contact_source' => '',
95 foreach ($params as $str) {
96 $this->assertElementNotContainsText('crm-contactinfo-content', $str);
100 $this->inlineEdit('crm-phone-content', array(
101 'phone_1_phone' => '123-456-7890',
102 'phone_1_phone_ext' => '101',
103 'phone_1_location_type_id' => array('Work'),
104 'phone_1_phone_type_id' => array('Mobile'),
108 $this->inlineEdit('crm-im-content', array(
109 'im_1_name' => 'testmeout',
110 'im_1_location_type_id' => array('Work'),
111 'im_1_provider_id' => array('Jabber'),
114 // Add an address - should default to home
115 $this->inlineEdit('address-block-1', array(
116 'address_1_street_address' => '123 St',
117 'address_1_city' => 'San Somewhere',
119 // Try to uncheck is_primary, we should get an error and it should stay checked
120 $this->click('address[1][is_primary]');
121 $this->waitForElementPresent('css=#crm-notification-container .error.ui-notify-message');
122 $this->assertChecked('address[1][is_primary]');
123 // Try to open another form while this one is still open - nothing should happen
124 $this->waitForElementPresent('address-block-2');
125 $this->openInlineForm('address-block-2', FALSE);
126 $this->assertElementNotPresent('css#address-block-2.form');
128 $this->inlineEdit('address-block-1', array(
129 'address_1_street_address' => '321 Other St',
130 'address_1_city' => 'Sans Nowhere',
131 'address_1_postal_code' => '99999',
132 'address_1_postal_code_suffix' => '99',
134 // Another address with same location type as first - should give an error
135 $this->inlineEdit('address-block-2', array(
136 'address_2_street_address' => '123 Foo',
137 'address_2_city' => 'San Anywhere',
138 'address_2_location_type_id' => array('Home'),
140 $this->waitForTextPresent('required');
141 // Share address with a new org
142 $this->click('address[2][use_shared_address]');
143 $orgName = 'Test Org Inline' . substr(sha1(rand()), 0, 7);
145 // create new organization with dialog
146 $this->clickAt("xpath=//div[@id='s2id_address_2_master_contact_id']/a");
147 $this->click("xpath=//li[@class='select2-no-results']//a[contains(text(),' New Organization')]");
148 $this->waitForElementPresent("css=div#crm-profile-block");
149 $this->waitForElementPresent("_qf_Edit_next");
151 $this->type('organization_name', $orgName);
152 $this->type('street_address-1', 'Test Org Street');
153 $this->type('city-1', 'Test Org City');
154 $this->clickLink('_qf_Edit_next', 'selected_shared_address-2', FALSE);
155 $this->waitForTextPresent('Test Org Street');
156 $this->inlineEdit('address-block-2', array(
157 'address_2_location_type_id' => array('Work'),
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');
165 $this->inlineEdit('crm-demographic-content', array(
166 'civicrm_gender_Female_1' => 1,
168 'birth_date' => 'date: Jan 1 1970',
170 $this->assertElementContainsText('crm-demographic-content', 'Female');
171 $this->assertElementContainsText('crm-demographic-content', 'Contact is Deceased');
172 $this->inlineEdit('crm-demographic-content', array(
175 $age = date('Y') - 1970;
176 $this->assertElementContainsText('crm-demographic-content', "$age years");
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',
185 // Try an invalid email
186 $this->inlineEdit('crm-email-content', array(
187 'email_2_email' => 'invalid@monkey,com',
191 $this->inlineEdit('crm-email-content', array(
192 'css=#Email_Block_2 a.crm-delete-inline' => TRUE,
194 $this->assertElementNotContainsText('crm-email-content', 'test2@monkey.com');
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',
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'),
213 $this->inlineEdit('crm-website-content', array(
214 'css=#Website_Block_2 a.crm-delete-inline' => TRUE,
216 $this->assertElementNotContainsText('crm-website-content', 'http://example.net');
218 // Change contact name
219 $this->inlineEdit('crm-contactname-content', array(
220 'first_name' => 'NewName',
221 'prefix_id' => array('Mr.'),
223 $this->assertElementContainsText('css=div.crm-summary-display_name', "Mr. NewName $lastName");
224 // Page title should be updated with new name on reload
225 $this->openCiviPage('contact/view', "reset=1&cid=$contactId", "crm-record-log");
226 $this->assertElementContainsText('css=title', "Mr. NewName $lastName");
230 * Click on an inline-edit block and wait for it to open
236 private function openInlineForm($block, $wait = TRUE) {
237 $this->mouseDown($block);
238 $this->mouseUp($block);
240 $this->waitForElementPresent("css=#$block .crm-container-snippet form");
245 * Enter values in an inline edit block and save
251 * @param \str|string $valid str: submit behavior
252 * 'error' if we are expecting a form validation error,
253 * 're_open' (default) after saving, opens the form and validate inputs
254 * 'keep_open' same as 're_open' but doesn't automatically cancel at the end
255 * 'no_open' do not re-open to validate
257 private function inlineEdit($block, $params, $valid = 're_open') {
258 $this->openInlineForm($block);
259 foreach ($params as $item => $val) {
260 switch(gettype($val)) {
265 if (substr($val, 0, 5) == 'date:') {
266 $this->webtestFillDate($item, trim(substr($val, 5)));
269 $this->type($item, $val);
273 $method = $val ?
'check' : 'uncheck';
274 $this->$method($item);
277 foreach ($val as $option) {
278 $selector = is_int($option) ?
'value' : 'label';
279 $this->select($item, "$selector=$option");
284 $this->click("css=#$block input.crm-form-submit");
285 if ($valid !== 'error' && $valid !='errorJs') {
286 // Verify the form saved
287 $this->waitForElementPresent("css=#$block > .crm-inline-block-content");
289 foreach ($params as $val) {
290 if (is_string($val) && $val && substr($val, 0, 5) != 'date:') {
291 $this->assertElementContainsText($block, $val);
294 elseif (!is_bool($val)) {
297 if (is_array($val)) {
298 foreach ($val as $option) {
299 if (!is_int($option)) {
300 $this->assertElementContainsText($block, $option);
305 // Open the form back up and check everything
306 if ($validate && $valid !== 'no_open') {
307 $this->openInlineForm($block);
308 foreach ($params as $item => $val) {
309 switch(gettype($val)) {
311 if ($val && substr($val, 0, 5) == 'date:') {
312 $val = date('m/d/Y', strtotime(trim(substr($val, 5))));
316 $this->assertElementValueEquals($item, $val);
320 $method = $val ?
'assertChecked' : 'assertNotChecked';
321 $this->$method($item);
324 foreach ($val as $option) {
325 $method = is_int($option) ?
'assertIsSelected' : 'assertSelected';
326 $this->$method($item, $option);
331 if ($valid !== 'keep_open') {
332 $this->click("css=#$block input.cancel");
336 // Verify there was a form error
340 $this->waitForElementPresent('css=label.error');
343 $this->waitForElementPresent('css=#crm-notification-container .error.ui-notify-message');
344 $this->click('css=#crm-notification-container .error .ui-notify-cross');