-- webtest fixes and improvement
[civicrm-core.git] / tests / phpunit / WebTest / Contact / SignatureTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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
28 require_once 'CiviTest/CiviSeleniumTestCase.php';
29 class WebTest_Contact_SignatureTest extends CiviSeleniumTestCase {
30
31 protected function setUp() {
32 parent::setUp();
33 }
34
35 /*
36 * Test Signature in TinyMC.
37 */
38 function testTinyMCE() {
39 $this->webtestLogin();
40
41 $this->openCiviPage('dashboard', 'reset=1', 'crm-recently-viewed');
42 $this->click("//div[@id='crm-recently-viewed']/ul/li/a");
43 $this->waitForPageToLoad($this->getTimeoutMsec());
44 $name = $this->getText("xpath=//div[@class='crm-summary-display_name']");
45
46 // Get contact id from url.
47 $matches = array();
48 preg_match('/cid=([0-9]+)/', $this->getLocation(), $matches);
49 $contactId = $matches[1];
50
51 // Select Your Editor
52 $this->_selectEditor('TinyMCE');
53
54 $this->openCiviPage("contact/add", "reset=1&action=update&cid={$contactId}");
55
56 $this->click("//tr[@id='Email_Block_1']/td[1]/div[2]/div[1]");
57 // HTML format message
58 $signature = 'Contact Signature in html';
59
60 $this->fireEvent('email_1_signature_html', 'focus');
61 $this->fillRichTextField('email_1_signature_html', $signature, 'TinyMCE');
62
63 // TEXT Format Message
64 $this->type('email_1_signature_text', 'Contact Signature in text');
65 $this->click('_qf_Contact_upload_view-top');
66 $this->waitForPageToLoad($this->getTimeoutMsec());
67
68 // Is status message correct?
69 $this->assertElementContainsText('crm-notification-container', "Contact Saved");
70
71 // Go for Ckeck Your Editor, Click on Send Mail
72 $this->click("//a[@id='crm-contact-actions-link']/span");
73 $this->click('link=Send an Email');
74 $this->waitForPageToLoad($this->getTimeoutMsec());
75 sleep(10);
76
77 $this->click('subject');
78 $subject = 'Subject_' . substr(sha1(rand()), 0, 7);
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');
85 $this->waitForPageToLoad($this->getTimeoutMsec());
86
87 // Go for Activity Search
88 $this->_checkActivity($subject, $signature);
89 }
90
91 /*
92 * Test Signature in CKEditor.
93 */
94 function testCKEditor() {
95 $this->webtestLogin();
96
97 $this->openCiviPage('dashboard', 'reset=1', 'crm-recently-viewed');
98 $this->click("//div[@id='crm-recently-viewed']/ul/li/a");
99 $this->waitForPageToLoad($this->getTimeoutMsec());
100 $name = $this->getText("xpath=//div[@class='crm-summary-display_name']");
101
102 // Get contact id from url.
103 $matches = array();
104 preg_match('/cid=([0-9]+)/', $this->getLocation(), $matches);
105 $contactId = $matches[1];
106
107 // Select Your Editor
108 $this->_selectEditor('CKEditor');
109
110 $this->openCiviPage("contact/add", "reset=1&action=update&cid={$contactId}");
111 $this->click("//tr[@id='Email_Block_1']/td[1]/div[2]/div[1]");
112
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?
124 $this->assertElementContainsText("crm-notification-container", "{$name} has been updated.");
125
126 // Go for Ckeck Your Editor, Click on Send Mail
127 $this->click("//a[@id='crm-contact-actions-link']/span");
128 $this->click('link=Send an Email');
129 $this->waitForPageToLoad($this->getTimeoutMsec());
130 sleep(10);
131
132 $this->click('subject');
133 $subject = 'Subject_' . substr(sha1(rand()), 0, 7);
134 $this->type('subject', $subject);
135
136 // Is signature correct? in Editor
137 $this->_checkSignature('html_message', $signature, 'CKEditor');
138
139 $this->click('_qf_Email_upload-top');
140 $this->waitForPageToLoad($this->getTimeoutMsec());
141
142 // Go for Activity Search
143 $this->_checkActivity($subject, $signature);
144 }
145
146 /*
147 * Helper function to select Editor.
148 */
149 function _selectEditor($editor) {
150 // Go directly to the URL of Set Default Editor.
151 $this->openCiviPage('admin/setting/preferences/display', 'reset=1');
152
153 // Select your Editor
154 $this->click('editor_id');
155 $this->select('editor_id', "label=$editor");
156 $this->click('_qf_Display_next-bottom');
157 $this->waitForPageToLoad($this->getTimeoutMsec());
158 }
159 /*
160 * Helper function for Check Signature in Editor.
161 */
162 function _checkSignature($fieldName, $signature, $editor) {
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 }
174 /*
175 * Helper function for Check Signature in Activity.
176 */
177 function _checkActivity($subject, $signature) {
178 $this->openCiviPage('activity/search', 'reset=1', '_qf_Search_refresh');
179
180 $this->type('activity_subject', $subject);
181
182 $this->click('_qf_Search_refresh');
183 $this->waitForPageToLoad($this->getTimeoutMsec());
184 $this->waitForElementPresent('Search');
185
186 // View your Activity
187 $this->click("xpath=id('Search')/div[3]/div/div[2]/table/tbody/tr[2]/td[9]/span/a[text()='View']");
188 $this->waitForPageToLoad($this->getTimeoutMsec());
189 $this->waitForElementPresent('_qf_ActivityView_next-bottom');
190
191 // Is signature correct? in Activity
192 $this->assertTrue($this->isTextPresent($signature));
193 }
194 }
195