Merge pull request #2758 from pratik-joshi/CRM-14278
[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->waitForPageToLoad($this->getTimeoutMsec());
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[@class='dataTables_wrapper']/table/tbody/tr/td[text()='{$campaignTitle}']/../td[1]");
97 $id = (int) $this->getText("//div[@id='campaignList']/div[@class='dataTables_wrapper']/table/tbody/tr/td[text()='{$campaignTitle}']/../td[1]");
98 $this->mailingAddTest($groupName, $campaignTitle, $id);
99 }
100
101 function mailingAddTest($groupName, $campaignTitle, $id) {
102 //---- create mailing contact and add to mailing Group
103 $firstName = substr(sha1(rand()), 0, 7);
104 $this->webtestAddContact($firstName, "Mailson", "mailino$firstName@mailson.co.in");
105
106 // go to group tab and add to mailing group
107 $this->click("css=li#tab_group a");
108 $this->waitForElementPresent("_qf_GroupContact_next");
109 $this->select("group_id", "$groupName");
110 $this->click("_qf_GroupContact_next");
111
112 $this->openCiviPage('mailing/send', 'reset=1', '_qf_Group_cancel');
113
114 //-------select recipients----------
115
116 // fill mailing name
117 $mailingName = substr(sha1(rand()), 0, 7);
118 $this->type("name", "Mailing $mailingName Webtest");
119
120 // select campaign
121 $this->click("campaign_id");
122 $this->select("campaign_id", "value=$id");
123
124 // Add the test mailing group
125 $this->select("includeGroups-f", "$groupName");
126 $this->click("add");
127
128 // click next
129 $this->click("_qf_Group_next");
130 $this->waitForElementPresent("_qf_Settings_cancel");
131
132 //--------track and respond----------
133
134 // check for default settings options
135 $this->assertChecked("url_tracking");
136 $this->assertChecked("open_tracking");
137
138 // do check count for Recipient
139 $this->assertElementContainsText('crm-container', "Total Recipients: 2");
140
141 // no need tracking for this test
142
143 // click next with default settings
144 $this->click("_qf_Settings_next");
145 $this->waitForElementPresent("_qf_Upload_cancel");
146
147 //--------Mailing content------------
148 // let from email address be default
149
150 // fill subject for mailing
151 $this->type("subject", "Test subject $mailingName for Webtest");
152
153 // check for default option enabled
154 $this->assertChecked("CIVICRM_QFID_1_upload_type");
155
156 // fill message (presently using script for simple text area)
157 $this->click("//fieldset[@id='compose_id']/div[2]/div[1]");
158 $this->type("text_message", "this is test content for Mailing $mailingName Webtest");
159
160 // add attachment?
161
162 // default header and footer ( with label )
163 $this->select("header_id", "label=Mailing Header");
164 $this->select("footer_id", "label=Mailing Footer");
165
166 // do check count for Recipient
167 $this->assertElementContainsText('crm-container', "Total Recipients: 2");
168
169 // click next with nominal content
170 $this->click("_qf_Upload_upload");
171 $this->waitForElementPresent("_qf_Test_cancel");
172
173 //---------------Test------------------
174
175 ////////--Commenting test mailing and mailing preview (test mailing and preview not presently working).
176
177 // send test mailing
178 //$this->type("test_email", "mailino@mailson.co.in");
179 //$this->click("sendtest");
180
181 // verify status message
182 //$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)."));
183
184 // check mailing preview
185 //$this->click("//form[@id='Test']/div[2]/div[4]/div[1]");
186 //$this->assertTrue($this->isTextPresent("this is test content for Mailing $mailingName Webtest"));
187
188 ////////
189
190 // do check count for Recipient
191 $this->assertElementContainsText('crm-container', "Total Recipients: 2");
192
193 // click next
194 $this->click("_qf_Test_next");
195 $this->waitForElementPresent("_qf_Schedule_cancel");
196
197 //----------Schedule or Send------------
198
199 // do check for default option enabled
200 $this->assertChecked("now");
201
202 // do check count for Recipient
203 $this->assertElementContainsText('crm-container', "Total Recipients: 2");
204
205 // finally schedule the mail by clicking submit
206 $this->click("_qf_Schedule_next");
207 $this->waitForPageToLoad($this->getTimeoutMsec());
208
209 //----------end New Mailing-------------
210
211 //check redirected page to Scheduled and Sent Mailings and verify for mailing name
212 $this->assertElementContainsText('page-title', "Find Mailings");
213 $this->assertElementContainsText('Search', "Mailing $mailingName Webtest");
214
215 //--------- mail delivery verification---------
216
217 // test undelivered report
218
219 // click report link of created mailing
220 $this->click("xpath=//table//tbody/tr[td[1]/text()='Mailing $mailingName Webtest']/descendant::a[text()='Report']");
221 $this->waitForPageToLoad($this->getTimeoutMsec());
222
223 // verify undelivered status message
224 $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.");
225
226 // do check for recipient group
227 $this->assertElementContainsText('crm-container', "Members of $groupName");
228
229 // directly send schedule mailing -- not working right now
230 $this->openCiviPage('mailing/queue', 'reset=1');
231
232 //click report link of created mailing
233 $this->click("xpath=//table//tbody/tr[td[1]/text()='Mailing $mailingName Webtest']/descendant::a[text()='Report']");
234 $this->waitForPageToLoad($this->getTimeoutMsec());
235
236 // do check again for recipient group
237 $this->assertElementContainsText('crm-container', "Members of $groupName");
238
239 // check for 100% delivery
240 $this->assertElementContainsText('crm-container', "2 (100.00%)");
241
242 // verify intended recipients
243 $this->verifyText("xpath=//table//tr[td/a[text()='Intended Recipients']]/descendant::td[2]", preg_quote("2"));
244
245 // verify successful deliveries
246 $this->verifyText("xpath=//table//tr[td/a[text()='Successful Deliveries']]/descendant::td[2]", preg_quote("2 (100.00%)"));
247
248 // verify status
249 $this->verifyText("xpath=//table//tr[td[1]/text()='Status']/descendant::td[2]", preg_quote("Complete"));
250
251 // verify mailing name
252 $this->verifyText("xpath=//table//tr[td[1]/text()='Mailing Name']/descendant::td[2]", preg_quote("Mailing $mailingName Webtest"));
253
254 // verify mailing subject
255 $this->verifyText("xpath=//table//tr[td[1]/text()='Subject']/descendant::td[2]", preg_quote("Test subject $mailingName for Webtest"));
256
257 $this->verifyText("xpath=//table//tr[td[1]/text()='Campaign']/descendant::td[2]", preg_quote("$campaignTitle"));
258
259 //---- check for delivery detail--
260
261 $this->click("link=Successful Deliveries");
262 $this->waitForPageToLoad($this->getTimeoutMsec());
263
264 // check for open page
265 $this->assertElementContainsText('page-title', "Successful Deliveries");
266
267 // verify email
268 $this->assertElementContainsText('mailing_event', "mailino$firstName@mailson.co.in");
269 //------end delivery verification---------
270 }
271 }
272