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