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