comment fixes
[civicrm-core.git] / tests / phpunit / WebTest / Campaign / MailingTest.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
81621fee 4 | CiviCRM version 4.7 |
6a488035 5 +--------------------------------------------------------------------+
e7112fa7 6 | Copyright CiviCRM LLC (c) 2004-2015 |
6a488035
TO
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 +--------------------------------------------------------------------+
d25dd0ee 25 */
6a488035 26
6a488035 27require_once 'CiviTest/CiviSeleniumTestCase.php';
e9479dcf
EM
28
29/**
30 * Class WebTest_Campaign_MailingTest
31 */
6a488035
TO
32class WebTest_Campaign_MailingTest extends CiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
00be9182 38 public function testCreateCampaign() {
6a488035 39 // Log in as admin first to verify permissions for CiviCampaign
42daf119 40 $this->webtestLogin('admin');
6a488035
TO
41
42 // Enable CiviCampaign module if necessary
5ff68892 43 $this->enableComponents(array('CiviMail', 'CiviCampaign'));
6a488035 44
5ff68892
CW
45 $this->setupDefaultMailbox();
46
47 // add the required permission
48 $this->changePermissions('edit-2-administer-civicampaign');
6a488035 49
42daf119
CW
50 // Log in as normal user
51 $this->webtestLogin();
52
6a488035
TO
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");
3bd51000 61 $this->_contactNames = array("$firstName.smith@example.org" => "Smith, $firstName");
6a488035
TO
62
63 // add contact to group
64 // visit group tab
65 $this->click("css=li#tab_group a");
66 $this->waitForElementPresent("group_id");
67
68 // add to group
69 $this->select("group_id", "label=$groupName");
70 $this->click("_qf_GroupContact_next");
2af8120a 71 $this->waitForElementPresent('link=Remove');
6a488035 72
8f737a72 73 $this->openCiviPage('campaign/add', 'reset=1', '_qf_Campaign_upload-bottom');
6a488035 74
6a488035
TO
75 $campaignTitle = "Campaign $title";
76 $this->type("title", $campaignTitle);
77
78 // select the campaign type
79 $this->select("campaign_type_id", "value=2");
80
81 // fill in the description
82 $this->type("description", "This is a test campaign");
83
84 // include groups for the campaign
bf333c47 85 $this->multiselect2("includeGroups", array("$groupName", "Advisory Board"));
6a488035
TO
86
87 // fill the end date for campaign
88 $this->webtestFillDate("end_date", "+1 year");
89
90 // select campaign status
91 $this->select("status_id", "value=2");
92
93 // click save
94 $this->click("_qf_Campaign_upload-bottom");
95 $this->waitForPageToLoad($this->getTimeoutMsec());
96
6c5f7368 97 $this->waitForText('crm-notification-container', "Campaign $title");
6a488035 98
03748831 99 $this->mailingAddTest($groupName, $campaignTitle, $title, $firstName);
6a488035
TO
100 }
101
4cbe18b8 102 /**
100fef9d 103 * @param string $groupName
4cbe18b8 104 * @param $campaignTitle
d50d5019 105 * @param $firstUserName
4cbe18b8 106 */
03748831 107 public function mailingAddTest($groupName, $campaignTitle, $title, $firstUserName) {
6a488035
TO
108 //---- create mailing contact and add to mailing Group
109 $firstName = substr(sha1(rand()), 0, 7);
110 $this->webtestAddContact($firstName, "Mailson", "mailino$firstName@mailson.co.in");
3bd51000 111 $this->_contactNames["mailino$firstName@mailson.co.in"] = "Mailson, $firstName";
6a488035
TO
112
113 // go to group tab and add to mailing group
114 $this->click("css=li#tab_group a");
115 $this->waitForElementPresent("_qf_GroupContact_next");
116 $this->select("group_id", "$groupName");
117 $this->click("_qf_GroupContact_next");
118
03748831 119 $this->openCiviPage('a/#/mailing/new');
120 $this->waitForElementPresent("xpath=//input[@name='mailingName']");
6a488035
TO
121 //-------select recipients----------
122
123 // fill mailing name
124 $mailingName = substr(sha1(rand()), 0, 7);
03748831 125 $this->type("xpath=//input[@name='mailingName']", "Mailing $mailingName Webtest");
6a488035
TO
126
127 // select campaign
d50d5019 128 $this->select2("s2id_crmUiId_4", "Campaign_" . $title);
6a488035
TO
129
130 // Add the test mailing group
03748831 131 $this->select2("s2id_crmUiId_8", $groupName, TRUE);
6a488035 132
03748831 133 $this->waitForTextPresent("~2 recipients");
6a488035
TO
134
135 //--------Mailing content------------
c79c8ec8 136 $tokens = ' {domain.address}{action.optOutUrl}';
6a488035 137 // fill subject for mailing
03748831 138 $this->type("xpath=//input[@name='subject']", "Test subject {$mailingName} for Webtest");
139 // HTML format message
140 $HTMLMessage = "This is HTML formatted content for Mailing {$mailingName} Webtest.";
c79c8ec8 141 $this->fillRichTextField("crmUiId_1", $HTMLMessage . $tokens);
03748831 142
c79c8ec8
CW
143 // FIXME: Selenium can't access content in an iframe
144 //$this->click("xpath=//div[@class='preview-popup']//a[text()='Preview as HTML']");
145 //$this->waitForTextPresent($HTMLMessage);
146 //$this->waitForAjaxContent();
147 //$this->click("xpath=//button[@title='Close']");
6a488035 148
03748831 149 // Open Plain-text Format pane and type text format msg
c79c8ec8
CW
150 $this->click("//div[starts-with(text(),'Plain Text')]");
151 $this->type("xpath=//*[@name='body_text']", "This is text formatted content for Mailing {$mailingName} Webtest.$tokens");
6a488035 152
03748831 153 $this->click("xpath=//div[@class='preview-popup']//a[text()='Preview as Plain Text']");
154 $this->waitForTextPresent("This is text formatted content for Mailing {$mailingName} Webtest.");
03748831 155 $this->click("xpath=//button[@title='Close']");
6a488035 156
03748831 157 //--------track and respond----------
158 $this->click("xpath=//ul/li/a[text()='Tracking']");
159 $this->assertChecked("url_tracking");
160 $this->assertChecked("open_tracking");
161 // no need tracking for this test
6a488035
TO
162
163 // default header and footer ( with label )
03748831 164 $this->click("xpath=//ul/li/a[text()='Header and Footer']");
6a488035
TO
165 $this->select("header_id", "label=Mailing Header");
166 $this->select("footer_id", "label=Mailing Footer");
167
6a488035
TO
168 //---------------Test------------------
169
170 ////////--Commenting test mailing and mailing preview (test mailing and preview not presently working).
171
172 // send test mailing
173 //$this->type("test_email", "mailino@mailson.co.in");
174 //$this->click("sendtest");
175
176 // verify status message
177 //$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)."));
178
179 // check mailing preview
180 //$this->click("//form[@id='Test']/div[2]/div[4]/div[1]");
181 //$this->assertTrue($this->isTextPresent("this is test content for Mailing $mailingName Webtest"));
182
183 ////////
184
6a488035 185 // click next
03748831 186 $this->click("xpath=//div[@class='crm-wizard-buttons']/button[text()='Next']");
6a488035
TO
187
188 //----------Schedule or Send------------
189
03748831 190 // do check for other option
191 $this->waitForTextPresent("Mailing $mailingName Webtest");
192 $this->click("xpath=//div[@class='content']//a[text()='~2 recipients']");
193 $verifyData = array(
d50d5019 194 "$firstUserName Smith" => "$firstUserName.smith@example.org",
195 "$firstName Mailson" => "mailino$firstName@mailson.co.in",
03748831 196 );
197 $this->webtestVerifyTabularData($verifyData);
198 $this->waitForTextPresent("(Include: $groupName)");
199 $this->assertChecked("xpath=//input[@id='schedule-send-now']");
6a488035
TO
200
201 // finally schedule the mail by clicking submit
03748831 202 $this->click("xpath=//center/a/div[text()='Submit Mailing']");
6a488035
TO
203 $this->waitForPageToLoad($this->getTimeoutMsec());
204
205 //----------end New Mailing-------------
206
207 //check redirected page to Scheduled and Sent Mailings and verify for mailing name
03748831 208 $this->waitForTextPresent("Find Mailings");
8f737a72 209 $this->assertElementContainsText('Search', "Mailing $mailingName Webtest");
6a488035
TO
210
211 //--------- mail delivery verification---------
212
213 // test undelivered report
214
215 // click report link of created mailing
216 $this->click("xpath=//table//tbody/tr[td[1]/text()='Mailing $mailingName Webtest']/descendant::a[text()='Report']");
217 $this->waitForPageToLoad($this->getTimeoutMsec());
218
219 // verify undelivered status message
6c6e6187 220 $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.");
6a488035
TO
221
222 // do check for recipient group
8f737a72 223 $this->assertElementContainsText('crm-container', "Members of $groupName");
6a488035
TO
224
225 // directly send schedule mailing -- not working right now
8f737a72 226 $this->openCiviPage('mailing/queue', 'reset=1');
6a488035
TO
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 // do check again for recipient group
8f737a72 233 $this->assertElementContainsText('crm-container', "Members of $groupName");
6a488035
TO
234
235 // check for 100% delivery
8f737a72 236 $this->assertElementContainsText('crm-container', "2 (100.00%)");
6a488035
TO
237
238 // verify intended recipients
239 $this->verifyText("xpath=//table//tr[td/a[text()='Intended Recipients']]/descendant::td[2]", preg_quote("2"));
240
241 // verify successful deliveries
242 $this->verifyText("xpath=//table//tr[td/a[text()='Successful Deliveries']]/descendant::td[2]", preg_quote("2 (100.00%)"));
243
244 // verify status
245 $this->verifyText("xpath=//table//tr[td[1]/text()='Status']/descendant::td[2]", preg_quote("Complete"));
246
247 // verify mailing name
248 $this->verifyText("xpath=//table//tr[td[1]/text()='Mailing Name']/descendant::td[2]", preg_quote("Mailing $mailingName Webtest"));
249
250 // verify mailing subject
251 $this->verifyText("xpath=//table//tr[td[1]/text()='Subject']/descendant::td[2]", preg_quote("Test subject $mailingName for Webtest"));
252
253 $this->verifyText("xpath=//table//tr[td[1]/text()='Campaign']/descendant::td[2]", preg_quote("$campaignTitle"));
254
255 //---- check for delivery detail--
6a488035
TO
256 $this->click("link=Successful Deliveries");
257 $this->waitForPageToLoad($this->getTimeoutMsec());
258
259 // check for open page
03748831 260 $this->waitForTextPresent("Successful Deliveries");
6a488035 261 // verify email
8f737a72 262 $this->assertElementContainsText('mailing_event', "mailino$firstName@mailson.co.in");
6a488035 263 //------end delivery verification---------
3bd51000
SB
264
265 // Search Advanced Search for contacts associated with Campaign in the Mailings Tab.
266 $this->mailingCampaignAdvancedSearchTest($campaignTitle, $this->_contactNames);
6a488035 267 }
96025800 268
85609814 269 public function mailingCampaignAdvancedSearchTest($campaignTitle, $contactNames) {
3bd51000
SB
270 // Go directly to Advanced Search
271 $this->openCiviPage('contact/search/advanced', 'reset=1');
272
273 // Select the Mailing Tab
274 $this->clickAjaxLink("CiviMail", 'campaigns');
275 $this->multiselect2("campaigns", array("$campaignTitle"));
276 $this->click("_qf_Advanced_refresh");
277
278 // Check for contacts inserted while adding Campaing and Mailing
9773de0a
SB
279 $this->waitForElementPresent('search-status');
280 $this->assertElementContainsText('search-status', '2 Contacts');
3bd51000 281 }
85609814 282
6a488035 283}