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';
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->waitForElementPresent('link=Remove');
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[@id='campaigns_wrapper']/table/tbody/tr/td[text()='{$campaignTitle}']/../td[1]");
97 $id = (int) $this->getText("//div[@id='campaignList']/div[@id='campaigns_wrapper']/table/tbody/tr/td[text()='{$campaignTitle}']/../td[1]");
98 $this->mailingAddTest($groupName, $campaignTitle, $id);
103 * @param $campaignTitle
106 function mailingAddTest($groupName, $campaignTitle, $id) {
107 //---- create mailing contact and add to mailing Group
108 $firstName = substr(sha1(rand()), 0, 7);
109 $this->webtestAddContact($firstName, "Mailson", "mailino$firstName@mailson.co.in");
111 // go to group tab and add to mailing group
112 $this->click("css=li#tab_group a");
113 $this->waitForElementPresent("_qf_GroupContact_next");
114 $this->select("group_id", "$groupName");
115 $this->click("_qf_GroupContact_next");
117 $this->openCiviPage('mailing/send', 'reset=1', '_qf_Group_cancel');
119 //-------select recipients----------
122 $mailingName = substr(sha1(rand()), 0, 7);
123 $this->type("name", "Mailing $mailingName Webtest");
126 $this->click("campaign_id");
127 $this->select("campaign_id", "value=$id");
129 // Add the test mailing group
130 $this->select("includeGroups-f", "$groupName");
134 $this->click("_qf_Group_next");
135 $this->waitForElementPresent("_qf_Settings_cancel");
137 //--------track and respond----------
139 // check for default settings options
140 $this->assertChecked("url_tracking");
141 $this->assertChecked("open_tracking");
143 // do check count for Recipient
144 $this->assertElementContainsText('crm-container', "Total Recipients: 2");
146 // no need tracking for this test
148 // click next with default settings
149 $this->click("_qf_Settings_next");
150 $this->waitForElementPresent("_qf_Upload_cancel");
152 //--------Mailing content------------
153 // let from email address be default
155 // fill subject for mailing
156 $this->type("subject", "Test subject $mailingName for Webtest");
158 // check for default option enabled
159 $this->assertChecked("CIVICRM_QFID_1_upload_type");
161 // fill message (presently using script for simple text area)
162 $this->click("//fieldset[@id='compose_id']/div[2]/div[1]");
163 $this->type("text_message", "this is test content for Mailing $mailingName Webtest");
167 // default header and footer ( with label )
168 $this->select("header_id", "label=Mailing Header");
169 $this->select("footer_id", "label=Mailing Footer");
171 // do check count for Recipient
172 $this->assertElementContainsText('crm-container', "Total Recipients: 2");
174 // click next with nominal content
175 $this->click("_qf_Upload_upload");
176 $this->waitForElementPresent("_qf_Test_cancel");
178 //---------------Test------------------
180 ////////--Commenting test mailing and mailing preview (test mailing and preview not presently working).
183 //$this->type("test_email", "mailino@mailson.co.in");
184 //$this->click("sendtest");
186 // verify status message
187 //$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 // check mailing preview
190 //$this->click("//form[@id='Test']/div[2]/div[4]/div[1]");
191 //$this->assertTrue($this->isTextPresent("this is test content for Mailing $mailingName Webtest"));
195 // do check count for Recipient
196 $this->assertElementContainsText('crm-container', "Total Recipients: 2");
199 $this->click("_qf_Test_next");
200 $this->waitForElementPresent("_qf_Schedule_cancel");
202 //----------Schedule or Send------------
204 // do check for default option enabled
205 $this->assertChecked("now");
207 // do check count for Recipient
208 $this->assertElementContainsText('crm-container', "Total Recipients: 2");
210 // finally schedule the mail by clicking submit
211 $this->click("_qf_Schedule_next");
212 $this->waitForPageToLoad($this->getTimeoutMsec());
214 //----------end New Mailing-------------
216 //check redirected page to Scheduled and Sent Mailings and verify for mailing name
217 $this->assertElementContainsText('page-title', "Find Mailings");
218 $this->assertElementContainsText('Search', "Mailing $mailingName Webtest");
220 //--------- mail delivery verification---------
222 // test undelivered report
224 // click report link of created mailing
225 $this->click("xpath=//table//tbody/tr[td[1]/text()='Mailing $mailingName Webtest']/descendant::a[text()='Report']");
226 $this->waitForPageToLoad($this->getTimeoutMsec());
228 // verify undelivered status message
229 $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.");
231 // do check for recipient group
232 $this->assertElementContainsText('crm-container', "Members of $groupName");
234 // directly send schedule mailing -- not working right now
235 $this->openCiviPage('mailing/queue', 'reset=1');
237 //click report link of created mailing
238 $this->click("xpath=//table//tbody/tr[td[1]/text()='Mailing $mailingName Webtest']/descendant::a[text()='Report']");
239 $this->waitForPageToLoad($this->getTimeoutMsec());
241 // do check again for recipient group
242 $this->assertElementContainsText('crm-container', "Members of $groupName");
244 // check for 100% delivery
245 $this->assertElementContainsText('crm-container', "2 (100.00%)");
247 // verify intended recipients
248 $this->verifyText("xpath=//table//tr[td/a[text()='Intended Recipients']]/descendant::td[2]", preg_quote("2"));
250 // verify successful deliveries
251 $this->verifyText("xpath=//table//tr[td/a[text()='Successful Deliveries']]/descendant::td[2]", preg_quote("2 (100.00%)"));
254 $this->verifyText("xpath=//table//tr[td[1]/text()='Status']/descendant::td[2]", preg_quote("Complete"));
256 // verify mailing name
257 $this->verifyText("xpath=//table//tr[td[1]/text()='Mailing Name']/descendant::td[2]", preg_quote("Mailing $mailingName Webtest"));
259 // verify mailing subject
260 $this->verifyText("xpath=//table//tr[td[1]/text()='Subject']/descendant::td[2]", preg_quote("Test subject $mailingName for Webtest"));
262 $this->verifyText("xpath=//table//tr[td[1]/text()='Campaign']/descendant::td[2]", preg_quote("$campaignTitle"));
264 //---- check for delivery detail--
266 $this->click("link=Successful Deliveries");
267 $this->waitForPageToLoad($this->getTimeoutMsec());
269 // check for open page
270 $this->assertElementContainsText('page-title', "Successful Deliveries");
273 $this->assertElementContainsText('mailing_event', "mailino$firstName@mailson.co.in");
274 //------end delivery verification---------