| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | CiviCRM version 4.7 | |
| 5 | +--------------------------------------------------------------------+ |
| 6 | | Copyright CiviCRM LLC (c) 2004-2016 | |
| 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 CKEditor. |
| 40 | */ |
| 41 | public function testCKEditor() { |
| 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('CKEditor'); |
| 54 | |
| 55 | $this->openCiviPage("contact/add", "reset=1&action=update&cid={$contactId}"); |
| 56 | $this->click("//tr[@id='Email_Block_1']/td[1]/div[3]/div[1]"); |
| 57 | |
| 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? |
| 69 | $this->waitForText('crm-notification-container', "{$name} has been updated."); |
| 70 | |
| 71 | // Go for Ckeck Your Editor, Click on Send Mail |
| 72 | $this->click("//a[@id='crm-contact-actions-link']/span"); |
| 73 | $this->clickLink('link=Send an Email', 'subject', FALSE); |
| 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'); |
| 83 | $this->waitForElementPresent("//a[@id='crm-contact-actions-link']/span"); |
| 84 | |
| 85 | // Go for Activity Search |
| 86 | $this->_checkActivity($subject, $signature); |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * Helper function to select Editor. |
| 91 | * @param $editor |
| 92 | */ |
| 93 | public function _selectEditor($editor) { |
| 94 | $this->openCiviPage('admin/setting/preferences/display', 'reset=1'); |
| 95 | |
| 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 | } |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * Helper function for Check Signature in Editor. |
| 107 | * @param $fieldName |
| 108 | * @param $signature |
| 109 | * @param $editor |
| 110 | */ |
| 111 | public function _checkSignature($fieldName, $signature, $editor) { |
| 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 | |
| 120 | $this->verifyText('//html/body', preg_quote("{$signature}")); |
| 121 | $this->selectFrame('relative=top'); |
| 122 | } |
| 123 | |
| 124 | /** |
| 125 | * Helper function for Check Signature in Activity. |
| 126 | * @param $subject |
| 127 | * @param $signature |
| 128 | */ |
| 129 | public function _checkActivity($subject, $signature) { |
| 130 | $this->openCiviPage('activity/search', 'reset=1', '_qf_Search_refresh'); |
| 131 | |
| 132 | $this->type('activity_subject', $subject); |
| 133 | |
| 134 | $this->clickLink('_qf_Search_refresh', 'Search'); |
| 135 | |
| 136 | // View your Activity |
| 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); |
| 138 | |
| 139 | // Is signature correct? in Activity |
| 140 | $this->assertTextPresent($signature); |
| 141 | } |
| 142 | |
| 143 | } |