Webtests and CRM test fix
[civicrm-core.git] / tests / phpunit / WebTest / Contact / SignatureTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
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
29 /**
30 * Class WebTest_Contact_SignatureTest
31 */
32 class WebTest_Contact_SignatureTest extends CiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
38 /**
39 * Test Signature in TinyMC.
40 */
41 public function testTinyMCE() {
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.
50 $contactId = $this->urlArg('cid');
51
52 // Select Your Editor
53 $this->_selectEditor('TinyMCE');
54
55 $this->openCiviPage("contact/add", "reset=1&action=update&cid=$contactId");
56
57 $this->click("//tr[@id='Email_Block_1']/td[1]/div[3]/div[1]");
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?
70 $this->waitForText('crm-notification-container', "Contact Saved");
71
72 // Go for Ckeck Your Editor, Click on Send Mail
73 $this->click("//a[@id='crm-contact-actions-link']/span");
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]");
76
77 $this->click('subject');
78 $subject = 'Subject_' . substr(sha1(rand()), 0, 8);
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
86 // Go for Activity Search
87 $this->_checkActivity($subject, $signature);
88
89 // Set Editor back to default so we don't break other tests
90 $this->_selectEditor('CKEditor');
91 }
92
93 /**
94 * Test Signature in CKEditor.
95 */
96 public function testCKEditor() {
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.
105 $contactId = $this->urlArg('cid');
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[3]/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->waitForText('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->clickLink('link=Send an Email', 'subject', FALSE);
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');
138 $this->waitForElementPresent("//a[@id='crm-contact-actions-link']/span");
139
140 // Go for Activity Search
141 $this->_checkActivity($subject, $signature);
142 }
143
144 /**
145 * Helper function to select Editor.
146 */
147 public function _selectEditor($editor) {
148 $this->openCiviPage('admin/setting/preferences/display', 'reset=1');
149
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 }
157 }
158
159 /**
160 * Helper function for Check Signature in Editor.
161 */
162 public 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 /**
176 * Helper function for Check Signature in Activity.
177 */
178 public function _checkActivity($subject, $signature) {
179 $this->openCiviPage('activity/search', 'reset=1', '_qf_Search_refresh');
180
181 $this->type('activity_subject', $subject);
182
183 $this->clickLink('_qf_Search_refresh', 'Search');
184
185 // View your Activity
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);
187
188 // Is signature correct? in Activity
189 $this->assertTextPresent($signature);
190 }
191 }