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