INFRA-132 - FunctionDeclarationArgumentSpacing.SpaceBeforeEquals
[civicrm-core.git] / tests / phpunit / WebTest / Mailing / AddMessageTemplateTest.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
39de6fd5 4 | CiviCRM version 4.6 |
6a488035 5 +--------------------------------------------------------------------+
06a1bc01 6 | Copyright CiviCRM LLC (c) 2004-2014 |
6a488035
TO
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
6a488035 27require_once 'CiviTest/CiviSeleniumTestCase.php';
e9479dcf
EM
28
29/**
30 * Class WebTest_Mailing_AddMessageTemplateTest
31 */
6a488035
TO
32class WebTest_Mailing_AddMessageTemplateTest extends CiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
4cbe18b8
EM
38 /**
39 * @param bool $useTokens
40 * @param null $msgTitle
41 */
00be9182 42 public function testTemplateAdd($useTokens = FALSE, $msgTitle = NULL) {
6a488035
TO
43 $this->webtestLogin();
44
6a488035
TO
45 $this->openCiviPage("admin/messageTemplates/add", "action=add&reset=1");
46
47 // Fill message title.
48 if (!$msgTitle) {
49 $msgTitle = 'msg_' . substr(sha1(rand()), 0, 7);
50 }
51 $this->type("msg_title", $msgTitle);
52 if ($useTokens) {
53 //Add Tokens
b4742465 54 $this->select2("msg_subject", "Display Name");
55 $this->select2("msg_subject", "Contact Type");
56 $this->select2("xpath=//*[contains(@data-field,'msg_text')]/../div/a", "Display Name", FALSE, TRUE);
57 $this->select2("xpath=//*[contains(@data-field,'msg_text')]/../div/a", "Contact Type", FALSE, TRUE);
58 $this->select2("xpath=//*[contains(@data-field,'html_message')]/../div/a", "Display Name", FALSE, TRUE);
59 $this->select2("xpath=//*[contains(@data-field,'html_message')]/../div/a", "Contact Type", FALSE, TRUE);
6a488035
TO
60 }
61 else {
62 // Fill message subject.
63 $msgSubject = "This is subject for message";
64 $this->type("msg_subject", $msgSubject);
65
66 // Fill text message.
67 $txtMsg = "This is text message";
68 $this->type("msg_text", $txtMsg);
69
70 // Fill html message.
71 $htmlMsg = "This is HTML message";
72 $this->type("msg_html", $htmlMsg);
73 }
74 // Clicking save.
75 $this->click("_qf_MessageTemplates_next");
76 $this->waitForPageToLoad($this->getTimeoutMsec());
77
78 // Is status message correct
6c5f7368 79 $this->waitForText('crm-notification-container', "The Message Template '$msgTitle' has been saved.");
6a488035
TO
80
81 // Verify text.
3fb9aed9
PJ
82 $this->assertTrue($this->isElementPresent("xpath=id('user')/div[2]/div/table/tbody//tr/td[1][contains(text(), '$msgTitle')]"),
83 'Message Template Title not found!');
6a488035 84 if (!$useTokens) {
3fb9aed9
PJ
85 $this->assertTrue($this->isElementPresent("xpath=id('user')/div[2]/div/table/tbody//tr/td[2][contains(text(), '$msgSubject')]"),
86 'Message Subject not found!');
6a488035
TO
87 }
88 }
89
00be9182 90 public function testAddMailingWithMessageTemplate() {
6a488035
TO
91 // Call the above test to set up our environment
92 $msgTitle = 'msg_' . substr(sha1(rand()), 0, 7);
93 $this->testTemplateAdd(TRUE, $msgTitle);
94
95 // create new mailing group
96 $groupName = $this->WebtestAddGroup();
97
98 //Create new contact and add to mailing Group
99 $firstName = substr(sha1(rand()), 0, 7);
100 $this->webtestAddContact($firstName, "Mailson", "mailino$firstName@mailson.co.in");
101 $this->click("css=li#tab_group a");
102 $this->waitForElementPresent("_qf_GroupContact_next");
103 $this->select("group_id", "$groupName");
104 $this->click("_qf_GroupContact_next");
105
106 // configure default mail-box
5ff68892 107 $this->setupDefaultMailbox();
6a488035 108
6a488035
TO
109 $this->openCiviPage("mailing/send", "reset=1", "_qf_Group_cancel");
110
111 // fill mailing name
112 $mailingName = substr(sha1(rand()), 0, 7);
113 $this->type("name", "Mailing $mailingName Webtest");
114
115 // Add the test mailing group
74210507 116 $this->select("includeGroups", "$groupName");
6a488035
TO
117
118 // click next
119 $this->click("_qf_Group_next");
120 $this->waitForElementPresent("_qf_Settings_cancel");
121 // check for default settings options
122 $this->assertChecked("url_tracking");
123 $this->assertChecked("open_tracking");
124
125 // do check count for Recipient
3fb9aed9 126 $this->assertElementContainsText('css=.messages', "Total Recipients: 1");
6a488035
TO
127 $this->click("_qf_Settings_next");
128 $this->waitForElementPresent("_qf_Upload_cancel");
129
130 $this->click("template");
131 $this->select("template", "label=$msgTitle");
efb29358
CW
132 // Because it tends to cause problems, all uses of sleep() must be justified in comments
133 // Sleep should never be used for wait for anything to load from the server
134 // Justification for this instance: FIXME
6a488035
TO
135 sleep(5);
136 $this->click("xpath=id('Upload')/div[2]/fieldset[@id='compose_id']/div[2]/div[1]");
137 $this->click('subject');
138
139 // check for default header and footer ( with label )
140 $this->select('header_id', "label=Mailing Header");
141 $this->select('footer_id', "label=Mailing Footer");
142
143 // do check count for Recipient
3fb9aed9 144 $this->assertElementContainsText('css=.messages', "Total Recipients: 1");
6a488035
TO
145
146 // click next with nominal content
147 $this->click("_qf_Upload_upload");
148 $this->waitForElementPresent("_qf_Test_cancel");
149
3fb9aed9 150 $this->assertElementContainsText('css=.messages', "Total Recipients: 1");
6a488035
TO
151
152 // click next
153 $this->click("_qf_Test_next");
154 $this->waitForElementPresent("_qf_Schedule_cancel");
155
156 $this->assertChecked("now");
157
158 // do check count for Recipient
3fb9aed9 159 $this->assertElementContainsText('css=.messages', "Total Recipients: 1");
6a488035
TO
160
161 // finally schedule the mail by clicking submit
162 $this->click("_qf_Schedule_next");
163 $this->waitForPageToLoad($this->getTimeoutMsec());
164
165 //check redirected page to Scheduled and Sent Mailings and verify for mailing name
b4742465 166 $this->assertElementContainsText('page-title', "Find Mailings");
167 $this->isTextPresent("Mailing $mailingName Webtest");
6a488035
TO
168 $this->openCiviPage('mailing/queue', 'reset=1');
169
170 // verify status
171 $this->verifyText("xpath=id('Search')/table/tbody/tr[1]/td[2]", preg_quote("Complete"));
172
173 //View Activity
174 $this->openCiviPage('activity/search', "reset=1", "_qf_Search_refresh");
175 $this->type("sort_name", $firstName);
176 $this->click("activity_type_id[19]");
177 $this->click("_qf_Search_refresh");
74210507
RK
178 $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']");
179 $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']");
180 $this->waitForElementPresent("xpath=//div[@class='ui-dialog-buttonset']/button/span[2]");
3fb9aed9 181 $this->assertElementContainsText('help', "Bulk Email Sent.", "Status message didn't show up after saving!");
6a488035 182 }
42daf119 183}