Merge pull request #87 from dlobo/CRM-12043
[civicrm-core.git] / tests / phpunit / WebTest / Mailing / AddMessageTemplateTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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
28 require_once 'CiviTest/CiviSeleniumTestCase.php';
29 class WebTest_Mailing_AddMessageTemplateTest extends CiviSeleniumTestCase {
30
31 protected function setUp() {
32 parent::setUp();
33 }
34
35 function testTemplateAdd($useTokens = FALSE, $msgTitle = NULL) {
36 $this->webtestLogin();
37
38 // Go directly to the URL of the screen that you will be testing (Add Message Template).
39 $this->openCiviPage("admin/messageTemplates/add", "action=add&reset=1");
40
41 // Fill message title.
42 if (!$msgTitle) {
43 $msgTitle = 'msg_' . substr(sha1(rand()), 0, 7);
44 }
45 $this->type("msg_title", $msgTitle);
46 if ($useTokens) {
47 //Add Tokens
48 $this->click("css=#msg_subject + a");
49 $this->waitForElementPresent("css=#tokenSubject + .ui-dialog-buttonpane button");
50 $this->type("filter3", "display");
51 $this->addSelection("token3", "label=Display Name");
52 $this->type("filter3", "contact");
53 $this->addSelection("token3", "label=Contact Type");
54 $this->click("css=#tokenSubject + .ui-dialog-buttonpane button");
55 $this->click("//span[@id='helptext']/a/label");
56 $this->waitForElementPresent("css=#tokenText + .ui-dialog-buttonpane button");
57 $this->type("filter1", "display");
58 $this->addSelection("token1", "label=Display Name");
59 $this->type("filter1", "contact");
60 $this->addSelection("token1", "label=Contact Type");
61 $this->click("css=#tokenText + .ui-dialog-buttonpane button");
62 $this->click("//span[@id='helphtml']/a/label");
63 $this->waitForElementPresent("css=#tokenHtml + .ui-dialog-buttonpane button");
64 $this->type("filter2", "display");
65 $this->addSelection("token2", "label=Display Name");
66 $this->type("filter2", "contact");
67 $this->addSelection("token2", "label=Contact Type");
68 $this->click("css=#tokenHtml + .ui-dialog-buttonpane button");
69 }
70 else {
71 // Fill message subject.
72 $msgSubject = "This is subject for message";
73 $this->type("msg_subject", $msgSubject);
74
75 // Fill text message.
76 $txtMsg = "This is text message";
77 $this->type("msg_text", $txtMsg);
78
79 // Fill html message.
80 $htmlMsg = "This is HTML message";
81 $this->type("msg_html", $htmlMsg);
82 }
83 // Clicking save.
84 $this->click("_qf_MessageTemplates_next");
85 $this->waitForPageToLoad($this->getTimeoutMsec());
86
87 // Is status message correct
88 $this->assertElementContainsText('crm-notification-container', "The Message Template '$msgTitle' has been saved.");
89
90 // Verify text.
91 $this->assertTrue($this->isElementPresent("xpath=id('user')/div[2]/div/table/tbody//tr/td[1][contains(text(), '$msgTitle')]"),
92 'Message Template Title not found!');
93 if (!$useTokens) {
94 $this->assertTrue($this->isElementPresent("xpath=id('user')/div[2]/div/table/tbody//tr/td[2][contains(text(), '$msgSubject')]"),
95 'Message Subject not found!');
96 }
97 }
98
99 function testAddMailingWithMessageTemplate() {
100 // Call the above test to set up our environment
101 $msgTitle = 'msg_' . substr(sha1(rand()), 0, 7);
102 $this->testTemplateAdd(TRUE, $msgTitle);
103
104 // create new mailing group
105 $groupName = $this->WebtestAddGroup();
106
107 //Create new contact and add to mailing Group
108 $firstName = substr(sha1(rand()), 0, 7);
109 $this->webtestAddContact($firstName, "Mailson", "mailino$firstName@mailson.co.in");
110 $this->click("css=li#tab_group a");
111 $this->waitForElementPresent("_qf_GroupContact_next");
112 $this->select("group_id", "$groupName");
113 $this->click("_qf_GroupContact_next");
114
115 // configure default mail-box
116 $this->openCiviPage("admin/mailSettings", "action=update&id=1&reset=1", '_qf_MailSettings_cancel-bottom');
117 $this->type('name', 'Test Domain');
118 $this->type('domain', 'example.com');
119 $this->select('protocol', 'value=1');
120 $this->click('_qf_MailSettings_next-bottom');
121 $this->waitForPageToLoad($this->getTimeoutMsec());
122
123 // Go directly to Schedule and Send Mailing form
124 $this->openCiviPage("mailing/send", "reset=1", "_qf_Group_cancel");
125
126 // fill mailing name
127 $mailingName = substr(sha1(rand()), 0, 7);
128 $this->type("name", "Mailing $mailingName Webtest");
129
130 // Add the test mailing group
131 $this->select("includeGroups-f", "$groupName");
132 $this->click("add");
133
134 // click next
135 $this->click("_qf_Group_next");
136 $this->waitForElementPresent("_qf_Settings_cancel");
137 // check for default settings options
138 $this->assertChecked("url_tracking");
139 $this->assertChecked("open_tracking");
140
141 // do check count for Recipient
142 $this->assertElementContainsText('css=.messages', "Total Recipients: 1");
143 $this->click("_qf_Settings_next");
144 $this->waitForElementPresent("_qf_Upload_cancel");
145
146 $this->click("template");
147 $this->select("template", "label=$msgTitle");
148 sleep(5);
149 $this->click("xpath=id('Upload')/div[2]/fieldset[@id='compose_id']/div[2]/div[1]");
150 $this->click('subject');
151
152 // check for default header and footer ( with label )
153 $this->select('header_id', "label=Mailing Header");
154 $this->select('footer_id', "label=Mailing Footer");
155
156 // do check count for Recipient
157 $this->assertElementContainsText('css=.messages', "Total Recipients: 1");
158
159 // click next with nominal content
160 $this->click("_qf_Upload_upload");
161 $this->waitForElementPresent("_qf_Test_cancel");
162
163 $this->assertElementContainsText('css=.messages', "Total Recipients: 1");
164
165 // click next
166 $this->click("_qf_Test_next");
167 $this->waitForElementPresent("_qf_Schedule_cancel");
168
169 $this->assertChecked("now");
170
171 // do check count for Recipient
172 $this->assertElementContainsText('css=.messages', "Total Recipients: 1");
173
174 // finally schedule the mail by clicking submit
175 $this->click("_qf_Schedule_next");
176 $this->waitForPageToLoad($this->getTimeoutMsec());
177
178 //check redirected page to Scheduled and Sent Mailings and verify for mailing name
179 $this->assertElementContainsText('page-title', "Scheduled and Sent Mailings");
180 $this->assertElementContainsText("xpath=//table[@class='selector']/tbody//tr//td", "Mailing $mailingName Webtest");
181 $this->openCiviPage('mailing/queue', 'reset=1');
182
183 // verify status
184 $this->verifyText("xpath=id('Search')/table/tbody/tr[1]/td[2]", preg_quote("Complete"));
185
186 //View Activity
187 $this->openCiviPage('activity/search', "reset=1", "_qf_Search_refresh");
188 $this->type("sort_name", $firstName);
189 $this->click("activity_type_id[19]");
190 $this->click("_qf_Search_refresh");
191 $this->waitForElementPresent("_qf_Search_next_print");
192
193 $this->click("xpath=id('Search')/div[3]/div/div[2]/table/tbody/tr[2]/td[9]/span/a[text()='View']");
194 $this->waitForElementPresent("_qf_ActivityView_next");
195 $this->assertElementContainsText('help', "Bulk Email Sent.", "Status message didn't show up after saving!");
196 }
197 }