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