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->addSelection("includeGroups-f", "label=$groupName");
85 $this->click("//option[@value=4]");
88 // fill the end date for campaign
89 $this->webtestFillDate("end_date", "+1 year");
91 // select campaign status
92 $this->select("status_id", "value=2");
95 $this->click("_qf_Campaign_upload-bottom");
96 $this->waitForPageToLoad($this->getTimeoutMsec());
98 $this->waitForText('crm-notification-container', "Campaign $title");
100 $this->waitForElementPresent("//div[@id='campaignList']/div[@id='campaigns_wrapper']/table/tbody/tr/td[text()='{$campaignTitle}']/../td[1]");
101 $id = (int) $this->getText("//div[@id='campaignList']/div[@id='campaigns_wrapper']/table/tbody/tr/td[text()='{$campaignTitle}']/../td[1]");
102 $this->mailingAddTest($groupName, $campaignTitle, $id);
107 * @param $campaignTitle
110 function mailingAddTest($groupName, $campaignTitle, $id) {
111 //---- create mailing contact and add to mailing Group
112 $firstName = substr(sha1(rand()), 0, 7);
113 $this->webtestAddContact($firstName, "Mailson", "mailino$firstName@mailson.co.in");
115 // go to group tab and add to mailing group
116 $this->click("css=li#tab_group a");
117 $this->waitForElementPresent("_qf_GroupContact_next");
118 $this->select("group_id", "$groupName");
119 $this->click("_qf_GroupContact_next");
121 $this->openCiviPage('mailing/send', 'reset=1', '_qf_Group_cancel');
123 //-------select recipients----------
126 $mailingName = substr(sha1(rand()), 0, 7);
127 $this->type("name", "Mailing $mailingName Webtest");
130 $this->click("campaign_id");
131 $this->select("campaign_id", "value=$id");
133 // Add the test mailing group
134 $this->select("includeGroups-f", "$groupName");
138 $this->click("_qf_Group_next");
139 $this->waitForElementPresent("_qf_Settings_cancel");
141 //--------track and respond----------
143 // check for default settings options
144 $this->assertChecked("url_tracking");
145 $this->assertChecked("open_tracking");
147 // do check count for Recipient
148 $this->assertElementContainsText('crm-container', "Total Recipients: 2");
150 // no need tracking for this test
152 // click next with default settings
153 $this->click("_qf_Settings_next");
154 $this->waitForElementPresent("_qf_Upload_cancel");
156 //--------Mailing content------------
157 // let from email address be default
159 // fill subject for mailing
160 $this->type("subject", "Test subject $mailingName for Webtest");
162 // check for default option enabled
163 $this->assertChecked("CIVICRM_QFID_1_upload_type");
165 // fill message (presently using script for simple text area)
166 $this->click("//fieldset[@id='compose_id']/div[2]/div[1]");
167 $this->type("text_message", "this is test content for Mailing $mailingName Webtest");
171 // default header and footer ( with label )
172 $this->select("header_id", "label=Mailing Header");
173 $this->select("footer_id", "label=Mailing Footer");
175 // do check count for Recipient
176 $this->assertElementContainsText('crm-container', "Total Recipients: 2");
178 // click next with nominal content
179 $this->click("_qf_Upload_upload");
180 $this->waitForElementPresent("_qf_Test_cancel");
182 //---------------Test------------------
184 ////////--Commenting test mailing and mailing preview (test mailing and preview not presently working).
187 //$this->type("test_email", "mailino@mailson.co.in");
188 //$this->click("sendtest");
190 // verify status message
191 //$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)."));
193 // check mailing preview
194 //$this->click("//form[@id='Test']/div[2]/div[4]/div[1]");
195 //$this->assertTrue($this->isTextPresent("this is test content for Mailing $mailingName Webtest"));
199 // do check count for Recipient
200 $this->assertElementContainsText('crm-container', "Total Recipients: 2");
203 $this->click("_qf_Test_next");
204 $this->waitForElementPresent("_qf_Schedule_cancel");
206 //----------Schedule or Send------------
208 // do check for default option enabled
209 $this->assertChecked("now");
211 // do check count for Recipient
212 $this->assertElementContainsText('crm-container', "Total Recipients: 2");
214 // finally schedule the mail by clicking submit
215 $this->click("_qf_Schedule_next");
216 $this->waitForPageToLoad($this->getTimeoutMsec());
218 //----------end New Mailing-------------
220 //check redirected page to Scheduled and Sent Mailings and verify for mailing name
221 $this->assertElementContainsText('page-title', "Find Mailings");
222 $this->assertElementContainsText('Search', "Mailing $mailingName Webtest");
224 //--------- mail delivery verification---------
226 // test undelivered report
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());
232 // verify undelivered status message
233 $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.");
235 // do check for recipient group
236 $this->assertElementContainsText('crm-container', "Members of $groupName");
238 // directly send schedule mailing -- not working right now
239 $this->openCiviPage('mailing/queue', 'reset=1');
241 //click report link of created mailing
242 $this->click("xpath=//table//tbody/tr[td[1]/text()='Mailing $mailingName Webtest']/descendant::a[text()='Report']");
243 $this->waitForPageToLoad($this->getTimeoutMsec());
245 // do check again for recipient group
246 $this->assertElementContainsText('crm-container', "Members of $groupName");
248 // check for 100% delivery
249 $this->assertElementContainsText('crm-container', "2 (100.00%)");
251 // verify intended recipients
252 $this->verifyText("xpath=//table//tr[td/a[text()='Intended Recipients']]/descendant::td[2]", preg_quote("2"));
254 // verify successful deliveries
255 $this->verifyText("xpath=//table//tr[td/a[text()='Successful Deliveries']]/descendant::td[2]", preg_quote("2 (100.00%)"));
258 $this->verifyText("xpath=//table//tr[td[1]/text()='Status']/descendant::td[2]", preg_quote("Complete"));
260 // verify mailing name
261 $this->verifyText("xpath=//table//tr[td[1]/text()='Mailing Name']/descendant::td[2]", preg_quote("Mailing $mailingName Webtest"));
263 // verify mailing subject
264 $this->verifyText("xpath=//table//tr[td[1]/text()='Subject']/descendant::td[2]", preg_quote("Test subject $mailingName for Webtest"));
266 $this->verifyText("xpath=//table//tr[td[1]/text()='Campaign']/descendant::td[2]", preg_quote("$campaignTitle"));
268 //---- check for delivery detail--
270 $this->click("link=Successful Deliveries");
271 $this->waitForPageToLoad($this->getTimeoutMsec());
273 // check for open page
274 $this->assertElementContainsText('page-title', "Successful Deliveries");
277 $this->assertElementContainsText('mailing_event', "mailino$firstName@mailson.co.in");
278 //------end delivery verification---------