whitespace cleanup
[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 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->assertElementContainsText('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 $this->clickLink('link=Send an Email', 'subject');
71
72 $this->click('subject');
73 $subject = 'Subject_' . substr(sha1(rand()), 0, 8);
74 $this->type('subject', $subject);
75
76 // Is signature correct? in Editor
77 $this->_checkSignature('html_message', $signature, 'TinyMCE');
78
79 $this->click('_qf_Email_upload-top');
80 $this->waitForPageToLoad($this->getTimeoutMsec());
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 $matches = array();
102 preg_match('/cid=([0-9]+)/', $this->getLocation(), $matches);
103 $contactId = $matches[1];
104
105 // Select Your Editor
106 $this->_selectEditor('CKEditor');
107
108 $this->openCiviPage("contact/add", "reset=1&action=update&cid={$contactId}");
109 $this->click("//tr[@id='Email_Block_1']/td[1]/div[2]/div[1]");
110
111 // HTML format message
112 $signature = 'Contact Signature in html';
113 $this->fireEvent('email_1_signature_html', 'focus');
114 $this->fillRichTextField('email_1_signature_html', $signature, 'CKEditor');
115
116 // TEXT Format Message
117 $this->type('email_1_signature_text', 'Contact Signature in text');
118 $this->click('_qf_Contact_upload_view-top');
119 $this->waitForPageToLoad($this->getTimeoutMsec());
120
121 // Is status message correct?
122 $this->assertElementContainsText("crm-notification-container", "{$name} has been updated.");
123
124 // Go for Ckeck Your Editor, Click on Send Mail
125 $this->click("//a[@id='crm-contact-actions-link']/span");
126 $this->clickLink('link=Send an Email', 'subject');
127
128 $this->click('subject');
129 $subject = 'Subject_' . substr(sha1(rand()), 0, 7);
130 $this->type('subject', $subject);
131
132 // Is signature correct? in Editor
133 $this->_checkSignature('html_message', $signature, 'CKEditor');
134
135 $this->click('_qf_Email_upload-top');
136 $this->waitForPageToLoad($this->getTimeoutMsec());
137
138 // Go for Activity Search
139 $this->_checkActivity($subject, $signature);
140 }
141
142 /**
143 * Helper function to select Editor.
144 */
145 function _selectEditor($editor) {
146 $this->openCiviPage('admin/setting/preferences/display', 'reset=1');
147
148 // Change editor if not already selected
149 if ($this->getSelectedLabel('editor_id') != $editor) {
150 $this->click('editor_id');
151 $this->select('editor_id', "label=$editor");
152 $this->click('_qf_Display_next-bottom');
153 $this->waitForPageToLoad($this->getTimeoutMsec());
154 }
155 }
156
157 /**
158 * Helper function for Check Signature in Editor.
159 */
160 function _checkSignature($fieldName, $signature, $editor) {
161 if ($editor == 'CKEditor') {
162 $this->waitForElementPresent("xpath=//div[@id='cke_{$fieldName}']//iframe");
163 $this->selectFrame("xpath=//div[@id='cke_{$fieldName}']//iframe");
164 }
165 else {
166 $this->selectFrame("xpath=//iframe[@id='{$fieldName}_ifr']");
167 }
168
169 $this->verifyText('//html/body', preg_quote("{$signature}"));
170 $this->selectFrame('relative=top');
171 }
172
173 /**
174 * Helper function for Check Signature in Activity.
175 */
176 function _checkActivity($subject, $signature) {
177 $this->openCiviPage('activity/search', 'reset=1', '_qf_Search_refresh');
178
179 $this->type('activity_subject', $subject);
180
181 $this->clickLink('_qf_Search_refresh', 'Search');
182
183 // View your Activity
184 $this->clickLink("xpath=id('Search')/div[3]/div/div[2]/table/tbody/tr[2]/td[9]/span/a[text()='View']", '_qf_ActivityView_next-bottom');
185
186 // Is signature correct? in Activity
187 $this->assertTextPresent($signature);
188 }
189 }
190