3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
27 require_once 'CiviTest/CiviSeleniumTestCase.php';
28 class WebTest_Mailing_AddMessageTemplateTest
extends CiviSeleniumTestCase
{
30 protected function setUp() {
35 * @param bool $useTokens
36 * @param null $msgTitle
38 function testTemplateAdd($useTokens = FALSE, $msgTitle = NULL) {
39 $this->webtestLogin();
41 $this->openCiviPage("admin/messageTemplates/add", "action=add&reset=1");
43 // Fill message title.
45 $msgTitle = 'msg_' . substr(sha1(rand()), 0, 7);
47 $this->type("msg_title", $msgTitle);
50 $this->select2("msg_subject", "Display Name");
51 $this->select2("msg_subject", "Contact Type");
52 $this->select2("xpath=//*[contains(@data-field,'msg_text')]/../div/a", "Display Name", FALSE, TRUE);
53 $this->select2("xpath=//*[contains(@data-field,'msg_text')]/../div/a", "Contact Type", FALSE, TRUE);
54 $this->select2("xpath=//*[contains(@data-field,'html_message')]/../div/a", "Display Name", FALSE, TRUE);
55 $this->select2("xpath=//*[contains(@data-field,'html_message')]/../div/a", "Contact Type", FALSE, TRUE);
58 // Fill message subject.
59 $msgSubject = "This is subject for message";
60 $this->type("msg_subject", $msgSubject);
63 $txtMsg = "This is text message";
64 $this->type("msg_text", $txtMsg);
67 $htmlMsg = "This is HTML message";
68 $this->type("msg_html", $htmlMsg);
71 $this->click("_qf_MessageTemplates_next");
72 $this->waitForPageToLoad($this->getTimeoutMsec());
74 // Is status message correct
75 $this->waitForText('crm-notification-container', "The Message Template '$msgTitle' has been saved.");
78 $this->assertTrue($this->isElementPresent("xpath=id('user')/div[2]/div/table/tbody//tr/td[1][contains(text(), '$msgTitle')]"),
79 'Message Template Title not found!');
81 $this->assertTrue($this->isElementPresent("xpath=id('user')/div[2]/div/table/tbody//tr/td[2][contains(text(), '$msgSubject')]"),
82 'Message Subject not found!');
86 function testAddMailingWithMessageTemplate() {
87 // Call the above test to set up our environment
88 $msgTitle = 'msg_' . substr(sha1(rand()), 0, 7);
89 $this->testTemplateAdd(TRUE, $msgTitle);
91 // create new mailing group
92 $groupName = $this->WebtestAddGroup();
94 //Create new contact and add to mailing Group
95 $firstName = substr(sha1(rand()), 0, 7);
96 $this->webtestAddContact($firstName, "Mailson", "mailino$firstName@mailson.co.in");
97 $this->click("css=li#tab_group a");
98 $this->waitForElementPresent("_qf_GroupContact_next");
99 $this->select("group_id", "$groupName");
100 $this->click("_qf_GroupContact_next");
102 // configure default mail-box
103 $this->setupDefaultMailbox();
105 $this->openCiviPage("mailing/send", "reset=1", "_qf_Group_cancel");
108 $mailingName = substr(sha1(rand()), 0, 7);
109 $this->type("name", "Mailing $mailingName Webtest");
111 // Add the test mailing group
112 $this->select("includeGroups-f", "$groupName");
116 $this->click("_qf_Group_next");
117 $this->waitForElementPresent("_qf_Settings_cancel");
118 // check for default settings options
119 $this->assertChecked("url_tracking");
120 $this->assertChecked("open_tracking");
122 // do check count for Recipient
123 $this->assertElementContainsText('css=.messages', "Total Recipients: 1");
124 $this->click("_qf_Settings_next");
125 $this->waitForElementPresent("_qf_Upload_cancel");
127 $this->click("template");
128 $this->select("template", "label=$msgTitle");
129 // Because it tends to cause problems, all uses of sleep() must be justified in comments
130 // Sleep should never be used for wait for anything to load from the server
131 // Justification for this instance: FIXME
133 $this->click("xpath=id('Upload')/div[2]/fieldset[@id='compose_id']/div[2]/div[1]");
134 $this->click('subject');
136 // check for default header and footer ( with label )
137 $this->select('header_id', "label=Mailing Header");
138 $this->select('footer_id', "label=Mailing Footer");
140 // do check count for Recipient
141 $this->assertElementContainsText('css=.messages', "Total Recipients: 1");
143 // click next with nominal content
144 $this->click("_qf_Upload_upload");
145 $this->waitForElementPresent("_qf_Test_cancel");
147 $this->assertElementContainsText('css=.messages', "Total Recipients: 1");
150 $this->click("_qf_Test_next");
151 $this->waitForElementPresent("_qf_Schedule_cancel");
153 $this->assertChecked("now");
155 // do check count for Recipient
156 $this->assertElementContainsText('css=.messages', "Total Recipients: 1");
158 // finally schedule the mail by clicking submit
159 $this->click("_qf_Schedule_next");
160 $this->waitForPageToLoad($this->getTimeoutMsec());
162 //check redirected page to Scheduled and Sent Mailings and verify for mailing name
163 $this->assertElementContainsText('page-title', "Find Mailings");
164 $this->isTextPresent("Mailing $mailingName Webtest");
165 $this->openCiviPage('mailing/queue', 'reset=1');
168 $this->verifyText("xpath=id('Search')/table/tbody/tr[1]/td[2]", preg_quote("Complete"));
171 $this->openCiviPage('activity/search', "reset=1", "_qf_Search_refresh");
172 $this->type("sort_name", $firstName);
173 $this->click("activity_type_id[19]");
174 $this->click("_qf_Search_refresh");
175 $this->waitForElementPresent("_qf_Search_next_print");
177 $this->click("xpath=id('Search')/div[3]/div/div[2]/table/tbody/tr[2]/td[9]/span/a[text()='View']");
178 $this->waitForElementPresent("_qf_ActivityView_next");
179 $this->assertElementContainsText('help', "Bulk Email Sent.", "Status message didn't show up after saving!");