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 is the path where our testing install resides.
37 // The rest of URL is defined in CiviSeleniumTestCase base class, in
39 $this->open($this->sboxPath
);
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();
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');
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,
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,
68 $this->waitForElementPresent('css=.icon.privacy-flag.do-not-phone');
69 $this->inlineEdit('crm-communication-pref-content', array(
70 'email_greeting_custom' => 'Hey You!',
72 $this->assertElementNotPresent('css=.icon.privacy-flag.do-not-email');
75 $this->click('css=div.crm-custom-set-block-1 .collapsible-title');
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',
87 'job_title' => 'jobtest123',
88 'nick_name' => 'nicktest123',
89 'contact_source' => 'sourcetest123',
91 $this->inlineEdit('crm-contactinfo-content', $params, 'keep_open');
92 // Clear fields and verify they are deleted
93 $this->inlineEdit('crm-contactinfo-content', array(
96 'contact_source' => '',
98 foreach ($params as $str) {
99 $this->assertElementNotContainsText('crm-contactinfo-content', $str);
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'),
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'),
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',
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');
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',
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'),
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');
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'),
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 // Page title should be updated with new name
224 $this->assertElementContainsText('css=title', "Mr. NewName $lastName");
228 * Click on an inline-edit block and wait for it to open
230 * @param $block string selector
232 private function openInlineForm($block, $wait = TRUE) {
233 $this->mouseDown($block);
234 $this->mouseUp($block);
236 $this->waitForElementPresent("css=#$block .crm-container-snippet form");
241 * Enter values in an inline edit block and save
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
251 private function inlineEdit($block, $params, $valid = 're_open') {
252 $this->openInlineForm($block);
253 foreach ($params as $item => $val) {
254 switch(gettype($val)) {
259 if (substr($val, 0, 5) == 'date:') {
260 $this->webtestFillDate($item, trim(substr($val, 5)));
263 $this->type($item, $val);
267 $method = $val ?
'check' : 'uncheck';
268 $this->$method($item);
271 foreach ($val as $option) {
272 $selector = is_int($option) ?
'value' : 'label';
273 $this->select($item, "$selector=$option");
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");
283 foreach ($params as $val) {
284 if (is_string($val) && $val && substr($val, 0, 5) != 'date:') {
285 $this->assertElementContainsText($block, $val);
288 elseif (!is_bool($val)) {
291 if (is_array($val)) {
292 foreach ($val as $option) {
293 if (!is_int($option)) {
294 $this->assertElementContainsText($block, $option);
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)) {
305 if ($val && substr($val, 0, 5) == 'date:') {
306 $val = date('m/d/Y', strtotime(trim(substr($val, 5))));
310 $this->assertElementValueEquals($item, $val);
314 $method = $val ?
'assertChecked' : 'assertNotChecked';
315 $this->$method($item);
318 foreach ($val as $option) {
319 $method = is_int($option) ?
'assertIsSelected' : 'assertSelected';
320 $this->$method($item, $option);
325 if ($valid !== 'keep_open') {
326 $this->click("css=#$block input.cancel");
330 // Verify there was a form error
332 $this->waitForElementPresent('css=#crm-notification-container .error.ui-notify-message');
333 $this->click('css=#crm-notification-container .error .ui-notify-cross');