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');
67 $this->openInlineForm('custom-set-content-1');
68 $dateFieldId = $this->getAttribute("xpath=//div[@id='constituent_information']/table/tbody/tr[3]/td[@class='html-adjust']/input@id");
69 $this->inlineEdit('custom-set-content-1', array(
70 'CIVICRM_QFID_Edu_2' => 1,
71 "//div[@id='constituent_information']/table/tbody/tr[2]/td[@class='html-adjust']/select" => array('Single'),
72 $dateFieldId => 'date: now - 10 years',
77 'job_title' => 'jobtest123',
78 'nick_name' => 'nicktest123',
79 'contact_source' => 'sourcetest123',
81 $this->inlineEdit('crm-contactinfo-content', $params, 'keep_open');
82 // Clear fields and verify they are deleted
83 $this->inlineEdit('crm-contactinfo-content', array(
86 'contact_source' => '',
88 foreach ($params as $str) {
89 $this->assertElementNotContainsText('crm-contactinfo-content', $str);
93 $this->inlineEdit('crm-phone-content', array(
94 'phone_1_phone' => '123-456-7890',
95 'phone_1_phone_ext' => '101',
96 'phone_1_location_type_id' => array('Work'),
97 'phone_1_phone_type_id' => array('Mobile'),
101 $this->inlineEdit('crm-im-content', array(
102 'im_1_name' => 'testmeout',
103 'im_1_location_type_id' => array('Work'),
104 'im_1_provider_id' => array('Jabber'),
107 // Add an address - should default to home
108 $this->inlineEdit('address-block-1', array(
109 'address_1_street_address' => '123 St',
110 'address_1_city' => 'San Somewhere',
112 // Try to uncheck is_primary, we should get an error and it should stay checked
113 $this->click('address[1][is_primary]');
114 $this->waitForElementPresent('css=#crm-notification-container .error.ui-notify-message');
115 $this->assertChecked('address[1][is_primary]');
116 // Try to open another form while this one is still open - nothing should happen
117 $this->waitForElementPresent('address-block-2');
118 $this->openInlineForm('address-block-2', FALSE);
119 $this->assertElementNotPresent('css#address-block-2.form');
121 $this->inlineEdit('address-block-1', array(
122 'address_1_street_address' => '321 Other St',
123 'address_1_city' => 'Sans Nowhere',
124 'address_1_postal_code' => '99999',
125 'address_1_postal_code_suffix' => '99',
127 // Another address with same location type as first - should give an error
128 $this->inlineEdit('address-block-2', array(
129 'address_2_street_address' => '123 Foo',
130 'address_2_city' => 'San Anywhere',
131 'address_2_location_type_id' => array('Home'),
133 $this->waitForTextPresent('required');
134 // Share address with a new org
135 $this->click('address[2][use_shared_address]');
136 $this->select('profiles_2', 'label=New Organization');
137 $orgName = 'Test Org Inline' . substr(sha1(rand()), 0, 7);
138 $this->waitForElementPresent('css=#contact-dialog-2 form');
139 $this->type('organization_name', $orgName);
140 $this->type('street_address-1', 'Test Org Street');
141 $this->type('city-1', 'Test Org City');
142 $this->click('_qf_Edit_next');
144 $this->waitForElementPresent('selected_shared_address-2');
145 $this->waitForTextPresent('Test Org Street');
146 $this->inlineEdit('address-block-2', array(
147 'address_2_location_type_id' => array('Work'),
149 $this->waitForElementPresent('css=.crm-content.crm-contact-current_employer');
150 $this->assertElementContainsText('crm-contactinfo-content', $orgName);
151 $this->assertElementContainsText('address-block-2', $orgName);
152 $this->assertElementContainsText('address-block-2', 'Work Address');
155 $this->inlineEdit('crm-demographic-content', array(
156 'civicrm_gender_Female_1' => 1,
158 'birth_date' => 'date: Jan 1 1970',
160 $this->assertElementContainsText('crm-demographic-content', 'Female');
161 $this->assertElementContainsText('crm-demographic-content', 'Contact is Deceased');
162 $this->inlineEdit('crm-demographic-content', array(
165 $age = date('Y') - 1970;
166 $this->assertElementContainsText('crm-demographic-content', "$age years");
169 $this->inlineEdit('crm-email-content', array(
170 'css=#crm-email-content a.add-more-inline' => TRUE,
171 'email_1_email' => 'test1@monkey.com',
172 'email_2_email' => 'test2@monkey.com',
175 // Try an invalid email
176 $this->inlineEdit('crm-email-content', array(
177 'email_2_email' => 'invalid@monkey,com',
181 $this->inlineEdit('crm-email-content', array(
182 'css=#Email_Block_2 a.crm-delete-inline' => TRUE,
184 $this->assertElementNotContainsText('crm-email-content', 'test2@monkey.com');
186 // Add website with invalid url
187 $this->inlineEdit('crm-website-content', array(
188 'css=#crm-website-content a.add-more-inline' => TRUE,
189 'website_1_url' => 'http://example.com',
190 'website_2_url' => 'something.wrong',
193 // Correct invalid url and add a third website
194 $this->inlineEdit('crm-website-content', array(
195 'css=#crm-website-content a.add-more-inline' => TRUE,
196 'website_2_url' => 'http://example.net',
197 'website_2_website_type_id' => array('Work'),
198 'website_3_url' => 'http://example.biz',
199 'website_3_website_type_id' => array('Main'),
203 $this->inlineEdit('crm-website-content', array(
204 'css=#Website_Block_2 a.crm-delete-inline' => TRUE,
206 $this->assertElementNotContainsText('crm-website-content', 'http://example.net');
208 // Change contact name
209 $this->inlineEdit('crm-contactname-content', array(
210 'first_name' => 'NewName',
211 'prefix_id' => array('Mr.'),
213 // Page title should be updated with new name
214 $this->assertElementContainsText('css=title', "Mr. NewName $lastName");
218 * Click on an inline-edit block and wait for it to open
220 * @param $block string selector
222 private function openInlineForm($block, $wait = TRUE) {
223 $this->mouseDown($block);
224 $this->mouseUp($block);
226 $this->waitForElementPresent("css=#$block .crm-container-snippet form");
231 * Enter values in an inline edit block and save
233 * @param $block string selector
234 * @param $params array
235 * @param $valid str: submit behavior
236 * 'error' if we are expecting a form validation error,
237 * 're_open' (default) after saving, opens the form and validate inputs
238 * 'keep_open' same as 're_open' but doesn't automatically cancel at the end
239 * 'no_open' do not re-open to validate
241 private function inlineEdit($block, $params, $valid = 're_open') {
242 $this->openInlineForm($block);
243 foreach ($params as $item => $val) {
244 switch(gettype($val)) {
249 if (substr($val, 0, 5) == 'date:') {
250 $this->webtestFillDate($item, trim(substr($val, 5)));
253 $this->type($item, $val);
257 $method = $val ?
'check' : 'uncheck';
258 $this->$method($item);
261 foreach ($val as $option) {
262 $selector = is_int($option) ?
'value' : 'label';
263 $this->select($item, "$selector=$option");
268 $this->click("css=#$block input.form-submit");
269 if ($valid !== 'error') {
270 // Verify the form saved
271 $this->waitForElementPresent("css=#$block > .crm-inline-block-content");
273 foreach ($params as $val) {
274 if (is_string($val) && $val && substr($val, 0, 5) != 'date:') {
275 $this->assertElementContainsText($block, $val);
278 elseif (!is_bool($val)) {
281 if (is_array($val)) {
282 foreach ($val as $option) {
283 if (!is_int($option)) {
284 $this->assertElementContainsText($block, $option);
289 // Open the form back up and check everything
290 if ($validate && $valid !== 'no_open') {
291 $this->openInlineForm($block);
292 foreach ($params as $item => $val) {
293 switch(gettype($val)) {
295 if ($val && substr($val, 0, 5) == 'date:') {
296 $val = date('m/d/Y', strtotime(trim(substr($val, 5))));
300 $this->assertElementValueEquals($item, $val);
304 $method = $val ?
'assertChecked' : 'assertNotChecked';
305 $this->$method($item);
308 foreach ($val as $option) {
309 $method = is_int($option) ?
'assertIsSelected' : 'assertSelected';
310 $this->$method($item, $option);
315 if ($valid !== 'keep_open') {
316 $this->click("css=#$block input.cancel");
320 // Verify there was a form error
322 $this->waitForElementPresent('css=#crm-notification-container .error.ui-notify-message');
323 $this->click('css=#crm-notification-container .error .ui-notify-cross');