| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | CiviCRM version 4.6 | |
| 5 | +--------------------------------------------------------------------+ |
| 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
| 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_Mailing_AddMessageTemplateTest |
| 31 | */ |
| 32 | class WebTest_Mailing_AddMessageTemplateTest extends CiviSeleniumTestCase { |
| 33 | |
| 34 | protected function setUp() { |
| 35 | parent::setUp(); |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * @param bool $useTokens |
| 40 | * @param null $msgTitle |
| 41 | */ |
| 42 | public function testTemplateAdd($useTokens = FALSE, $msgTitle = NULL) { |
| 43 | $this->markTestSkipped('Skipping for now as it works fine locally.'); |
| 44 | $this->webtestLogin(); |
| 45 | |
| 46 | $this->openCiviPage("admin/messageTemplates/add", "action=add&reset=1"); |
| 47 | |
| 48 | // Fill message title. |
| 49 | if (!$msgTitle) { |
| 50 | $msgTitle = 'msg_' . substr(sha1(rand()), 0, 7); |
| 51 | } |
| 52 | $this->type("msg_title", $msgTitle); |
| 53 | if ($useTokens) { |
| 54 | //Add Tokens |
| 55 | $this->select2("msg_subject", "Display Name"); |
| 56 | $this->select2("msg_subject", "Contact Type"); |
| 57 | $this->select2("xpath=//*[contains(@data-field,'msg_text')]/../div/a", "Display Name", FALSE, TRUE); |
| 58 | $this->select2("xpath=//*[contains(@data-field,'msg_text')]/../div/a", "Contact Type", FALSE, TRUE); |
| 59 | $this->select2("xpath=//*[contains(@data-field,'html_message')]/../div/a", "Display Name", FALSE, TRUE); |
| 60 | $this->select2("xpath=//*[contains(@data-field,'html_message')]/../div/a", "Contact Type", FALSE, TRUE); |
| 61 | } |
| 62 | else { |
| 63 | // Fill message subject. |
| 64 | $msgSubject = "This is subject for message"; |
| 65 | $this->type("msg_subject", $msgSubject); |
| 66 | |
| 67 | // Fill text message. |
| 68 | $txtMsg = "This is text message"; |
| 69 | $this->type("msg_text", $txtMsg); |
| 70 | |
| 71 | // Fill html message. |
| 72 | $htmlMsg = "This is HTML message"; |
| 73 | $this->type("msg_html", $htmlMsg); |
| 74 | } |
| 75 | // Clicking save. |
| 76 | $this->click("_qf_MessageTemplates_next"); |
| 77 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 78 | |
| 79 | // Is status message correct |
| 80 | $this->waitForText('crm-notification-container', "The Message Template '$msgTitle' has been saved."); |
| 81 | |
| 82 | // Verify text. |
| 83 | $this->assertTrue($this->isElementPresent("xpath=id('user')/div[2]/div/table/tbody//tr/td[1][contains(text(), '$msgTitle')]"), |
| 84 | 'Message Template Title not found!'); |
| 85 | if (!$useTokens) { |
| 86 | $this->assertTrue($this->isElementPresent("xpath=id('user')/div[2]/div/table/tbody//tr/td[2][contains(text(), '$msgSubject')]"), |
| 87 | 'Message Subject not found!'); |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | public function testAddMailingWithMessageTemplate() { |
| 92 | $this->markTestSkipped('Skipping for now as it works fine locally.'); |
| 93 | // Call the above test to set up our environment |
| 94 | $msgTitle = 'msg_' . substr(sha1(rand()), 0, 7); |
| 95 | $this->testTemplateAdd(TRUE, $msgTitle); |
| 96 | |
| 97 | // create new mailing group |
| 98 | $groupName = $this->WebtestAddGroup(); |
| 99 | |
| 100 | //Create new contact and add to mailing Group |
| 101 | $firstName = substr(sha1(rand()), 0, 7); |
| 102 | $this->webtestAddContact($firstName, "Mailson", "mailino$firstName@mailson.co.in"); |
| 103 | $this->click("css=li#tab_group a"); |
| 104 | $this->waitForElementPresent("_qf_GroupContact_next"); |
| 105 | $this->select("group_id", "$groupName"); |
| 106 | $this->click("_qf_GroupContact_next"); |
| 107 | |
| 108 | // configure default mail-box |
| 109 | $this->setupDefaultMailbox(); |
| 110 | |
| 111 | $this->openCiviPage("a/#/mailing/new"); |
| 112 | $this->waitForElementPresent("xpath=//input[@name='mailingName']"); |
| 113 | |
| 114 | // fill mailing name |
| 115 | $mailingName = substr(sha1(rand()), 0, 7); |
| 116 | $this->type("xpath=//input[@name='mailingName']", "Mailing $mailingName Webtest"); |
| 117 | |
| 118 | // Add the test mailing group |
| 119 | $this->select2("s2id_crmUiId_8", $groupName, TRUE); |
| 120 | |
| 121 | // do check count for Recipient |
| 122 | $this->waitForTextPresent("~1 recipient"); |
| 123 | $this->click("msg_template_id"); |
| 124 | $this->select("msg_template_id", "label=$msgTitle"); |
| 125 | |
| 126 | $this->waitForAjaxContent(); |
| 127 | $this->select2('s2id_autogen1', "Unsubscribe via web page"); |
| 128 | $this->select2('s2id_autogen1', "Domain (organization) address"); |
| 129 | $this->waitForAjaxContent(); |
| 130 | $this->select2('s2id_autogen3', "Unsubscribe via web page"); |
| 131 | $this->select2('s2id_autogen3', "Domain (organization) address"); |
| 132 | $this->waitForAjaxContent(); |
| 133 | $this->click("xpath=//div[@class='preview-popup']//a[text()='Preview as Plain Text']"); |
| 134 | $this->click('subject'); |
| 135 | |
| 136 | // check for default settings options |
| 137 | $this->click("xpath=//ul/li/a[text()='Tracking']"); |
| 138 | $this->assertChecked("url_tracking"); |
| 139 | $this->assertChecked("open_tracking"); |
| 140 | |
| 141 | // check for default header and footer ( with label ) |
| 142 | $this->click("xpath=//ul/li/a[text()='Header and Footer']"); |
| 143 | $this->select('header_id', "label=Mailing Header"); |
| 144 | $this->select('footer_id', "label=Mailing Footer"); |
| 145 | |
| 146 | // click next |
| 147 | $this->click("xpath=//div[@class='crm-wizard-buttons']/button[text()='Next']"); |
| 148 | |
| 149 | $this->assertChecked("xpath=//input[@id='schedule-send-now']"); |
| 150 | $this->waitForTextPresent("Mailing $mailingName Webtest"); |
| 151 | $this->click("xpath=//div[@class='content']//a[text()='~1 recipient']"); |
| 152 | $this->webtestVerifyTabularData(array("$firstName Mailson" => "mailino$firstName@mailson.co.in")); |
| 153 | $this->click("xpath=//button[@title='Close']"); |
| 154 | $this->waitForTextPresent("(Include: $groupName)"); |
| 155 | |
| 156 | // finally schedule the mail by clicking submit |
| 157 | $this->click("xpath=//center/a/div[text()='Submit Mailing']"); |
| 158 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 159 | |
| 160 | //check redirected page to Scheduled and Sent Mailings and verify for mailing name |
| 161 | $this->waitForTextPresent("Find Mailings"); |
| 162 | $this->isTextPresent("Mailing $mailingName Webtest"); |
| 163 | $this->openCiviPage('mailing/queue', 'reset=1'); |
| 164 | |
| 165 | // verify status |
| 166 | $this->verifyText("xpath=id('Search')/table/tbody/tr[1]/td[2]", preg_quote("Complete")); |
| 167 | |
| 168 | //View Activity |
| 169 | $this->openCiviPage('activity/search', "reset=1", "_qf_Search_refresh"); |
| 170 | $this->type("sort_name", $firstName); |
| 171 | $this->select("activity_type_id", "label=Bulk Email"); |
| 172 | $this->click("_qf_Search_refresh"); |
| 173 | $this->waitForElementPresent("xpath=//form[@id='Search']/div[3]/div/div[2]/table[@class='selector row-highlight']/tbody/tr[2]/td[9]/span/a[1][text()='View']"); |
| 174 | $this->click("xpath=//form[@id='Search']/div[3]/div/div[2]/table[@class='selector row-highlight']/tbody/tr[2]/td[9]/span/a[1][text()='View']"); |
| 175 | $this->waitForElementPresent("xpath=//div[@class='ui-dialog-buttonset']/button/span[2]"); |
| 176 | $this->assertElementContainsText('help', "Bulk Email Sent.", "Status message didn't show up after saving!"); |
| 177 | } |
| 178 | |
| 179 | } |