Merge pull request #3114 from Edzelopez/CRM-14621
[civicrm-core.git] / tests / phpunit / WebTest / Mailing / AddMessageTemplateTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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 class WebTest_Mailing_AddMessageTemplateTest extends CiviSeleniumTestCase {
29
30 protected function setUp() {
31 parent::setUp();
32 }
33
34 function testTemplateAdd($useTokens = FALSE, $msgTitle = NULL) {
35 $this->webtestLogin();
36
37 $this->openCiviPage("admin/messageTemplates/add", "action=add&reset=1");
38
39 // Fill message title.
40 if (!$msgTitle) {
41 $msgTitle = 'msg_' . substr(sha1(rand()), 0, 7);
42 }
43 $this->type("msg_title", $msgTitle);
44 if ($useTokens) {
45 //Add Tokens
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);
52 }
53 else {
54 // Fill message subject.
55 $msgSubject = "This is subject for message";
56 $this->type("msg_subject", $msgSubject);
57
58 // Fill text message.
59 $txtMsg = "This is text message";
60 $this->type("msg_text", $txtMsg);
61
62 // Fill html message.
63 $htmlMsg = "This is HTML message";
64 $this->type("msg_html", $htmlMsg);
65 }
66 // Clicking save.
67 $this->click("_qf_MessageTemplates_next");
68 $this->waitForPageToLoad($this->getTimeoutMsec());
69
70 // Is status message correct
71 $this->waitForText('crm-notification-container', "The Message Template '$msgTitle' has been saved.");
72
73 // Verify text.
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!');
76 if (!$useTokens) {
77 $this->assertTrue($this->isElementPresent("xpath=id('user')/div[2]/div/table/tbody//tr/td[2][contains(text(), '$msgSubject')]"),
78 'Message Subject not found!');
79 }
80 }
81
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);
86
87 // create new mailing group
88 $groupName = $this->WebtestAddGroup();
89
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");
97
98 // configure default mail-box
99 $this->setupDefaultMailbox();
100
101 $this->openCiviPage("mailing/send", "reset=1", "_qf_Group_cancel");
102
103 // fill mailing name
104 $mailingName = substr(sha1(rand()), 0, 7);
105 $this->type("name", "Mailing $mailingName Webtest");
106
107 // Add the test mailing group
108 $this->select("includeGroups-f", "$groupName");
109 $this->click("add");
110
111 // click next
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");
117
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");
122
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
128 sleep(5);
129 $this->click("xpath=id('Upload')/div[2]/fieldset[@id='compose_id']/div[2]/div[1]");
130 $this->click('subject');
131
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");
135
136 // do check count for Recipient
137 $this->assertElementContainsText('css=.messages', "Total Recipients: 1");
138
139 // click next with nominal content
140 $this->click("_qf_Upload_upload");
141 $this->waitForElementPresent("_qf_Test_cancel");
142
143 $this->assertElementContainsText('css=.messages', "Total Recipients: 1");
144
145 // click next
146 $this->click("_qf_Test_next");
147 $this->waitForElementPresent("_qf_Schedule_cancel");
148
149 $this->assertChecked("now");
150
151 // do check count for Recipient
152 $this->assertElementContainsText('css=.messages', "Total Recipients: 1");
153
154 // finally schedule the mail by clicking submit
155 $this->click("_qf_Schedule_next");
156 $this->waitForPageToLoad($this->getTimeoutMsec());
157
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');
162
163 // verify status
164 $this->verifyText("xpath=id('Search')/table/tbody/tr[1]/td[2]", preg_quote("Complete"));
165
166 //View Activity
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");
172
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!");
176 }
177 }