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(TRUE);
39 // Enable CiviCampaign module if necessary
40 $this->enableComponents(array('CiviCampaign'));
42 // add the required Drupal permission
43 $permissions = array('edit-2-administer-civicampaign');
44 $this->changePermissions($permissions);
47 $title = substr(sha1(rand()), 0, 7);
48 $groupName = $this->WebtestAddGroup();
51 // We're using Quick Add block on the main page for this.
52 $firstName = substr(sha1(rand()), 0, 7);
53 $this->webtestAddContact($firstName, "Smith", "$firstName.smith@example.org");
55 // add contact to group
57 $this->click("css=li#tab_group a");
58 $this->waitForElementPresent("group_id");
61 $this->select("group_id", "label=$groupName");
62 $this->click("_qf_GroupContact_next");
63 $this->waitForPageToLoad($this->getTimeoutMsec());
65 // Go directly to the URL of the screen that you will be testing
66 $this->openCiviPage('campaign/add', 'reset=1', '_qf_Campaign_upload-bottom');
68 // Let's start filling the form with values.
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->assertElementContainsText('crm-notification-container', "Campaign Campaign $title has been saved.",
95 "Status message didn't show up after saving campaign!"
98 $this->waitForElementPresent("//div[@id='campaignList']/div[@class='dataTables_wrapper']/table/tbody/tr/td[text()='{$campaignTitle}']/../td[1]");
99 $id = (int) $this->getText("//div[@id='campaignList']/div[@class='dataTables_wrapper']/table/tbody/tr/td[text()='{$campaignTitle}']/../td[1]");
100 $this->mailingAddTest($groupName, $campaignTitle, $id);
103 function mailingAddTest($groupName, $campaignTitle, $id) {
104 //---- create mailing contact and add to mailing Group
105 $firstName = substr(sha1(rand()), 0, 7);
106 $this->webtestAddContact($firstName, "Mailson", "mailino$firstName@mailson.co.in");
108 // go to group tab and add to mailing group
109 $this->click("css=li#tab_group a");
110 $this->waitForElementPresent("_qf_GroupContact_next");
111 $this->select("group_id", "$groupName");
112 $this->click("_qf_GroupContact_next");
114 // configure default mail-box
115 $this->openCiviPage('admin/mailSettings', 'action=update&id=1&reset=1', '_qf_MailSettings_cancel-bottom');
116 $this->type('name', 'Test Domain');
117 $this->type('domain', 'example.com');
118 $this->select('protocol', 'value=1');
119 $this->click('_qf_MailSettings_next-bottom');
120 $this->waitForPageToLoad($this->getTimeoutMsec());
122 // Go directly to Schedule and Send Mailing form
123 $this->openCiviPage('mailing/send', 'reset=1', '_qf_Group_cancel');
125 //-------select recipients----------
128 $mailingName = substr(sha1(rand()), 0, 7);
129 $this->type("name", "Mailing $mailingName Webtest");
132 $this->click("campaign_id");
133 $this->select("campaign_id", "value=$id");
135 // Add the test mailing group
136 $this->select("includeGroups-f", "$groupName");
140 $this->click("_qf_Group_next");
141 $this->waitForElementPresent("_qf_Settings_cancel");
143 //--------track and respond----------
145 // check for default settings options
146 $this->assertChecked("url_tracking");
147 $this->assertChecked("open_tracking");
149 // do check count for Recipient
150 $this->assertElementContainsText('crm-container', "Total Recipients: 2");
152 // no need tracking for this test
154 // click next with default settings
155 $this->click("_qf_Settings_next");
156 $this->waitForElementPresent("_qf_Upload_cancel");
158 //--------Mailing content------------
159 // let from email address be default
161 // fill subject for mailing
162 $this->type("subject", "Test subject $mailingName for Webtest");
164 // check for default option enabled
165 $this->assertChecked("CIVICRM_QFID_1_upload_type");
167 // fill message (presently using script for simple text area)
168 $this->click("//fieldset[@id='compose_id']/div[2]/div[1]");
169 $this->type("text_message", "this is test content for Mailing $mailingName Webtest");
173 // default header and footer ( with label )
174 $this->select("header_id", "label=Mailing Header");
175 $this->select("footer_id", "label=Mailing Footer");
177 // do check count for Recipient
178 $this->assertElementContainsText('crm-container', "Total Recipients: 2");
180 // click next with nominal content
181 $this->click("_qf_Upload_upload");
182 $this->waitForElementPresent("_qf_Test_cancel");
184 //---------------Test------------------
186 ////////--Commenting test mailing and mailing preview (test mailing and preview not presently working).
189 //$this->type("test_email", "mailino@mailson.co.in");
190 //$this->click("sendtest");
192 // verify status message
193 //$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)."));
195 // check mailing preview
196 //$this->click("//form[@id='Test']/div[2]/div[4]/div[1]");
197 //$this->assertTrue($this->isTextPresent("this is test content for Mailing $mailingName Webtest"));
201 // do check count for Recipient
202 $this->assertElementContainsText('crm-container', "Total Recipients: 2");
205 $this->click("_qf_Test_next");
206 $this->waitForElementPresent("_qf_Schedule_cancel");
208 //----------Schedule or Send------------
210 // do check for default option enabled
211 $this->assertChecked("now");
213 // do check count for Recipient
214 $this->assertElementContainsText('crm-container', "Total Recipients: 2");
216 // finally schedule the mail by clicking submit
217 $this->click("_qf_Schedule_next");
218 $this->waitForPageToLoad($this->getTimeoutMsec());
220 //----------end New Mailing-------------
222 //check redirected page to Scheduled and Sent Mailings and verify for mailing name
223 $this->assertElementContainsText('page-title', "Scheduled and Sent Mailings");
224 $this->assertElementContainsText('Search', "Mailing $mailingName Webtest");
226 //--------- mail delivery verification---------
228 // test undelivered report
230 // click report link of created mailing
231 $this->click("xpath=//table//tbody/tr[td[1]/text()='Mailing $mailingName Webtest']/descendant::a[text()='Report']");
232 $this->waitForPageToLoad($this->getTimeoutMsec());
234 // verify undelivered status message
235 $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.");
237 // do check for recipient group
238 $this->assertElementContainsText('crm-container', "Members of $groupName");
240 // directly send schedule mailing -- not working right now
241 $this->openCiviPage('mailing/queue', 'reset=1');
243 //click report link of created mailing
244 $this->click("xpath=//table//tbody/tr[td[1]/text()='Mailing $mailingName Webtest']/descendant::a[text()='Report']");
245 $this->waitForPageToLoad($this->getTimeoutMsec());
247 // do check again for recipient group
248 $this->assertElementContainsText('crm-container', "Members of $groupName");
250 // check for 100% delivery
251 $this->assertElementContainsText('crm-container', "2 (100.00%)");
253 // verify intended recipients
254 $this->verifyText("xpath=//table//tr[td/a[text()='Intended Recipients']]/descendant::td[2]", preg_quote("2"));
256 // verify successful deliveries
257 $this->verifyText("xpath=//table//tr[td/a[text()='Successful Deliveries']]/descendant::td[2]", preg_quote("2 (100.00%)"));
260 $this->verifyText("xpath=//table//tr[td[1]/text()='Status']/descendant::td[2]", preg_quote("Complete"));
262 // verify mailing name
263 $this->verifyText("xpath=//table//tr[td[1]/text()='Mailing Name']/descendant::td[2]", preg_quote("Mailing $mailingName Webtest"));
265 // verify mailing subject
266 $this->verifyText("xpath=//table//tr[td[1]/text()='Subject']/descendant::td[2]", preg_quote("Test subject $mailingName for Webtest"));
268 $this->verifyText("xpath=//table//tr[td[1]/text()='Campaign']/descendant::td[2]", preg_quote("$campaignTitle"));
270 //---- check for delivery detail--
272 $this->click("link=Successful Deliveries");
273 $this->waitForPageToLoad($this->getTimeoutMsec());
275 // check for open page
276 $this->assertElementContainsText('page-title', "Successful Deliveries");
279 $this->assertElementContainsText('mailing_event', "mailino$firstName@mailson.co.in");
280 //------end delivery verification---------