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