Merge pull request #2845 from elcapo/activity-contact-api
[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->click("css=#msg_subject + a");
47 $this->waitForElementPresent("css=#tokenSubject + .ui-dialog-buttonpane button");
48 $this->type("filter3", "display");
49 $this->addSelection("token3", "label=Display Name");
50 $this->type("filter3", "contact");
51 $this->addSelection("token3", "label=Contact Type");
52 $this->click("css=#tokenSubject + .ui-dialog-buttonpane button");
53 $this->click("//span[@id='helptext']/a/label");
54 $this->waitForElementPresent("css=#tokenText + .ui-dialog-buttonpane button");
55 $this->type("filter1", "display");
56 $this->addSelection("token1", "label=Display Name");
57 $this->type("filter1", "contact");
58 $this->addSelection("token1", "label=Contact Type");
59 $this->click("css=#tokenText + .ui-dialog-buttonpane button");
60 $this->click("//span[@id='helphtml']/a/label");
61 $this->waitForElementPresent("css=#tokenHtml + .ui-dialog-buttonpane button");
62 $this->type("filter2", "display");
63 $this->addSelection("token2", "label=Display Name");
64 $this->type("filter2", "contact");
65 $this->addSelection("token2", "label=Contact Type");
66 $this->click("css=#tokenHtml + .ui-dialog-buttonpane button");
67 }
68 else {
69 // Fill message subject.
70 $msgSubject = "This is subject for message";
71 $this->type("msg_subject", $msgSubject);
72
73 // Fill text message.
74 $txtMsg = "This is text message";
75 $this->type("msg_text", $txtMsg);
76
77 // Fill html message.
78 $htmlMsg = "This is HTML message";
79 $this->type("msg_html", $htmlMsg);
80 }
81 // Clicking save.
82 $this->click("_qf_MessageTemplates_next");
83 $this->waitForPageToLoad($this->getTimeoutMsec());
84
85 // Is status message correct
86 $this->waitForText('crm-notification-container', "The Message Template '$msgTitle' has been saved.");
87
88 // Verify text.
89 $this->assertTrue($this->isElementPresent("xpath=id('user')/div[2]/div/table/tbody//tr/td[1][contains(text(), '$msgTitle')]"),
90 'Message Template Title not found!');
91 if (!$useTokens) {
92 $this->assertTrue($this->isElementPresent("xpath=id('user')/div[2]/div/table/tbody//tr/td[2][contains(text(), '$msgSubject')]"),
93 'Message Subject not found!');
94 }
95 }
96
97 function testAddMailingWithMessageTemplate() {
98 // Call the above test to set up our environment
99 $msgTitle = 'msg_' . substr(sha1(rand()), 0, 7);
100 $this->testTemplateAdd(TRUE, $msgTitle);
101
102 // create new mailing group
103 $groupName = $this->WebtestAddGroup();
104
105 //Create new contact and add to mailing Group
106 $firstName = substr(sha1(rand()), 0, 7);
107 $this->webtestAddContact($firstName, "Mailson", "mailino$firstName@mailson.co.in");
108 $this->click("css=li#tab_group a");
109 $this->waitForElementPresent("_qf_GroupContact_next");
110 $this->select("group_id", "$groupName");
111 $this->click("_qf_GroupContact_next");
112
113 // configure default mail-box
114 $this->setupDefaultMailbox();
115
116 $this->openCiviPage("mailing/send", "reset=1", "_qf_Group_cancel");
117
118 // fill mailing name
119 $mailingName = substr(sha1(rand()), 0, 7);
120 $this->type("name", "Mailing $mailingName Webtest");
121
122 // Add the test mailing group
123 $this->select("includeGroups-f", "$groupName");
124 $this->click("add");
125
126 // click next
127 $this->click("_qf_Group_next");
128 $this->waitForElementPresent("_qf_Settings_cancel");
129 // check for default settings options
130 $this->assertChecked("url_tracking");
131 $this->assertChecked("open_tracking");
132
133 // do check count for Recipient
134 $this->assertElementContainsText('css=.messages', "Total Recipients: 1");
135 $this->click("_qf_Settings_next");
136 $this->waitForElementPresent("_qf_Upload_cancel");
137
138 $this->click("template");
139 $this->select("template", "label=$msgTitle");
140 // Because it tends to cause problems, all uses of sleep() must be justified in comments
141 // Sleep should never be used for wait for anything to load from the server
142 // Justification for this instance: FIXME
143 sleep(5);
144 $this->click("xpath=id('Upload')/div[2]/fieldset[@id='compose_id']/div[2]/div[1]");
145 $this->click('subject');
146
147 // check for default header and footer ( with label )
148 $this->select('header_id', "label=Mailing Header");
149 $this->select('footer_id', "label=Mailing Footer");
150
151 // do check count for Recipient
152 $this->assertElementContainsText('css=.messages', "Total Recipients: 1");
153
154 // click next with nominal content
155 $this->click("_qf_Upload_upload");
156 $this->waitForElementPresent("_qf_Test_cancel");
157
158 $this->assertElementContainsText('css=.messages', "Total Recipients: 1");
159
160 // click next
161 $this->click("_qf_Test_next");
162 $this->waitForElementPresent("_qf_Schedule_cancel");
163
164 $this->assertChecked("now");
165
166 // do check count for Recipient
167 $this->assertElementContainsText('css=.messages', "Total Recipients: 1");
168
169 // finally schedule the mail by clicking submit
170 $this->click("_qf_Schedule_next");
171 $this->waitForPageToLoad($this->getTimeoutMsec());
172
173 //check redirected page to Scheduled and Sent Mailings and verify for mailing name
174 $this->assertElementContainsText('page-title', "Scheduled and Sent Mailings");
175 $this->assertElementContainsText("xpath=//table[@class='selector']/tbody//tr//td", "Mailing $mailingName Webtest");
176 $this->openCiviPage('mailing/queue', 'reset=1');
177
178 // verify status
179 $this->verifyText("xpath=id('Search')/table/tbody/tr[1]/td[2]", preg_quote("Complete"));
180
181 //View Activity
182 $this->openCiviPage('activity/search', "reset=1", "_qf_Search_refresh");
183 $this->type("sort_name", $firstName);
184 $this->click("activity_type_id[19]");
185 $this->click("_qf_Search_refresh");
186 $this->waitForElementPresent("_qf_Search_next_print");
187
188 $this->click("xpath=id('Search')/div[3]/div/div[2]/table/tbody/tr[2]/td[9]/span/a[text()='View']");
189 $this->waitForElementPresent("_qf_ActivityView_next");
190 $this->assertElementContainsText('help', "Bulk Email Sent.", "Status message didn't show up after saving!");
191 }
192 }