3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
27 require_once 'CiviTest/CiviSeleniumTestCase.php';
30 * Class WebTest_Campaign_MailingTest
32 class WebTest_Campaign_MailingTest
extends CiviSeleniumTestCase
{
34 protected function setUp() {
38 function testCreateCampaign() {
39 // Log in as admin first to verify permissions for CiviCampaign
40 $this->webtestLogin('admin');
42 // Enable CiviCampaign module if necessary
43 $this->enableComponents(array('CiviMail', 'CiviCampaign'));
45 $this->setupDefaultMailbox();
47 // add the required permission
48 $this->changePermissions('edit-2-administer-civicampaign');
50 // Log in as normal user
51 $this->webtestLogin();
54 $title = substr(sha1(rand()), 0, 7);
55 $groupName = $this->WebtestAddGroup();
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");
62 // add contact to group
64 $this->click("css=li#tab_group a");
65 $this->waitForElementPresent("group_id");
68 $this->select("group_id", "label=$groupName");
69 $this->click("_qf_GroupContact_next");
70 $this->waitForElementPresent('link=Remove');
72 $this->openCiviPage('campaign/add', 'reset=1', '_qf_Campaign_upload-bottom');
74 $campaignTitle = "Campaign $title";
75 $this->type("title", $campaignTitle);
77 // select the campaign type
78 $this->select("campaign_type_id", "value=2");
80 // fill in the description
81 $this->type("description", "This is a test campaign");
83 // include groups for the campaign
84 $this->multiselect2("includeGroups", array("$groupName", "Advisory Board"));
86 // fill the end date for campaign
87 $this->webtestFillDate("end_date", "+1 year");
89 // select campaign status
90 $this->select("status_id", "value=2");
93 $this->click("_qf_Campaign_upload-bottom");
94 $this->waitForPageToLoad($this->getTimeoutMsec());
96 $this->waitForText('crm-notification-container', "Campaign $title");
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]");
100 $this->mailingAddTest($groupName, $campaignTitle, $id);
105 * @param $campaignTitle
108 function mailingAddTest($groupName, $campaignTitle, $id) {
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");
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");
119 $this->openCiviPage('mailing/send', 'reset=1', '_qf_Group_cancel');
121 //-------select recipients----------
124 $mailingName = substr(sha1(rand()), 0, 7);
125 $this->type("name", "Mailing $mailingName Webtest");
128 $this->click("campaign_id");
129 $this->select("campaign_id", "value=$id");
131 // Add the test mailing group
132 $this->select("includeGroups", "$groupName");
135 $this->click("_qf_Group_next");
136 $this->waitForElementPresent("_qf_Settings_cancel");
138 //--------track and respond----------
140 // check for default settings options
141 $this->assertChecked("url_tracking");
142 $this->assertChecked("open_tracking");
144 // do check count for Recipient
145 $this->assertElementContainsText('crm-container', "Total Recipients: 2");
147 // no need tracking for this test
149 // click next with default settings
150 $this->click("_qf_Settings_next");
151 $this->waitForElementPresent("_qf_Upload_cancel");
153 //--------Mailing content------------
154 // let from email address be default
156 // fill subject for mailing
157 $this->type("subject", "Test subject $mailingName for Webtest");
159 // check for default option enabled
160 $this->assertChecked("CIVICRM_QFID_1_upload_type");
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");
168 // default header and footer ( with label )
169 $this->select("header_id", "label=Mailing Header");
170 $this->select("footer_id", "label=Mailing Footer");
172 // do check count for Recipient
173 $this->assertElementContainsText('crm-container', "Total Recipients: 2");
175 // click next with nominal content
176 $this->click("_qf_Upload_upload");
177 $this->waitForElementPresent("_qf_Test_cancel");
179 //---------------Test------------------
181 ////////--Commenting test mailing and mailing preview (test mailing and preview not presently working).
184 //$this->type("test_email", "mailino@mailson.co.in");
185 //$this->click("sendtest");
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)."));
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"));
196 // do check count for Recipient
197 $this->assertElementContainsText('crm-container', "Total Recipients: 2");
200 $this->click("_qf_Test_next");
201 $this->waitForElementPresent("_qf_Schedule_cancel");
203 //----------Schedule or Send------------
205 // do check for default option enabled
206 $this->assertChecked("now");
208 // do check count for Recipient
209 $this->assertElementContainsText('crm-container', "Total Recipients: 2");
211 // finally schedule the mail by clicking submit
212 $this->click("_qf_Schedule_next");
213 $this->waitForPageToLoad($this->getTimeoutMsec());
215 //----------end New Mailing-------------
217 //check redirected page to Scheduled and Sent Mailings and verify for mailing name
218 $this->assertElementContainsText('page-title', "Find Mailings");
219 $this->assertElementContainsText('Search', "Mailing $mailingName Webtest");
221 //--------- mail delivery verification---------
223 // test undelivered report
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());
229 // verify undelivered status message
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.");
232 // do check for recipient group
233 $this->assertElementContainsText('crm-container', "Members of $groupName");
235 // directly send schedule mailing -- not working right now
236 $this->openCiviPage('mailing/queue', 'reset=1');
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());
242 // do check again for recipient group
243 $this->assertElementContainsText('crm-container', "Members of $groupName");
245 // check for 100% delivery
246 $this->assertElementContainsText('crm-container', "2 (100.00%)");
248 // verify intended recipients
249 $this->verifyText("xpath=//table//tr[td/a[text()='Intended Recipients']]/descendant::td[2]", preg_quote("2"));
251 // verify successful deliveries
252 $this->verifyText("xpath=//table//tr[td/a[text()='Successful Deliveries']]/descendant::td[2]", preg_quote("2 (100.00%)"));
255 $this->verifyText("xpath=//table//tr[td[1]/text()='Status']/descendant::td[2]", preg_quote("Complete"));
257 // verify mailing name
258 $this->verifyText("xpath=//table//tr[td[1]/text()='Mailing Name']/descendant::td[2]", preg_quote("Mailing $mailingName Webtest"));
260 // verify mailing subject
261 $this->verifyText("xpath=//table//tr[td[1]/text()='Subject']/descendant::td[2]", preg_quote("Test subject $mailingName for Webtest"));
263 $this->verifyText("xpath=//table//tr[td[1]/text()='Campaign']/descendant::td[2]", preg_quote("$campaignTitle"));
265 //---- check for delivery detail--
267 $this->click("link=Successful Deliveries");
268 $this->waitForPageToLoad($this->getTimeoutMsec());
270 // check for open page
271 $this->assertElementContainsText('page-title', "Successful Deliveries");
274 $this->assertElementContainsText('mailing_event', "mailino$firstName@mailson.co.in");
275 //------end delivery verification---------