3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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 +--------------------------------------------------------------------+
28 require_once 'CiviTest/CiviSeleniumTestCase.php';
29 class WebTest_Contact_InlineFieldsEditTest
extends CiviSeleniumTestCase
{
31 protected function setUp() {
35 function testAddAndEditField() {
36 $this->webtestLogin();
39 $firstName = 'WebTest' . substr(sha1(rand()), 0, 7);
40 $lastName = 'InlineFieldsEdit' . substr(sha1(rand()), 0, 7);
41 $this->webtestAddContact($firstName, $lastName);
42 $this->waitForElementPresent('css=.crm-inline-edit-container.crm-edit-ready');
44 // Set Communication Prefs
45 $this->inlineEdit('crm-communication-pref-content', array(
46 'css=#email_greeting_display a' => TRUE,
47 'privacy_do_not_email' => 1,
48 'preferred_communication_method_1' => 1,
49 'preferred_communication_method_2' => 1,
51 $this->waitForElementPresent('css=.icon.privacy-flag.do-not-email');
52 $this->inlineEdit('crm-communication-pref-content', array(
53 'privacy_do_not_phone' => 1,
54 'privacy_do_not_email' => 0,
55 'preferred_communication_method_1' => 0,
56 'preferred_communication_method_2' => 0,
58 $this->waitForElementPresent('css=.icon.privacy-flag.do-not-phone');
59 $this->inlineEdit('crm-communication-pref-content', array(
60 'email_greeting_custom' => 'Hey You!',
62 $this->assertElementNotPresent('css=.icon.privacy-flag.do-not-email');
65 $this->click('css=div.crm-custom-set-block-1 .collapsible-title');
66 // Because it tends to cause problems, all uses of sleep() must be justified in comments
67 // NOTE: Sleep should never be used for wait for anything to load from the server
68 // Justification for this instance: opening an accordion is predictable
70 $this->openInlineForm('custom-set-content-1');
71 $dateFieldId = $this->getAttribute("xpath=//div[@id='constituent_information']/table/tbody/tr[3]/td[@class='html-adjust']/input@id");
72 $this->inlineEdit('custom-set-content-1', array(
73 'CIVICRM_QFID_Edu_2' => 1,
74 "//div[@id='constituent_information']/table/tbody/tr[2]/td[@class='html-adjust']/select" => array('Single'),
75 $dateFieldId => 'date: now - 10 years',
80 'job_title' => 'jobtest123',
81 'nick_name' => 'nicktest123',
82 'contact_source' => 'sourcetest123',
84 $this->inlineEdit('crm-contactinfo-content', $params, 'keep_open');
85 // Clear fields and verify they are deleted
86 $this->inlineEdit('crm-contactinfo-content', array(
89 'contact_source' => '',
91 foreach ($params as $str) {
92 $this->assertElementNotContainsText('crm-contactinfo-content', $str);
96 $this->inlineEdit('crm-phone-content', array(
97 'phone_1_phone' => '123-456-7890',
98 'phone_1_phone_ext' => '101',
99 'phone_1_location_type_id' => array('Work'),
100 'phone_1_phone_type_id' => array('Mobile'),
104 $this->inlineEdit('crm-im-content', array(
105 'im_1_name' => 'testmeout',
106 'im_1_location_type_id' => array('Work'),
107 'im_1_provider_id' => array('Jabber'),
110 // Add an address - should default to home
111 $this->inlineEdit('address-block-1', array(
112 'address_1_street_address' => '123 St',
113 'address_1_city' => 'San Somewhere',
115 // Try to uncheck is_primary, we should get an error and it should stay checked
116 $this->click('address[1][is_primary]');
117 $this->waitForElementPresent('css=#crm-notification-container .error.ui-notify-message');
118 $this->assertChecked('address[1][is_primary]');
119 // Try to open another form while this one is still open - nothing should happen
120 $this->waitForElementPresent('address-block-2');
121 $this->openInlineForm('address-block-2', FALSE);
122 $this->assertElementNotPresent('css#address-block-2.form');
124 $this->inlineEdit('address-block-1', array(
125 'address_1_street_address' => '321 Other St',
126 'address_1_city' => 'Sans Nowhere',
127 'address_1_postal_code' => '99999',
128 'address_1_postal_code_suffix' => '99',
130 // Another address with same location type as first - should give an error
131 $this->inlineEdit('address-block-2', array(
132 'address_2_street_address' => '123 Foo',
133 'address_2_city' => 'San Anywhere',
134 'address_2_location_type_id' => array('Home'),
136 $this->waitForTextPresent('required');
137 // Share address with a new org
138 $this->click('address[2][use_shared_address]');
139 $this->select('profiles_2', 'label=New Organization');
140 $orgName = 'Test Org Inline' . substr(sha1(rand()), 0, 7);
141 $this->waitForElementPresent('css=#contact-dialog-2 form');
142 $this->type('organization_name', $orgName);
143 $this->type('street_address-1', 'Test Org Street');
144 $this->type('city-1', 'Test Org City');
145 $this->clickLink('_qf_Edit_next', 'selected_shared_address-2');
146 $this->waitForTextPresent('Test Org Street');
147 $this->inlineEdit('address-block-2', array(
148 'address_2_location_type_id' => array('Work'),
150 $this->waitForElementPresent('css=.crm-content.crm-contact-current_employer');
151 $this->assertElementContainsText('crm-contactinfo-content', $orgName);
152 $this->assertElementContainsText('address-block-2', $orgName);
153 $this->assertElementContainsText('address-block-2', 'Work Address');
156 $this->inlineEdit('crm-demographic-content', array(
157 'civicrm_gender_Female_1' => 1,
159 'birth_date' => 'date: Jan 1 1970',
161 $this->assertElementContainsText('crm-demographic-content', 'Female');
162 $this->assertElementContainsText('crm-demographic-content', 'Contact is Deceased');
163 $this->inlineEdit('crm-demographic-content', array(
166 $age = date('Y') - 1970;
167 $this->assertElementContainsText('crm-demographic-content', "$age years");
170 $this->inlineEdit('crm-email-content', array(
171 'css=#crm-email-content a.add-more-inline' => TRUE,
172 'email_1_email' => 'test1@monkey.com',
173 'email_2_email' => 'test2@monkey.com',
176 // Try an invalid email
177 $this->inlineEdit('crm-email-content', array(
178 'email_2_email' => 'invalid@monkey,com',
182 $this->inlineEdit('crm-email-content', array(
183 'css=#Email_Block_2 a.crm-delete-inline' => TRUE,
185 $this->assertElementNotContainsText('crm-email-content', 'test2@monkey.com');
187 // Add website with invalid url
188 $this->inlineEdit('crm-website-content', array(
189 'css=#crm-website-content a.add-more-inline' => TRUE,
190 'website_1_url' => 'http://example.com',
191 'website_2_url' => 'something.wrong',
194 // Correct invalid url and add a third website
195 $this->inlineEdit('crm-website-content', array(
196 'css=#crm-website-content a.add-more-inline' => TRUE,
197 'website_2_url' => 'http://example.net',
198 'website_2_website_type_id' => array('Work'),
199 'website_3_url' => 'http://example.biz',
200 'website_3_website_type_id' => array('Main'),
204 $this->inlineEdit('crm-website-content', array(
205 'css=#Website_Block_2 a.crm-delete-inline' => TRUE,
207 $this->assertElementNotContainsText('crm-website-content', 'http://example.net');
209 // Change contact name
210 $this->inlineEdit('crm-contactname-content', array(
211 'first_name' => 'NewName',
212 'prefix_id' => array('Mr.'),
214 // Page title should be updated with new name
215 $this->assertElementContainsText('css=title', "Mr. NewName $lastName");
219 * Click on an inline-edit block and wait for it to open
221 * @param $block string selector
223 private function openInlineForm($block, $wait = TRUE) {
224 $this->mouseDown($block);
225 $this->mouseUp($block);
227 $this->waitForElementPresent("css=#$block .crm-container-snippet form");
232 * Enter values in an inline edit block and save
234 * @param $block string selector
235 * @param $params array
236 * @param $valid str: submit behavior
237 * 'error' if we are expecting a form validation error,
238 * 're_open' (default) after saving, opens the form and validate inputs
239 * 'keep_open' same as 're_open' but doesn't automatically cancel at the end
240 * 'no_open' do not re-open to validate
242 private function inlineEdit($block, $params, $valid = 're_open') {
243 $this->openInlineForm($block);
244 foreach ($params as $item => $val) {
245 switch(gettype($val)) {
250 if (substr($val, 0, 5) == 'date:') {
251 $this->webtestFillDate($item, trim(substr($val, 5)));
254 $this->type($item, $val);
258 $method = $val ?
'check' : 'uncheck';
259 $this->$method($item);
262 foreach ($val as $option) {
263 $selector = is_int($option) ?
'value' : 'label';
264 $this->select($item, "$selector=$option");
269 $this->click("css=#$block input.form-submit");
270 if ($valid !== 'error') {
271 // Verify the form saved
272 $this->waitForElementPresent("css=#$block > .crm-inline-block-content");
274 foreach ($params as $val) {
275 if (is_string($val) && $val && substr($val, 0, 5) != 'date:') {
276 $this->assertElementContainsText($block, $val);
279 elseif (!is_bool($val)) {
282 if (is_array($val)) {
283 foreach ($val as $option) {
284 if (!is_int($option)) {
285 $this->assertElementContainsText($block, $option);
290 // Open the form back up and check everything
291 if ($validate && $valid !== 'no_open') {
292 $this->openInlineForm($block);
293 foreach ($params as $item => $val) {
294 switch(gettype($val)) {
296 if ($val && substr($val, 0, 5) == 'date:') {
297 $val = date('m/d/Y', strtotime(trim(substr($val, 5))));
301 $this->assertElementValueEquals($item, $val);
305 $method = $val ?
'assertChecked' : 'assertNotChecked';
306 $this->$method($item);
309 foreach ($val as $option) {
310 $method = is_int($option) ?
'assertIsSelected' : 'assertSelected';
311 $this->$method($item, $option);
316 if ($valid !== 'keep_open') {
317 $this->click("css=#$block input.cancel");
321 // Verify there was a form error
323 $this->waitForElementPresent('css=#crm-notification-container .error.ui-notify-message');
324 $this->click('css=#crm-notification-container .error .ui-notify-cross');