Merge pull request #4875 from civicrm/minor-fix
[civicrm-core.git] / tests / phpunit / WebTest / Contact / SignatureTest.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
39de6fd5 4 | CiviCRM version 4.6 |
6a488035 5 +--------------------------------------------------------------------+
06a1bc01 6 | Copyright CiviCRM LLC (c) 2004-2014 |
6a488035
TO
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
6a488035 27require_once 'CiviTest/CiviSeleniumTestCase.php';
e9479dcf
EM
28
29/**
30 * Class WebTest_Contact_SignatureTest
31 */
6a488035
TO
32class WebTest_Contact_SignatureTest extends CiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
efb29358
CW
38 /**
39 * Test Signature in TinyMC.
6a488035 40 */
00be9182 41 public function testTinyMCE() {
6a488035
TO
42 $this->webtestLogin();
43
44 $this->openCiviPage('dashboard', 'reset=1', 'crm-recently-viewed');
45 $this->click("//div[@id='crm-recently-viewed']/ul/li/a");
46 $this->waitForPageToLoad($this->getTimeoutMsec());
47 $name = $this->getText("xpath=//div[@class='crm-summary-display_name']");
48
49 // Get contact id from url.
efb29358 50 $contactId = $this->urlArg('cid');
6a488035
TO
51
52 // Select Your Editor
53 $this->_selectEditor('TinyMCE');
54
efb29358 55 $this->openCiviPage("contact/add", "reset=1&action=update&cid=$contactId");
6a488035 56
44c45561 57 $this->click("//tr[@id='Email_Block_1']/td[1]/div[3]/div[1]");
6a488035
TO
58 // HTML format message
59 $signature = 'Contact Signature in html';
60
61 $this->fireEvent('email_1_signature_html', 'focus');
62 $this->fillRichTextField('email_1_signature_html', $signature, 'TinyMCE');
63
64 // TEXT Format Message
65 $this->type('email_1_signature_text', 'Contact Signature in text');
66 $this->click('_qf_Contact_upload_view-top');
67 $this->waitForPageToLoad($this->getTimeoutMsec());
68
69 // Is status message correct?
6c5f7368 70 $this->waitForText('crm-notification-container', "Contact Saved");
6a488035
TO
71
72 // Go for Ckeck Your Editor, Click on Send Mail
73 $this->click("//a[@id='crm-contact-actions-link']/span");
405bc6ee
CW
74 // the other test checks this in a popup, we'll try it full-page here
75 $this->clickLinkSuppressPopup('link=Send an Email', "xpath=//body[@id='tinymce']/p[2]");
6a488035
TO
76
77 $this->click('subject');
efb29358 78 $subject = 'Subject_' . substr(sha1(rand()), 0, 8);
6a488035
TO
79 $this->type('subject', $subject);
80
81 // Is signature correct? in Editor
82 $this->_checkSignature('html_message', $signature, 'TinyMCE');
83
84 $this->click('_qf_Email_upload-top');
6a488035
TO
85
86 // Go for Activity Search
87 $this->_checkActivity($subject, $signature);
efb29358
CW
88
89 // Set Editor back to default so we don't break other tests
90 $this->_selectEditor('CKEditor');
6a488035
TO
91 }
92
efb29358 93 /**
6a488035
TO
94 * Test Signature in CKEditor.
95 */
00be9182 96 public function testCKEditor() {
6a488035
TO
97 $this->webtestLogin();
98
99 $this->openCiviPage('dashboard', 'reset=1', 'crm-recently-viewed');
100 $this->click("//div[@id='crm-recently-viewed']/ul/li/a");
101 $this->waitForPageToLoad($this->getTimeoutMsec());
102 $name = $this->getText("xpath=//div[@class='crm-summary-display_name']");
103
104 // Get contact id from url.
a471a3b6 105 $contactId = $this->urlArg('cid');
6a488035
TO
106
107 // Select Your Editor
108 $this->_selectEditor('CKEditor');
109
69369531 110 $this->openCiviPage("contact/add", "reset=1&action=update&cid={$contactId}");
44c45561 111 $this->click("//tr[@id='Email_Block_1']/td[1]/div[3]/div[1]");
efb29358 112
6a488035
TO
113 // HTML format message
114 $signature = 'Contact Signature in html';
115 $this->fireEvent('email_1_signature_html', 'focus');
116 $this->fillRichTextField('email_1_signature_html', $signature, 'CKEditor');
117
118 // TEXT Format Message
119 $this->type('email_1_signature_text', 'Contact Signature in text');
120 $this->click('_qf_Contact_upload_view-top');
121 $this->waitForPageToLoad($this->getTimeoutMsec());
122
123 // Is status message correct?
6c5f7368 124 $this->waitForText('crm-notification-container', "{$name} has been updated.");
6a488035
TO
125
126 // Go for Ckeck Your Editor, Click on Send Mail
127 $this->click("//a[@id='crm-contact-actions-link']/span");
44c45561 128 $this->clickLink('link=Send an Email', 'subject', FALSE);
6a488035
TO
129
130 $this->click('subject');
131 $subject = 'Subject_' . substr(sha1(rand()), 0, 7);
132 $this->type('subject', $subject);
133
134 // Is signature correct? in Editor
135 $this->_checkSignature('html_message', $signature, 'CKEditor');
136
137 $this->click('_qf_Email_upload-top');
44c45561 138 $this->waitForElementPresent("//a[@id='crm-contact-actions-link']/span");
6a488035
TO
139
140 // Go for Activity Search
141 $this->_checkActivity($subject, $signature);
142 }
143
efb29358 144 /**
6a488035
TO
145 * Helper function to select Editor.
146 */
00be9182 147 public function _selectEditor($editor) {
69369531 148 $this->openCiviPage('admin/setting/preferences/display', 'reset=1');
6a488035 149
efb29358
CW
150 // Change editor if not already selected
151 if ($this->getSelectedLabel('editor_id') != $editor) {
152 $this->click('editor_id');
153 $this->select('editor_id', "label=$editor");
154 $this->click('_qf_Display_next-bottom');
155 $this->waitForPageToLoad($this->getTimeoutMsec());
156 }
6a488035 157 }
efb29358
CW
158
159 /**
6a488035
TO
160 * Helper function for Check Signature in Editor.
161 */
00be9182 162 public function _checkSignature($fieldName, $signature, $editor) {
6a488035
TO
163 if ($editor == 'CKEditor') {
164 $this->waitForElementPresent("xpath=//div[@id='cke_{$fieldName}']//iframe");
165 $this->selectFrame("xpath=//div[@id='cke_{$fieldName}']//iframe");
166 }
167 else {
168 $this->selectFrame("xpath=//iframe[@id='{$fieldName}_ifr']");
169 }
170
171 $this->verifyText('//html/body', preg_quote("{$signature}"));
172 $this->selectFrame('relative=top');
173 }
efb29358
CW
174
175 /**
6a488035
TO
176 * Helper function for Check Signature in Activity.
177 */
00be9182 178 public function _checkActivity($subject, $signature) {
6a488035
TO
179 $this->openCiviPage('activity/search', 'reset=1', '_qf_Search_refresh');
180
181 $this->type('activity_subject', $subject);
182
225a8648 183 $this->clickLink('_qf_Search_refresh', 'Search');
6a488035
TO
184
185 // View your Activity
44c45561 186 $this->clickLink("xpath=id('Search')/div[3]/div/div[2]/table/tbody/tr[2]/td[9]/span/a[text()='View']", '_qf_ActivityView_cancel-bottom', FALSE);
6a488035
TO
187
188 // Is signature correct? in Activity
efb29358 189 $this->assertTextPresent($signature);
6a488035
TO
190 }
191}