Merge pull request #84 from pradpnayak/CRM-12018
[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(TRUE);
38
39 // Enable CiviCampaign module if necessary
40 $this->enableComponents(array('CiviCampaign'));
41
42 // add the required Drupal permission
43 $permissions = array('edit-2-administer-civicampaign');
44 $this->changePermissions($permissions);
45
46 // Create new group
47 $title = substr(sha1(rand()), 0, 7);
48 $groupName = $this->WebtestAddGroup();
49
50 // Adding contact
51 // We're using Quick Add block on the main page for this.
52 $firstName = substr(sha1(rand()), 0, 7);
53 $this->webtestAddContact($firstName, "Smith", "$firstName.smith@example.org");
54
55 // add contact to group
56 // visit group tab
57 $this->click("css=li#tab_group a");
58 $this->waitForElementPresent("group_id");
59
60 // add to group
61 $this->select("group_id", "label=$groupName");
62 $this->click("_qf_GroupContact_next");
63 $this->waitForPageToLoad($this->getTimeoutMsec());
64
65 // Go directly to the URL of the screen that you will be testing
66 $this->openCiviPage('campaign/add', 'reset=1', '_qf_Campaign_upload-bottom');
67
68 // Let's start filling the form with values.
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->assertElementContainsText('crm-notification-container', "Campaign Campaign $title has been saved.",
95 "Status message didn't show up after saving campaign!"
96 );
97
98 $this->waitForElementPresent("//div[@id='campaignList']/div[@class='dataTables_wrapper']/table/tbody/tr/td[text()='{$campaignTitle}']/../td[1]");
99 $id = (int) $this->getText("//div[@id='campaignList']/div[@class='dataTables_wrapper']/table/tbody/tr/td[text()='{$campaignTitle}']/../td[1]");
100 $this->mailingAddTest($groupName, $campaignTitle, $id);
101 }
102
103 function mailingAddTest($groupName, $campaignTitle, $id) {
104 //---- create mailing contact and add to mailing Group
105 $firstName = substr(sha1(rand()), 0, 7);
106 $this->webtestAddContact($firstName, "Mailson", "mailino$firstName@mailson.co.in");
107
108 // go to group tab and add to mailing group
109 $this->click("css=li#tab_group a");
110 $this->waitForElementPresent("_qf_GroupContact_next");
111 $this->select("group_id", "$groupName");
112 $this->click("_qf_GroupContact_next");
113
114 // configure default mail-box
115 $this->openCiviPage('admin/mailSettings', 'action=update&id=1&reset=1', '_qf_MailSettings_cancel-bottom');
116 $this->type('name', 'Test Domain');
117 $this->type('domain', 'example.com');
118 $this->select('protocol', 'value=1');
119 $this->click('_qf_MailSettings_next-bottom');
120 $this->waitForPageToLoad($this->getTimeoutMsec());
121
122 // Go directly to Schedule and Send Mailing form
123 $this->openCiviPage('mailing/send', 'reset=1', '_qf_Group_cancel');
124
125 //-------select recipients----------
126
127 // fill mailing name
128 $mailingName = substr(sha1(rand()), 0, 7);
129 $this->type("name", "Mailing $mailingName Webtest");
130
131 // select campaign
132 $this->click("campaign_id");
133 $this->select("campaign_id", "value=$id");
134
135 // Add the test mailing group
136 $this->select("includeGroups-f", "$groupName");
137 $this->click("add");
138
139 // click next
140 $this->click("_qf_Group_next");
141 $this->waitForElementPresent("_qf_Settings_cancel");
142
143 //--------track and respond----------
144
145 // check for default settings options
146 $this->assertChecked("url_tracking");
147 $this->assertChecked("open_tracking");
148
149 // do check count for Recipient
150 $this->assertElementContainsText('crm-container', "Total Recipients: 2");
151
152 // no need tracking for this test
153
154 // click next with default settings
155 $this->click("_qf_Settings_next");
156 $this->waitForElementPresent("_qf_Upload_cancel");
157
158 //--------Mailing content------------
159 // let from email address be default
160
161 // fill subject for mailing
162 $this->type("subject", "Test subject $mailingName for Webtest");
163
164 // check for default option enabled
165 $this->assertChecked("CIVICRM_QFID_1_upload_type");
166
167 // fill message (presently using script for simple text area)
168 $this->click("//fieldset[@id='compose_id']/div[2]/div[1]");
169 $this->type("text_message", "this is test content for Mailing $mailingName Webtest");
170
171 // add attachment?
172
173 // default header and footer ( with label )
174 $this->select("header_id", "label=Mailing Header");
175 $this->select("footer_id", "label=Mailing Footer");
176
177 // do check count for Recipient
178 $this->assertElementContainsText('crm-container', "Total Recipients: 2");
179
180 // click next with nominal content
181 $this->click("_qf_Upload_upload");
182 $this->waitForElementPresent("_qf_Test_cancel");
183
184 //---------------Test------------------
185
186 ////////--Commenting test mailing and mailing preview (test mailing and preview not presently working).
187
188 // send test mailing
189 //$this->type("test_email", "mailino@mailson.co.in");
190 //$this->click("sendtest");
191
192 // verify status message
193 //$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)."));
194
195 // check mailing preview
196 //$this->click("//form[@id='Test']/div[2]/div[4]/div[1]");
197 //$this->assertTrue($this->isTextPresent("this is test content for Mailing $mailingName Webtest"));
198
199 ////////
200
201 // do check count for Recipient
202 $this->assertElementContainsText('crm-container', "Total Recipients: 2");
203
204 // click next
205 $this->click("_qf_Test_next");
206 $this->waitForElementPresent("_qf_Schedule_cancel");
207
208 //----------Schedule or Send------------
209
210 // do check for default option enabled
211 $this->assertChecked("now");
212
213 // do check count for Recipient
214 $this->assertElementContainsText('crm-container', "Total Recipients: 2");
215
216 // finally schedule the mail by clicking submit
217 $this->click("_qf_Schedule_next");
218 $this->waitForPageToLoad($this->getTimeoutMsec());
219
220 //----------end New Mailing-------------
221
222 //check redirected page to Scheduled and Sent Mailings and verify for mailing name
223 $this->assertElementContainsText('page-title', "Scheduled and Sent Mailings");
224 $this->assertElementContainsText('Search', "Mailing $mailingName Webtest");
225
226 //--------- mail delivery verification---------
227
228 // test undelivered report
229
230 // click report link of created mailing
231 $this->click("xpath=//table//tbody/tr[td[1]/text()='Mailing $mailingName Webtest']/descendant::a[text()='Report']");
232 $this->waitForPageToLoad($this->getTimeoutMsec());
233
234 // verify undelivered status message
235 $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.");
236
237 // do check for recipient group
238 $this->assertElementContainsText('crm-container', "Members of $groupName");
239
240 // directly send schedule mailing -- not working right now
241 $this->openCiviPage('mailing/queue', 'reset=1');
242
243 //click report link of created mailing
244 $this->click("xpath=//table//tbody/tr[td[1]/text()='Mailing $mailingName Webtest']/descendant::a[text()='Report']");
245 $this->waitForPageToLoad($this->getTimeoutMsec());
246
247 // do check again for recipient group
248 $this->assertElementContainsText('crm-container', "Members of $groupName");
249
250 // check for 100% delivery
251 $this->assertElementContainsText('crm-container', "2 (100.00%)");
252
253 // verify intended recipients
254 $this->verifyText("xpath=//table//tr[td/a[text()='Intended Recipients']]/descendant::td[2]", preg_quote("2"));
255
256 // verify successful deliveries
257 $this->verifyText("xpath=//table//tr[td/a[text()='Successful Deliveries']]/descendant::td[2]", preg_quote("2 (100.00%)"));
258
259 // verify status
260 $this->verifyText("xpath=//table//tr[td[1]/text()='Status']/descendant::td[2]", preg_quote("Complete"));
261
262 // verify mailing name
263 $this->verifyText("xpath=//table//tr[td[1]/text()='Mailing Name']/descendant::td[2]", preg_quote("Mailing $mailingName Webtest"));
264
265 // verify mailing subject
266 $this->verifyText("xpath=//table//tr[td[1]/text()='Subject']/descendant::td[2]", preg_quote("Test subject $mailingName for Webtest"));
267
268 $this->verifyText("xpath=//table//tr[td[1]/text()='Campaign']/descendant::td[2]", preg_quote("$campaignTitle"));
269
270 //---- check for delivery detail--
271
272 $this->click("link=Successful Deliveries");
273 $this->waitForPageToLoad($this->getTimeoutMsec());
274
275 // check for open page
276 $this->assertElementContainsText('page-title', "Successful Deliveries");
277
278 // verify email
279 $this->assertElementContainsText('mailing_event', "mailino$firstName@mailson.co.in");
280 //------end delivery verification---------
281 }
282 }
283