Merge remote-tracking branch 'upstream/4.4' into 4.4-master-2014-04-04-00-08-28
[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[2]/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]");
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 $this->waitForPageToLoad($this->getTimeoutMsec());
82
83 // Go for Activity Search
84 $this->_checkActivity($subject, $signature);
85
86 // Set Editor back to default so we don't break other tests
87 $this->_selectEditor('CKEditor');
88 }
89
90 /**
91 * Test Signature in CKEditor.
92 */
93 function testCKEditor() {
94 $this->webtestLogin();
95
96 $this->openCiviPage('dashboard', 'reset=1', 'crm-recently-viewed');
97 $this->click("//div[@id='crm-recently-viewed']/ul/li/a");
98 $this->waitForPageToLoad($this->getTimeoutMsec());
99 $name = $this->getText("xpath=//div[@class='crm-summary-display_name']");
100
101 // Get contact id from url.
102 $contactId = $this->urlArg('cid');
103
104 // Select Your Editor
105 $this->_selectEditor('CKEditor');
106
107 $this->openCiviPage("contact/add", "reset=1&action=update&cid={$contactId}");
108 $this->click("//tr[@id='Email_Block_1']/td[1]/div[2]/div[1]");
109
110 // HTML format message
111 $signature = 'Contact Signature in html';
112 $this->fireEvent('email_1_signature_html', 'focus');
113 $this->fillRichTextField('email_1_signature_html', $signature, 'CKEditor');
114
115 // TEXT Format Message
116 $this->type('email_1_signature_text', 'Contact Signature in text');
117 $this->click('_qf_Contact_upload_view-top');
118 $this->waitForPageToLoad($this->getTimeoutMsec());
119
120 // Is status message correct?
121 $this->waitForText('crm-notification-container', "{$name} has been updated.");
122
123 // Go for Ckeck Your Editor, Click on Send Mail
124 $this->click("//a[@id='crm-contact-actions-link']/span");
125 $this->clickLink('link=Send an Email', 'subject');
126
127 $this->click('subject');
128 $subject = 'Subject_' . substr(sha1(rand()), 0, 7);
129 $this->type('subject', $subject);
130
131 // Is signature correct? in Editor
132 $this->_checkSignature('html_message', $signature, 'CKEditor');
133
134 $this->click('_qf_Email_upload-top');
135 $this->waitForPageToLoad($this->getTimeoutMsec());
136
137 // Go for Activity Search
138 $this->_checkActivity($subject, $signature);
139 }
140
141 /**
142 * Helper function to select Editor.
143 */
144 function _selectEditor($editor) {
145 $this->openCiviPage('admin/setting/preferences/display', 'reset=1');
146
147 // Change editor if not already selected
148 if ($this->getSelectedLabel('editor_id') != $editor) {
149 $this->click('editor_id');
150 $this->select('editor_id', "label=$editor");
151 $this->click('_qf_Display_next-bottom');
152 $this->waitForPageToLoad($this->getTimeoutMsec());
153 }
154 }
155
156 /**
157 * Helper function for Check Signature in Editor.
158 */
159 function _checkSignature($fieldName, $signature, $editor) {
160 if ($editor == 'CKEditor') {
161 $this->waitForElementPresent("xpath=//div[@id='cke_{$fieldName}']//iframe");
162 $this->selectFrame("xpath=//div[@id='cke_{$fieldName}']//iframe");
163 }
164 else {
165 $this->selectFrame("xpath=//iframe[@id='{$fieldName}_ifr']");
166 }
167
168 $this->verifyText('//html/body', preg_quote("{$signature}"));
169 $this->selectFrame('relative=top');
170 }
171
172 /**
173 * Helper function for Check Signature in Activity.
174 */
175 function _checkActivity($subject, $signature) {
176 $this->openCiviPage('activity/search', 'reset=1', '_qf_Search_refresh');
177
178 $this->type('activity_subject', $subject);
179
180 $this->clickLink('_qf_Search_refresh', 'Search');
181
182 // View your Activity
183 $this->clickLink("xpath=id('Search')/div[3]/div/div[2]/table/tbody/tr[2]/td[9]/span/a[text()='View']", '_qf_ActivityView_next-bottom');
184
185 // Is signature correct? in Activity
186 $this->assertTextPresent($signature);
187 }
188 }
189