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() {
34 function testTemplateAdd($useTokens = FALSE, $msgTitle = NULL) {
35 $this->webtestLogin();
37 $this->openCiviPage("admin/messageTemplates/add", "action=add&reset=1");
39 // Fill message title.
41 $msgTitle = 'msg_' . substr(sha1(rand()), 0, 7);
43 $this->type("msg_title", $msgTitle);
46 $this->select2("msg_subject", "Display Name");
47 $this->select2("msg_subject", "Contact Type");
48 $this->select2("xpath=//*[contains(@data-field,'msg_text')]/../div/a", "Display Name", FALSE, TRUE);
49 $this->select2("xpath=//*[contains(@data-field,'msg_text')]/../div/a", "Contact Type", FALSE, TRUE);
50 $this->select2("xpath=//*[contains(@data-field,'html_message')]/../div/a", "Display Name", FALSE, TRUE);
51 $this->select2("xpath=//*[contains(@data-field,'html_message')]/../div/a", "Contact Type", FALSE, TRUE);
54 // Fill message subject.
55 $msgSubject = "This is subject for message";
56 $this->type("msg_subject", $msgSubject);
59 $txtMsg = "This is text message";
60 $this->type("msg_text", $txtMsg);
63 $htmlMsg = "This is HTML message";
64 $this->type("msg_html", $htmlMsg);
67 $this->click("_qf_MessageTemplates_next");
68 $this->waitForPageToLoad($this->getTimeoutMsec());
70 // Is status message correct
71 $this->waitForText('crm-notification-container', "The Message Template '$msgTitle' has been saved.");
74 $this->assertTrue($this->isElementPresent("xpath=id('user')/div[2]/div/table/tbody//tr/td[1][contains(text(), '$msgTitle')]"),
75 'Message Template Title not found!');
77 $this->assertTrue($this->isElementPresent("xpath=id('user')/div[2]/div/table/tbody//tr/td[2][contains(text(), '$msgSubject')]"),
78 'Message Subject not found!');
82 function testAddMailingWithMessageTemplate() {
83 // Call the above test to set up our environment
84 $msgTitle = 'msg_' . substr(sha1(rand()), 0, 7);
85 $this->testTemplateAdd(TRUE, $msgTitle);
87 // create new mailing group
88 $groupName = $this->WebtestAddGroup();
90 //Create new contact and add to mailing Group
91 $firstName = substr(sha1(rand()), 0, 7);
92 $this->webtestAddContact($firstName, "Mailson", "mailino$firstName@mailson.co.in");
93 $this->click("css=li#tab_group a");
94 $this->waitForElementPresent("_qf_GroupContact_next");
95 $this->select("group_id", "$groupName");
96 $this->click("_qf_GroupContact_next");
98 // configure default mail-box
99 $this->setupDefaultMailbox();
101 $this->openCiviPage("mailing/send", "reset=1", "_qf_Group_cancel");
104 $mailingName = substr(sha1(rand()), 0, 7);
105 $this->type("name", "Mailing $mailingName Webtest");
107 // Add the test mailing group
108 $this->select("includeGroups-f", "$groupName");
112 $this->click("_qf_Group_next");
113 $this->waitForElementPresent("_qf_Settings_cancel");
114 // check for default settings options
115 $this->assertChecked("url_tracking");
116 $this->assertChecked("open_tracking");
118 // do check count for Recipient
119 $this->assertElementContainsText('css=.messages', "Total Recipients: 1");
120 $this->click("_qf_Settings_next");
121 $this->waitForElementPresent("_qf_Upload_cancel");
123 $this->click("template");
124 $this->select("template", "label=$msgTitle");
125 // Because it tends to cause problems, all uses of sleep() must be justified in comments
126 // Sleep should never be used for wait for anything to load from the server
127 // Justification for this instance: FIXME
129 $this->click("xpath=id('Upload')/div[2]/fieldset[@id='compose_id']/div[2]/div[1]");
130 $this->click('subject');
132 // check for default header and footer ( with label )
133 $this->select('header_id', "label=Mailing Header");
134 $this->select('footer_id', "label=Mailing Footer");
136 // do check count for Recipient
137 $this->assertElementContainsText('css=.messages', "Total Recipients: 1");
139 // click next with nominal content
140 $this->click("_qf_Upload_upload");
141 $this->waitForElementPresent("_qf_Test_cancel");
143 $this->assertElementContainsText('css=.messages', "Total Recipients: 1");
146 $this->click("_qf_Test_next");
147 $this->waitForElementPresent("_qf_Schedule_cancel");
149 $this->assertChecked("now");
151 // do check count for Recipient
152 $this->assertElementContainsText('css=.messages', "Total Recipients: 1");
154 // finally schedule the mail by clicking submit
155 $this->click("_qf_Schedule_next");
156 $this->waitForPageToLoad($this->getTimeoutMsec());
158 //check redirected page to Scheduled and Sent Mailings and verify for mailing name
159 $this->assertElementContainsText('page-title', "Find Mailings");
160 $this->isTextPresent("Mailing $mailingName Webtest");
161 $this->openCiviPage('mailing/queue', 'reset=1');
164 $this->verifyText("xpath=id('Search')/table/tbody/tr[1]/td[2]", preg_quote("Complete"));
167 $this->openCiviPage('activity/search', "reset=1", "_qf_Search_refresh");
168 $this->type("sort_name", $firstName);
169 $this->click("activity_type_id[19]");
170 $this->click("_qf_Search_refresh");
171 $this->waitForElementPresent("_qf_Search_next_print");
173 $this->click("xpath=id('Search')/div[3]/div/div[2]/table/tbody/tr[2]/td[9]/span/a[text()='View']");
174 $this->waitForElementPresent("_qf_ActivityView_next");
175 $this->assertElementContainsText('help', "Bulk Email Sent.", "Status message didn't show up after saving!");