3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
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 +--------------------------------------------------------------------+
27 require_once 'CiviTest/CiviSeleniumTestCase.php';
28 class WebTest_Campaign_MailingTest
extends CiviSeleniumTestCase
{
30 protected function setUp() {
34 function testCreateCampaign() {
35 // Log in as admin first to verify permissions for CiviCampaign
36 $this->webtestLogin('admin');
38 // Enable CiviCampaign module if necessary
39 $this->enableComponents(array('CiviMail', 'CiviCampaign'));
41 $this->setupDefaultMailbox();
43 // add the required permission
44 $this->changePermissions('edit-2-administer-civicampaign');
46 // Log in as normal user
47 $this->webtestLogin();
50 $title = substr(sha1(rand()), 0, 7);
51 $groupName = $this->WebtestAddGroup();
54 // We're using Quick Add block on the main page for this.
55 $firstName = substr(sha1(rand()), 0, 7);
56 $this->webtestAddContact($firstName, "Smith", "$firstName.smith@example.org");
58 // add contact to group
60 $this->click("css=li#tab_group a");
61 $this->waitForElementPresent("group_id");
64 $this->select("group_id", "label=$groupName");
65 $this->click("_qf_GroupContact_next");
66 $this->waitForPageToLoad($this->getTimeoutMsec());
68 $this->openCiviPage('campaign/add', 'reset=1', '_qf_Campaign_upload-bottom');
70 $campaignTitle = "Campaign $title";
71 $this->type("title", $campaignTitle);
73 // select the campaign type
74 $this->select("campaign_type_id", "value=2");
76 // fill in the description
77 $this->type("description", "This is a test campaign");
79 // include groups for the campaign
80 $this->addSelection("includeGroups-f", "label=$groupName");
81 $this->click("//option[@value=4]");
84 // fill the end date for campaign
85 $this->webtestFillDate("end_date", "+1 year");
87 // select campaign status
88 $this->select("status_id", "value=2");
91 $this->click("_qf_Campaign_upload-bottom");
92 $this->waitForPageToLoad($this->getTimeoutMsec());
94 $this->waitForText('crm-notification-container', "Campaign $title");
96 $this->waitForElementPresent("//div[@id='campaignList']/div[@class='dataTables_wrapper']/table/tbody/tr/td[text()='{$campaignTitle}']/../td[1]");
97 $id = (int) $this->getText("//div[@id='campaignList']/div[@class='dataTables_wrapper']/table/tbody/tr/td[text()='{$campaignTitle}']/../td[1]");
98 $this->mailingAddTest($groupName, $campaignTitle, $id);
101 function mailingAddTest($groupName, $campaignTitle, $id) {
102 //---- create mailing contact and add to mailing Group
103 $firstName = substr(sha1(rand()), 0, 7);
104 $this->webtestAddContact($firstName, "Mailson", "mailino$firstName@mailson.co.in");
106 // go to group tab and add to mailing group
107 $this->click("css=li#tab_group a");
108 $this->waitForElementPresent("_qf_GroupContact_next");
109 $this->select("group_id", "$groupName");
110 $this->click("_qf_GroupContact_next");
112 $this->openCiviPage('mailing/send', 'reset=1', '_qf_Group_cancel');
114 //-------select recipients----------
117 $mailingName = substr(sha1(rand()), 0, 7);
118 $this->type("name", "Mailing $mailingName Webtest");
121 $this->click("campaign_id");
122 $this->select("campaign_id", "value=$id");
124 // Add the test mailing group
125 $this->select("includeGroups-f", "$groupName");
129 $this->click("_qf_Group_next");
130 $this->waitForElementPresent("_qf_Settings_cancel");
132 //--------track and respond----------
134 // check for default settings options
135 $this->assertChecked("url_tracking");
136 $this->assertChecked("open_tracking");
138 // do check count for Recipient
139 $this->assertElementContainsText('crm-container', "Total Recipients: 2");
141 // no need tracking for this test
143 // click next with default settings
144 $this->click("_qf_Settings_next");
145 $this->waitForElementPresent("_qf_Upload_cancel");
147 //--------Mailing content------------
148 // let from email address be default
150 // fill subject for mailing
151 $this->type("subject", "Test subject $mailingName for Webtest");
153 // check for default option enabled
154 $this->assertChecked("CIVICRM_QFID_1_upload_type");
156 // fill message (presently using script for simple text area)
157 $this->click("//fieldset[@id='compose_id']/div[2]/div[1]");
158 $this->type("text_message", "this is test content for Mailing $mailingName Webtest");
162 // default header and footer ( with label )
163 $this->select("header_id", "label=Mailing Header");
164 $this->select("footer_id", "label=Mailing Footer");
166 // do check count for Recipient
167 $this->assertElementContainsText('crm-container', "Total Recipients: 2");
169 // click next with nominal content
170 $this->click("_qf_Upload_upload");
171 $this->waitForElementPresent("_qf_Test_cancel");
173 //---------------Test------------------
175 ////////--Commenting test mailing and mailing preview (test mailing and preview not presently working).
178 //$this->type("test_email", "mailino@mailson.co.in");
179 //$this->click("sendtest");
181 // verify status message
182 //$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)."));
184 // check mailing preview
185 //$this->click("//form[@id='Test']/div[2]/div[4]/div[1]");
186 //$this->assertTrue($this->isTextPresent("this is test content for Mailing $mailingName Webtest"));
190 // do check count for Recipient
191 $this->assertElementContainsText('crm-container', "Total Recipients: 2");
194 $this->click("_qf_Test_next");
195 $this->waitForElementPresent("_qf_Schedule_cancel");
197 //----------Schedule or Send------------
199 // do check for default option enabled
200 $this->assertChecked("now");
202 // do check count for Recipient
203 $this->assertElementContainsText('crm-container', "Total Recipients: 2");
205 // finally schedule the mail by clicking submit
206 $this->click("_qf_Schedule_next");
207 $this->waitForPageToLoad($this->getTimeoutMsec());
209 //----------end New Mailing-------------
211 //check redirected page to Scheduled and Sent Mailings and verify for mailing name
212 $this->assertElementContainsText('page-title', "Find Mailings");
213 $this->assertElementContainsText('Search', "Mailing $mailingName Webtest");
215 //--------- mail delivery verification---------
217 // test undelivered report
219 // click report link of created mailing
220 $this->click("xpath=//table//tbody/tr[td[1]/text()='Mailing $mailingName Webtest']/descendant::a[text()='Report']");
221 $this->waitForPageToLoad($this->getTimeoutMsec());
223 // verify undelivered status message
224 $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.");
226 // do check for recipient group
227 $this->assertElementContainsText('crm-container', "Members of $groupName");
229 // directly send schedule mailing -- not working right now
230 $this->openCiviPage('mailing/queue', 'reset=1');
232 //click report link of created mailing
233 $this->click("xpath=//table//tbody/tr[td[1]/text()='Mailing $mailingName Webtest']/descendant::a[text()='Report']");
234 $this->waitForPageToLoad($this->getTimeoutMsec());
236 // do check again for recipient group
237 $this->assertElementContainsText('crm-container', "Members of $groupName");
239 // check for 100% delivery
240 $this->assertElementContainsText('crm-container', "2 (100.00%)");
242 // verify intended recipients
243 $this->verifyText("xpath=//table//tr[td/a[text()='Intended Recipients']]/descendant::td[2]", preg_quote("2"));
245 // verify successful deliveries
246 $this->verifyText("xpath=//table//tr[td/a[text()='Successful Deliveries']]/descendant::td[2]", preg_quote("2 (100.00%)"));
249 $this->verifyText("xpath=//table//tr[td[1]/text()='Status']/descendant::td[2]", preg_quote("Complete"));
251 // verify mailing name
252 $this->verifyText("xpath=//table//tr[td[1]/text()='Mailing Name']/descendant::td[2]", preg_quote("Mailing $mailingName Webtest"));
254 // verify mailing subject
255 $this->verifyText("xpath=//table//tr[td[1]/text()='Subject']/descendant::td[2]", preg_quote("Test subject $mailingName for Webtest"));
257 $this->verifyText("xpath=//table//tr[td[1]/text()='Campaign']/descendant::td[2]", preg_quote("$campaignTitle"));
259 //---- check for delivery detail--
261 $this->click("link=Successful Deliveries");
262 $this->waitForPageToLoad($this->getTimeoutMsec());
264 // check for open page
265 $this->assertElementContainsText('page-title', "Successful Deliveries");
268 $this->assertElementContainsText('mailing_event', "mailino$firstName@mailson.co.in");
269 //------end delivery verification---------