Merge pull request #12178 from jitendrapurohit/membership-4
[civicrm-core.git] / tests / phpunit / WebTest / Contact / SignatureTest.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
2fe49090 4 | CiviCRM version 5 |
6a488035 5 +--------------------------------------------------------------------+
8c9251b3 6 | Copyright CiviCRM LLC (c) 2004-2018 |
6a488035
TO
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 +--------------------------------------------------------------------+
d25dd0ee 25 */
6a488035 26
6a488035 27require_once 'CiviTest/CiviSeleniumTestCase.php';
e9479dcf
EM
28
29/**
30 * Class WebTest_Contact_SignatureTest
31 */
6a488035
TO
32class WebTest_Contact_SignatureTest extends CiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
efb29358 38 /**
6a488035
TO
39 * Test Signature in CKEditor.
40 */
00be9182 41 public function testCKEditor() {
6a488035
TO
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.
a471a3b6 50 $contactId = $this->urlArg('cid');
6a488035
TO
51
52 // Select Your Editor
53 $this->_selectEditor('CKEditor');
54
69369531 55 $this->openCiviPage("contact/add", "reset=1&action=update&cid={$contactId}");
44c45561 56 $this->click("//tr[@id='Email_Block_1']/td[1]/div[3]/div[1]");
efb29358 57
6a488035
TO
58 // HTML format message
59 $signature = 'Contact Signature in html';
60 $this->fireEvent('email_1_signature_html', 'focus');
61 $this->fillRichTextField('email_1_signature_html', $signature, 'CKEditor');
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?
6c5f7368 69 $this->waitForText('crm-notification-container', "{$name} has been updated.");
6a488035
TO
70
71 // Go for Ckeck Your Editor, Click on Send Mail
72 $this->click("//a[@id='crm-contact-actions-link']/span");
44c45561 73 $this->clickLink('link=Send an Email', 'subject', FALSE);
6a488035
TO
74
75 $this->click('subject');
76 $subject = 'Subject_' . substr(sha1(rand()), 0, 7);
77 $this->type('subject', $subject);
78
79 // Is signature correct? in Editor
80 $this->_checkSignature('html_message', $signature, 'CKEditor');
81
82 $this->click('_qf_Email_upload-top');
44c45561 83 $this->waitForElementPresent("//a[@id='crm-contact-actions-link']/span");
6a488035
TO
84
85 // Go for Activity Search
86 $this->_checkActivity($subject, $signature);
87 }
88
efb29358 89 /**
6a488035 90 * Helper function to select Editor.
1e1fdcf6 91 * @param $editor
6a488035 92 */
00be9182 93 public function _selectEditor($editor) {
69369531 94 $this->openCiviPage('admin/setting/preferences/display', 'reset=1');
6a488035 95
efb29358
CW
96 // Change editor if not already selected
97 if ($this->getSelectedLabel('editor_id') != $editor) {
98 $this->click('editor_id');
99 $this->select('editor_id', "label=$editor");
100 $this->click('_qf_Display_next-bottom');
101 $this->waitForPageToLoad($this->getTimeoutMsec());
102 }
6a488035 103 }
efb29358
CW
104
105 /**
6a488035 106 * Helper function for Check Signature in Editor.
1e1fdcf6
EM
107 * @param $fieldName
108 * @param $signature
109 * @param $editor
6a488035 110 */
00be9182 111 public function _checkSignature($fieldName, $signature, $editor) {
6a488035
TO
112 if ($editor == 'CKEditor') {
113 $this->waitForElementPresent("xpath=//div[@id='cke_{$fieldName}']//iframe");
114 $this->selectFrame("xpath=//div[@id='cke_{$fieldName}']//iframe");
115 }
116 else {
117 $this->selectFrame("xpath=//iframe[@id='{$fieldName}_ifr']");
118 }
119
1fd662d2 120 $this->assertElementContainsText("//html/body", "$signature");
6a488035
TO
121 $this->selectFrame('relative=top');
122 }
efb29358
CW
123
124 /**
6a488035 125 * Helper function for Check Signature in Activity.
1e1fdcf6
EM
126 * @param $subject
127 * @param $signature
6a488035 128 */
00be9182 129 public function _checkActivity($subject, $signature) {
6a488035
TO
130 $this->openCiviPage('activity/search', 'reset=1', '_qf_Search_refresh');
131
132 $this->type('activity_subject', $subject);
133
225a8648 134 $this->clickLink('_qf_Search_refresh', 'Search');
6a488035
TO
135
136 // View your Activity
44c45561 137 $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);
6a488035
TO
138
139 // Is signature correct? in Activity
efb29358 140 $this->assertTextPresent($signature);
6a488035 141 }
96025800 142
6a488035 143}