version fixes
[civicrm-core.git] / tests / phpunit / WebTest / Campaign / MailingTest.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
39de6fd5 4 | CiviCRM version 4.6 |
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");
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");
2af8120a 70 $this->waitForElementPresent('link=Remove');
6a488035 71
8f737a72 72 $this->openCiviPage('campaign/add', 'reset=1', '_qf_Campaign_upload-bottom');
6a488035 73
6a488035
TO
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
bf333c47 84 $this->multiselect2("includeGroups", array("$groupName", "Advisory Board"));
6a488035
TO
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
6c5f7368 96 $this->waitForText('crm-notification-container', "Campaign $title");
6a488035 97
03748831 98 $this->mailingAddTest($groupName, $campaignTitle, $title, $firstName);
6a488035
TO
99 }
100
4cbe18b8 101 /**
100fef9d 102 * @param string $groupName
4cbe18b8 103 * @param $campaignTitle
d50d5019 104 * @param $firstUserName
4cbe18b8 105 */
03748831 106 public function mailingAddTest($groupName, $campaignTitle, $title, $firstUserName) {
6a488035
TO
107 //---- create mailing contact and add to mailing Group
108 $firstName = substr(sha1(rand()), 0, 7);
109 $this->webtestAddContact($firstName, "Mailson", "mailino$firstName@mailson.co.in");
110
111 // go to group tab and add to mailing group
112 $this->click("css=li#tab_group a");
113 $this->waitForElementPresent("_qf_GroupContact_next");
114 $this->select("group_id", "$groupName");
115 $this->click("_qf_GroupContact_next");
116
03748831 117 $this->openCiviPage('a/#/mailing/new');
118 $this->waitForElementPresent("xpath=//input[@name='mailingName']");
6a488035
TO
119 //-------select recipients----------
120
121 // fill mailing name
122 $mailingName = substr(sha1(rand()), 0, 7);
03748831 123 $this->type("xpath=//input[@name='mailingName']", "Mailing $mailingName Webtest");
6a488035
TO
124
125 // select campaign
d50d5019 126 $this->select2("s2id_crmUiId_4", "Campaign_" . $title);
6a488035
TO
127
128 // Add the test mailing group
03748831 129 $this->select2("s2id_crmUiId_8", $groupName, TRUE);
6a488035 130
03748831 131 $this->waitForTextPresent("~2 recipients");
6a488035
TO
132
133 //--------Mailing content------------
c79c8ec8 134 $tokens = ' {domain.address}{action.optOutUrl}';
6a488035 135 // fill subject for mailing
03748831 136 $this->type("xpath=//input[@name='subject']", "Test subject {$mailingName} for Webtest");
137 // HTML format message
138 $HTMLMessage = "This is HTML formatted content for Mailing {$mailingName} Webtest.";
c79c8ec8 139 $this->fillRichTextField("crmUiId_1", $HTMLMessage . $tokens);
03748831 140
c79c8ec8
CW
141 // FIXME: Selenium can't access content in an iframe
142 //$this->click("xpath=//div[@class='preview-popup']//a[text()='Preview as HTML']");
143 //$this->waitForTextPresent($HTMLMessage);
144 //$this->waitForAjaxContent();
145 //$this->click("xpath=//button[@title='Close']");
6a488035 146
03748831 147 // Open Plain-text Format pane and type text format msg
c79c8ec8
CW
148 $this->click("//div[starts-with(text(),'Plain Text')]");
149 $this->type("xpath=//*[@name='body_text']", "This is text formatted content for Mailing {$mailingName} Webtest.$tokens");
6a488035 150
03748831 151 $this->click("xpath=//div[@class='preview-popup']//a[text()='Preview as Plain Text']");
152 $this->waitForTextPresent("This is text formatted content for Mailing {$mailingName} Webtest.");
03748831 153 $this->click("xpath=//button[@title='Close']");
6a488035 154
03748831 155 //--------track and respond----------
156 $this->click("xpath=//ul/li/a[text()='Tracking']");
157 $this->assertChecked("url_tracking");
158 $this->assertChecked("open_tracking");
159 // no need tracking for this test
6a488035
TO
160
161 // default header and footer ( with label )
03748831 162 $this->click("xpath=//ul/li/a[text()='Header and Footer']");
6a488035
TO
163 $this->select("header_id", "label=Mailing Header");
164 $this->select("footer_id", "label=Mailing Footer");
165
6a488035
TO
166 //---------------Test------------------
167
168 ////////--Commenting test mailing and mailing preview (test mailing and preview not presently working).
169
170 // send test mailing
171 //$this->type("test_email", "mailino@mailson.co.in");
172 //$this->click("sendtest");
173
174 // verify status message
175 //$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)."));
176
177 // check mailing preview
178 //$this->click("//form[@id='Test']/div[2]/div[4]/div[1]");
179 //$this->assertTrue($this->isTextPresent("this is test content for Mailing $mailingName Webtest"));
180
181 ////////
182
6a488035 183 // click next
03748831 184 $this->click("xpath=//div[@class='crm-wizard-buttons']/button[text()='Next']");
6a488035
TO
185
186 //----------Schedule or Send------------
187
03748831 188 // do check for other option
189 $this->waitForTextPresent("Mailing $mailingName Webtest");
190 $this->click("xpath=//div[@class='content']//a[text()='~2 recipients']");
191 $verifyData = array(
d50d5019 192 "$firstUserName Smith" => "$firstUserName.smith@example.org",
193 "$firstName Mailson" => "mailino$firstName@mailson.co.in",
03748831 194 );
195 $this->webtestVerifyTabularData($verifyData);
196 $this->waitForTextPresent("(Include: $groupName)");
197 $this->assertChecked("xpath=//input[@id='schedule-send-now']");
6a488035
TO
198
199 // finally schedule the mail by clicking submit
03748831 200 $this->click("xpath=//center/a/div[text()='Submit Mailing']");
6a488035
TO
201 $this->waitForPageToLoad($this->getTimeoutMsec());
202
203 //----------end New Mailing-------------
204
205 //check redirected page to Scheduled and Sent Mailings and verify for mailing name
03748831 206 $this->waitForTextPresent("Find Mailings");
8f737a72 207 $this->assertElementContainsText('Search', "Mailing $mailingName Webtest");
6a488035
TO
208
209 //--------- mail delivery verification---------
210
211 // test undelivered report
212
213 // click report link of created mailing
214 $this->click("xpath=//table//tbody/tr[td[1]/text()='Mailing $mailingName Webtest']/descendant::a[text()='Report']");
215 $this->waitForPageToLoad($this->getTimeoutMsec());
216
217 // verify undelivered status message
6c6e6187 218 $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
219
220 // do check for recipient group
8f737a72 221 $this->assertElementContainsText('crm-container', "Members of $groupName");
6a488035
TO
222
223 // directly send schedule mailing -- not working right now
8f737a72 224 $this->openCiviPage('mailing/queue', 'reset=1');
6a488035
TO
225
226 //click report link of created mailing
227 $this->click("xpath=//table//tbody/tr[td[1]/text()='Mailing $mailingName Webtest']/descendant::a[text()='Report']");
228 $this->waitForPageToLoad($this->getTimeoutMsec());
229
230 // do check again for recipient group
8f737a72 231 $this->assertElementContainsText('crm-container', "Members of $groupName");
6a488035
TO
232
233 // check for 100% delivery
8f737a72 234 $this->assertElementContainsText('crm-container', "2 (100.00%)");
6a488035
TO
235
236 // verify intended recipients
237 $this->verifyText("xpath=//table//tr[td/a[text()='Intended Recipients']]/descendant::td[2]", preg_quote("2"));
238
239 // verify successful deliveries
240 $this->verifyText("xpath=//table//tr[td/a[text()='Successful Deliveries']]/descendant::td[2]", preg_quote("2 (100.00%)"));
241
242 // verify status
243 $this->verifyText("xpath=//table//tr[td[1]/text()='Status']/descendant::td[2]", preg_quote("Complete"));
244
245 // verify mailing name
246 $this->verifyText("xpath=//table//tr[td[1]/text()='Mailing Name']/descendant::td[2]", preg_quote("Mailing $mailingName Webtest"));
247
248 // verify mailing subject
249 $this->verifyText("xpath=//table//tr[td[1]/text()='Subject']/descendant::td[2]", preg_quote("Test subject $mailingName for Webtest"));
250
251 $this->verifyText("xpath=//table//tr[td[1]/text()='Campaign']/descendant::td[2]", preg_quote("$campaignTitle"));
252
253 //---- check for delivery detail--
6a488035
TO
254 $this->click("link=Successful Deliveries");
255 $this->waitForPageToLoad($this->getTimeoutMsec());
256
257 // check for open page
03748831 258 $this->waitForTextPresent("Successful Deliveries");
6a488035 259 // verify email
8f737a72 260 $this->assertElementContainsText('mailing_event', "mailino$firstName@mailson.co.in");
6a488035
TO
261 //------end delivery verification---------
262 }
96025800 263
6a488035 264}