Merge pull request #3344 from eileenmcnaughton/comments
[civicrm-core.git] / tests / phpunit / WebTest / Campaign / MailingTest.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_Campaign_MailingTest extends CiviSeleniumTestCase {
29
30 protected function setUp() {
31 parent::setUp();
32 }
33
34 function testCreateCampaign() {
35 // Log in as admin first to verify permissions for CiviCampaign
36 $this->webtestLogin('admin');
37
38 // Enable CiviCampaign module if necessary
39 $this->enableComponents(array('CiviMail', 'CiviCampaign'));
40
41 $this->setupDefaultMailbox();
42
43 // add the required permission
44 $this->changePermissions('edit-2-administer-civicampaign');
45
46 // Log in as normal user
47 $this->webtestLogin();
48
49 // Create new group
50 $title = substr(sha1(rand()), 0, 7);
51 $groupName = $this->WebtestAddGroup();
52
53 // Adding contact
54 // We're using Quick Add block on the main page for this.
55 $firstName = substr(sha1(rand()), 0, 7);
56 $this->webtestAddContact($firstName, "Smith", "$firstName.smith@example.org");
57
58 // add contact to group
59 // visit group tab
60 $this->click("css=li#tab_group a");
61 $this->waitForElementPresent("group_id");
62
63 // add to group
64 $this->select("group_id", "label=$groupName");
65 $this->click("_qf_GroupContact_next");
66 $this->waitForElementPresent('link=Remove');
67
68 $this->openCiviPage('campaign/add', 'reset=1', '_qf_Campaign_upload-bottom');
69
70 $campaignTitle = "Campaign $title";
71 $this->type("title", $campaignTitle);
72
73 // select the campaign type
74 $this->select("campaign_type_id", "value=2");
75
76 // fill in the description
77 $this->type("description", "This is a test campaign");
78
79 // include groups for the campaign
80 $this->addSelection("includeGroups-f", "label=$groupName");
81 $this->click("//option[@value=4]");
82 $this->click("add");
83
84 // fill the end date for campaign
85 $this->webtestFillDate("end_date", "+1 year");
86
87 // select campaign status
88 $this->select("status_id", "value=2");
89
90 // click save
91 $this->click("_qf_Campaign_upload-bottom");
92 $this->waitForPageToLoad($this->getTimeoutMsec());
93
94 $this->waitForText('crm-notification-container', "Campaign $title");
95
96 $this->waitForElementPresent("//div[@id='campaignList']/div[@id='campaigns_wrapper']/table/tbody/tr/td[text()='{$campaignTitle}']/../td[1]");
97 $id = (int) $this->getText("//div[@id='campaignList']/div[@id='campaigns_wrapper']/table/tbody/tr/td[text()='{$campaignTitle}']/../td[1]");
98 $this->mailingAddTest($groupName, $campaignTitle, $id);
99 }
100
101 /**
102 * @param $groupName
103 * @param $campaignTitle
104 * @param $id
105 */
106 function mailingAddTest($groupName, $campaignTitle, $id) {
107 //---- create mailing contact and add to mailing Group
108 $firstName = substr(sha1(rand()), 0, 7);
109 $this->webtestAddContact($firstName, "Mailson", "mailino$firstName@mailson.co.in");
110
111 // go to group tab and add to mailing group
112 $this->click("css=li#tab_group a");
113 $this->waitForElementPresent("_qf_GroupContact_next");
114 $this->select("group_id", "$groupName");
115 $this->click("_qf_GroupContact_next");
116
117 $this->openCiviPage('mailing/send', 'reset=1', '_qf_Group_cancel');
118
119 //-------select recipients----------
120
121 // fill mailing name
122 $mailingName = substr(sha1(rand()), 0, 7);
123 $this->type("name", "Mailing $mailingName Webtest");
124
125 // select campaign
126 $this->click("campaign_id");
127 $this->select("campaign_id", "value=$id");
128
129 // Add the test mailing group
130 $this->select("includeGroups-f", "$groupName");
131 $this->click("add");
132
133 // click next
134 $this->click("_qf_Group_next");
135 $this->waitForElementPresent("_qf_Settings_cancel");
136
137 //--------track and respond----------
138
139 // check for default settings options
140 $this->assertChecked("url_tracking");
141 $this->assertChecked("open_tracking");
142
143 // do check count for Recipient
144 $this->assertElementContainsText('crm-container', "Total Recipients: 2");
145
146 // no need tracking for this test
147
148 // click next with default settings
149 $this->click("_qf_Settings_next");
150 $this->waitForElementPresent("_qf_Upload_cancel");
151
152 //--------Mailing content------------
153 // let from email address be default
154
155 // fill subject for mailing
156 $this->type("subject", "Test subject $mailingName for Webtest");
157
158 // check for default option enabled
159 $this->assertChecked("CIVICRM_QFID_1_upload_type");
160
161 // fill message (presently using script for simple text area)
162 $this->click("//fieldset[@id='compose_id']/div[2]/div[1]");
163 $this->type("text_message", "this is test content for Mailing $mailingName Webtest");
164
165 // add attachment?
166
167 // default header and footer ( with label )
168 $this->select("header_id", "label=Mailing Header");
169 $this->select("footer_id", "label=Mailing Footer");
170
171 // do check count for Recipient
172 $this->assertElementContainsText('crm-container', "Total Recipients: 2");
173
174 // click next with nominal content
175 $this->click("_qf_Upload_upload");
176 $this->waitForElementPresent("_qf_Test_cancel");
177
178 //---------------Test------------------
179
180 ////////--Commenting test mailing and mailing preview (test mailing and preview not presently working).
181
182 // send test mailing
183 //$this->type("test_email", "mailino@mailson.co.in");
184 //$this->click("sendtest");
185
186 // verify status message
187 //$this->assertTrue($this->isTextPresent("Your test message has been sent. Click 'Next' when you are ready to Schedule or Send your live mailing (you will still have a chance to confirm or cancel sending this mailing on the next page)."));
188
189 // check mailing preview
190 //$this->click("//form[@id='Test']/div[2]/div[4]/div[1]");
191 //$this->assertTrue($this->isTextPresent("this is test content for Mailing $mailingName Webtest"));
192
193 ////////
194
195 // do check count for Recipient
196 $this->assertElementContainsText('crm-container', "Total Recipients: 2");
197
198 // click next
199 $this->click("_qf_Test_next");
200 $this->waitForElementPresent("_qf_Schedule_cancel");
201
202 //----------Schedule or Send------------
203
204 // do check for default option enabled
205 $this->assertChecked("now");
206
207 // do check count for Recipient
208 $this->assertElementContainsText('crm-container', "Total Recipients: 2");
209
210 // finally schedule the mail by clicking submit
211 $this->click("_qf_Schedule_next");
212 $this->waitForPageToLoad($this->getTimeoutMsec());
213
214 //----------end New Mailing-------------
215
216 //check redirected page to Scheduled and Sent Mailings and verify for mailing name
217 $this->assertElementContainsText('page-title', "Find Mailings");
218 $this->assertElementContainsText('Search', "Mailing $mailingName Webtest");
219
220 //--------- mail delivery verification---------
221
222 // test undelivered report
223
224 // click report link of created mailing
225 $this->click("xpath=//table//tbody/tr[td[1]/text()='Mailing $mailingName Webtest']/descendant::a[text()='Report']");
226 $this->waitForPageToLoad($this->getTimeoutMsec());
227
228 // verify undelivered status message
229 $this->assertElementContainsText('crm-container',"Delivery has not yet begun for this mailing. If the scheduled delivery date and time is past, ask the system administrator or technical support contact for your site to verify that the automated mailer task ('cron job') is running - and how frequently.");
230
231 // do check for recipient group
232 $this->assertElementContainsText('crm-container', "Members of $groupName");
233
234 // directly send schedule mailing -- not working right now
235 $this->openCiviPage('mailing/queue', 'reset=1');
236
237 //click report link of created mailing
238 $this->click("xpath=//table//tbody/tr[td[1]/text()='Mailing $mailingName Webtest']/descendant::a[text()='Report']");
239 $this->waitForPageToLoad($this->getTimeoutMsec());
240
241 // do check again for recipient group
242 $this->assertElementContainsText('crm-container', "Members of $groupName");
243
244 // check for 100% delivery
245 $this->assertElementContainsText('crm-container', "2 (100.00%)");
246
247 // verify intended recipients
248 $this->verifyText("xpath=//table//tr[td/a[text()='Intended Recipients']]/descendant::td[2]", preg_quote("2"));
249
250 // verify successful deliveries
251 $this->verifyText("xpath=//table//tr[td/a[text()='Successful Deliveries']]/descendant::td[2]", preg_quote("2 (100.00%)"));
252
253 // verify status
254 $this->verifyText("xpath=//table//tr[td[1]/text()='Status']/descendant::td[2]", preg_quote("Complete"));
255
256 // verify mailing name
257 $this->verifyText("xpath=//table//tr[td[1]/text()='Mailing Name']/descendant::td[2]", preg_quote("Mailing $mailingName Webtest"));
258
259 // verify mailing subject
260 $this->verifyText("xpath=//table//tr[td[1]/text()='Subject']/descendant::td[2]", preg_quote("Test subject $mailingName for Webtest"));
261
262 $this->verifyText("xpath=//table//tr[td[1]/text()='Campaign']/descendant::td[2]", preg_quote("$campaignTitle"));
263
264 //---- check for delivery detail--
265
266 $this->click("link=Successful Deliveries");
267 $this->waitForPageToLoad($this->getTimeoutMsec());
268
269 // check for open page
270 $this->assertElementContainsText('page-title', "Successful Deliveries");
271
272 // verify email
273 $this->assertElementContainsText('mailing_event', "mailino$firstName@mailson.co.in");
274 //------end delivery verification---------
275 }
276 }
277