3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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 +--------------------------------------------------------------------+
28 require_once 'CiviTest/CiviSeleniumTestCase.php';
29 class WebTest_Campaign_MailingTest
extends CiviSeleniumTestCase
{
31 protected function setUp() {
35 function testCreateCampaign() {
36 // Log in as admin first to verify permissions for CiviCampaign
37 $this->webtestLogin('admin');
39 // Enable CiviCampaign module if necessary
40 $this->enableComponents(array('CiviMail', 'CiviCampaign'));
42 $this->setupDefaultMailbox();
44 // add the required permission
45 $this->changePermissions('edit-2-administer-civicampaign');
47 // Log in as normal user
48 $this->webtestLogin();
51 $title = substr(sha1(rand()), 0, 7);
52 $groupName = $this->WebtestAddGroup();
55 // We're using Quick Add block on the main page for this.
56 $firstName = substr(sha1(rand()), 0, 7);
57 $this->webtestAddContact($firstName, "Smith", "$firstName.smith@example.org");
59 // add contact to group
61 $this->click("css=li#tab_group a");
62 $this->waitForElementPresent("group_id");
65 $this->select("group_id", "label=$groupName");
66 $this->click("_qf_GroupContact_next");
67 $this->waitForPageToLoad($this->getTimeoutMsec());
69 $this->openCiviPage('campaign/add', 'reset=1', '_qf_Campaign_upload-bottom');
72 $campaignTitle = "Campaign $title";
73 $this->type("title", $campaignTitle);
75 // select the campaign type
76 $this->select("campaign_type_id", "value=2");
78 // fill in the description
79 $this->type("description", "This is a test campaign");
81 // include groups for the campaign
82 $this->addSelection("includeGroups-f", "label=$groupName");
83 $this->click("//option[@value=4]");
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->assertElementContainsText('crm-notification-container', "Campaign Campaign $title has been saved.",
97 "Status message didn't show up after saving campaign!"
100 $this->waitForElementPresent("//div[@id='campaignList']/div[@class='dataTables_wrapper']/table/tbody/tr/td[text()='{$campaignTitle}']/../td[1]");
101 $id = (int) $this->getText("//div[@id='campaignList']/div[@class='dataTables_wrapper']/table/tbody/tr/td[text()='{$campaignTitle}']/../td[1]");
102 $this->mailingAddTest($groupName, $campaignTitle, $id);
105 function mailingAddTest($groupName, $campaignTitle, $id) {
106 //---- create mailing contact and add to mailing Group
107 $firstName = substr(sha1(rand()), 0, 7);
108 $this->webtestAddContact($firstName, "Mailson", "mailino$firstName@mailson.co.in");
110 // go to group tab and add to mailing group
111 $this->click("css=li#tab_group a");
112 $this->waitForElementPresent("_qf_GroupContact_next");
113 $this->select("group_id", "$groupName");
114 $this->click("_qf_GroupContact_next");
116 $this->openCiviPage('mailing/send', 'reset=1', '_qf_Group_cancel');
118 //-------select recipients----------
121 $mailingName = substr(sha1(rand()), 0, 7);
122 $this->type("name", "Mailing $mailingName Webtest");
125 $this->click("campaign_id");
126 $this->select("campaign_id", "value=$id");
128 // Add the test mailing group
129 $this->select("includeGroups-f", "$groupName");
133 $this->click("_qf_Group_next");
134 $this->waitForElementPresent("_qf_Settings_cancel");
136 //--------track and respond----------
138 // check for default settings options
139 $this->assertChecked("url_tracking");
140 $this->assertChecked("open_tracking");
142 // do check count for Recipient
143 $this->assertElementContainsText('crm-container', "Total Recipients: 2");
145 // no need tracking for this test
147 // click next with default settings
148 $this->click("_qf_Settings_next");
149 $this->waitForElementPresent("_qf_Upload_cancel");
151 //--------Mailing content------------
152 // let from email address be default
154 // fill subject for mailing
155 $this->type("subject", "Test subject $mailingName for Webtest");
157 // check for default option enabled
158 $this->assertChecked("CIVICRM_QFID_1_upload_type");
160 // fill message (presently using script for simple text area)
161 $this->click("//fieldset[@id='compose_id']/div[2]/div[1]");
162 $this->type("text_message", "this is test content for Mailing $mailingName Webtest");
166 // default header and footer ( with label )
167 $this->select("header_id", "label=Mailing Header");
168 $this->select("footer_id", "label=Mailing Footer");
170 // do check count for Recipient
171 $this->assertElementContainsText('crm-container', "Total Recipients: 2");
173 // click next with nominal content
174 $this->click("_qf_Upload_upload");
175 $this->waitForElementPresent("_qf_Test_cancel");
177 //---------------Test------------------
179 ////////--Commenting test mailing and mailing preview (test mailing and preview not presently working).
182 //$this->type("test_email", "mailino@mailson.co.in");
183 //$this->click("sendtest");
185 // verify status message
186 //$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)."));
188 // check mailing preview
189 //$this->click("//form[@id='Test']/div[2]/div[4]/div[1]");
190 //$this->assertTrue($this->isTextPresent("this is test content for Mailing $mailingName Webtest"));
194 // do check count for Recipient
195 $this->assertElementContainsText('crm-container', "Total Recipients: 2");
198 $this->click("_qf_Test_next");
199 $this->waitForElementPresent("_qf_Schedule_cancel");
201 //----------Schedule or Send------------
203 // do check for default option enabled
204 $this->assertChecked("now");
206 // do check count for Recipient
207 $this->assertElementContainsText('crm-container', "Total Recipients: 2");
209 // finally schedule the mail by clicking submit
210 $this->click("_qf_Schedule_next");
211 $this->waitForPageToLoad($this->getTimeoutMsec());
213 //----------end New Mailing-------------
215 //check redirected page to Scheduled and Sent Mailings and verify for mailing name
216 $this->assertElementContainsText('page-title', "Scheduled and Sent Mailings");
217 $this->assertElementContainsText('Search', "Mailing $mailingName Webtest");
219 //--------- mail delivery verification---------
221 // test undelivered report
223 // click report link of created mailing
224 $this->click("xpath=//table//tbody/tr[td[1]/text()='Mailing $mailingName Webtest']/descendant::a[text()='Report']");
225 $this->waitForPageToLoad($this->getTimeoutMsec());
227 // verify undelivered status message
228 $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.");
230 // do check for recipient group
231 $this->assertElementContainsText('crm-container', "Members of $groupName");
233 // directly send schedule mailing -- not working right now
234 $this->openCiviPage('mailing/queue', 'reset=1');
236 //click report link of created mailing
237 $this->click("xpath=//table//tbody/tr[td[1]/text()='Mailing $mailingName Webtest']/descendant::a[text()='Report']");
238 $this->waitForPageToLoad($this->getTimeoutMsec());
240 // do check again for recipient group
241 $this->assertElementContainsText('crm-container', "Members of $groupName");
243 // check for 100% delivery
244 $this->assertElementContainsText('crm-container', "2 (100.00%)");
246 // verify intended recipients
247 $this->verifyText("xpath=//table//tr[td/a[text()='Intended Recipients']]/descendant::td[2]", preg_quote("2"));
249 // verify successful deliveries
250 $this->verifyText("xpath=//table//tr[td/a[text()='Successful Deliveries']]/descendant::td[2]", preg_quote("2 (100.00%)"));
253 $this->verifyText("xpath=//table//tr[td[1]/text()='Status']/descendant::td[2]", preg_quote("Complete"));
255 // verify mailing name
256 $this->verifyText("xpath=//table//tr[td[1]/text()='Mailing Name']/descendant::td[2]", preg_quote("Mailing $mailingName Webtest"));
258 // verify mailing subject
259 $this->verifyText("xpath=//table//tr[td[1]/text()='Subject']/descendant::td[2]", preg_quote("Test subject $mailingName for Webtest"));
261 $this->verifyText("xpath=//table//tr[td[1]/text()='Campaign']/descendant::td[2]", preg_quote("$campaignTitle"));
263 //---- check for delivery detail--
265 $this->click("link=Successful Deliveries");
266 $this->waitForPageToLoad($this->getTimeoutMsec());
268 // check for open page
269 $this->assertElementContainsText('page-title', "Successful Deliveries");
272 $this->assertElementContainsText('mailing_event', "mailino$firstName@mailson.co.in");
273 //------end delivery verification---------