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_Mailing_MailingTest
extends CiviSeleniumTestCase
{
30 protected function setUp() {
34 function testAddMailing() {
35 $this->webtestLogin();
37 //----do create test mailing group
38 $this->openCiviPage("group/add", "reset=1", "_qf_Edit_upload");
41 $groupName = 'group_' . substr(sha1(rand()), 0, 7);
44 $this->type("title", $groupName);
47 $this->type("description", "New mailing group for Webtest");
49 // enable Mailing List
50 $this->click("group_type[2]");
52 // select Visibility as Public Pages
53 $this->select("visibility", "value=Public Pages");
56 $this->clickLink("_qf_Edit_upload");
58 // Is status message correct?
59 $this->waitForText('crm-notification-container', "The Group '$groupName' has been saved.");
61 //---- create mailing contact and add to mailing Group
62 $firstName = substr(sha1(rand()), 0, 7);
63 $this->webtestAddContact($firstName, "Mailson", "mailino$firstName@mailson.co.in");
65 // Get contact id from url.
66 $contactId = $this->urlArg('cid');
68 // go to group tab and add to mailing group
69 $this->click("css=li#tab_group a");
70 $this->waitForElementPresent("_qf_GroupContact_next");
71 $this->select("group_id", "$groupName");
72 $this->clickLink("_qf_GroupContact_next", "_qf_GroupContact_next", FALSE);
74 // configure default mail-box
75 $this->setupDefaultMailbox();
77 $this->openCiviPage("mailing/send", "reset=1", "_qf_Group_cancel");
79 //-------select recipients----------
82 $mailingName = substr(sha1(rand()), 0, 7);
83 $this->type("name", "Mailing $mailingName Webtest");
85 // Add the test mailing group
86 $this->select("includeGroups-f", "$groupName");
90 $this->clickLink("_qf_Group_next", "_qf_Settings_cancel", FALSE);
92 //--------track and respond----------
94 // check for default settings options
95 $this->assertChecked("url_tracking");
96 $this->assertChecked("open_tracking");
98 // do check count for Recipient
99 $this->assertElementContainsText('css=.messages', "Total Recipients: 1");
101 // no need tracking for this test
103 // click next with default settings
104 $this->clickLink("_qf_Settings_next", "_qf_Upload_cancel");
106 //--------Mailing content------------
107 // let from email address be default
109 // fill subject for mailing
110 $this->type("subject", "Test subject {$mailingName} for Webtest");
112 // check for default option enabled
113 $this->assertChecked("CIVICRM_QFID_1_upload_type");
115 // HTML format message
116 $HTMLMessage = "This is HTML formatted content for Mailing {$mailingName} Webtest.";
117 $this->fillRichTextField("html_message", $HTMLMessage);
119 // Open Plain-text Format pane and type text format msg
120 $this->click("//fieldset[@id='compose_id']/div[2]/div[1]");
121 $this->type("text_message", "This is text formatted content for Mailing {$mailingName} Webtest.");
123 // select default header and footer ( with label )
124 $this->select("header_id", "label=Mailing Header");
125 $this->select("footer_id", "label=Mailing Footer");
127 // do check count for Recipient
128 $this->assertElementContainsText('css=.messages', "Total Recipients: 1");
130 // click next with nominal content
131 $this->clickLink("_qf_Upload_upload", "_qf_Test_cancel");
133 //---------------Test------------------
135 ////////--Commenting test mailing and mailing preview (test mailing and preview not presently working).
138 //$this->type("test_email", "mailino@mailson.co.in");
139 //$this->click("sendtest");
141 // verify status message
142 //$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)."));
144 // check mailing preview
145 //$this->click("//form[@id='Test']/div[2]/div[4]/div[1]");
146 //$this->assertTrue($this->isTextPresent("this is test content for Mailing $mailingName Webtest"));
150 // do check count for Recipient
151 $this->assertElementContainsText('css=.messages', "Total Recipients: 1");
154 $this->clickLink("_qf_Test_next", "_qf_Schedule_cancel");
156 //----------Schedule or Send------------
158 // do check for default option enabled
159 $this->assertChecked("now");
161 // do check count for Recipient
162 $this->assertElementContainsText('css=.messages', "Total Recipients: 1");
164 // finally schedule the mail by clicking submit
165 $this->clickLink("_qf_Schedule_next");
167 //----------end New Mailing-------------
169 //check redirected page to Scheduled and Sent Mailings and verify for mailing name
170 $this->assertElementContainsText('page-title', "Find Mailings");
171 $this->assertElementContainsText("xpath=//table[@class='selector row-highlight']/tbody//tr//td", "Mailing $mailingName Webtest");
173 //--------- mail delivery verification---------
174 // test undelivered report
176 // click report link of created mailing
177 $this->clickLink("xpath=//table//tbody/tr[td[1]/text()='Mailing $mailingName Webtest']/descendant::a[text()='Report']");
179 // verify undelivered status message
180 $this->assertElementContainsText('css=.messages', "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.");
182 // do check for recipient group
183 $this->assertElementContainsText("xpath=//fieldset/legend[text()='Recipients']/../table/tbody//tr/td", "Members of $groupName");
185 // directly send schedule mailing -- not working right now
186 $this->openCiviPage("mailing/queue", "reset=1");
188 //click report link of created mailing
189 $this->clickLink("xpath=//table//tbody/tr[td[1]/text()='Mailing $mailingName Webtest']/descendant::a[text()='Report']");
191 // do check again for recipient group
192 $this->assertElementContainsText("xpath=//fieldset/legend[text()='Recipients']/../table/tbody//tr/td", "Members of $groupName");
194 // verify intended recipients
195 $this->verifyText("xpath=//table//tr[td/a[text()='Intended Recipients']]/descendant::td[2]", preg_quote("1"));
197 // verify successful deliveries
198 $this->verifyText("xpath=//table//tr[td/a[text()='Successful Deliveries']]/descendant::td[2]", preg_quote("1 (100.00%)"));
201 $this->verifyText("xpath=//table//tr[td[1]/text()='Status']/descendant::td[2]", preg_quote("Complete"));
203 // verify mailing name
204 $this->verifyText("xpath=//table//tr[td[1]/text()='Mailing Name']/descendant::td[2]", preg_quote("Mailing $mailingName Webtest"));
206 // verify mailing subject
207 $this->verifyText("xpath=//table//tr[td[1]/text()='Subject']/descendant::td[2]", preg_quote("Test subject $mailingName for Webtest"));
209 //---- check for delivery detail--
211 $this->clickLink("link=Successful Deliveries");
213 // check for open page
214 $this->assertElementContainsText( 'page-title', "Successful Deliveries");
217 $this->verifyText("xpath=//table[@id='mailing_event']/tbody//tr/td[2]", preg_quote("mailino$firstName@mailson.co.in"));
219 $eventQueue = new CRM_Mailing_Event_DAO_Queue();
220 $eventQueue->contact_id
= $contactId;
221 $eventQueue->find(TRUE);
223 $permission = array('edit-1-access-civimail-subscribeunsubscribe-pages');
224 $this->changePermissions($permission);
225 $this->webtestLogout();
228 $forwardUrl = array("mailing/forward", "reset=1&jid={$eventQueue->job_id}&qid={$eventQueue->id}&h={$eventQueue->hash}");
229 $this->openCiviPage($forwardUrl[0], $forwardUrl[1], NULL);
231 $this->type("email_0", substr(sha1(rand()), 0, 7) . '@example.com');
232 $this->type("email_1", substr(sha1(rand()), 0, 7) . '@example.com');
234 $this->click("comment_show");
235 $this->type("forward_comment", "Test Message");
237 $this->click("_qf_ForwardMailing_next-bottom");
238 $this->waitForPageToLoad($this->getTimeoutMsec());
239 $this->assertElementContainsText('css=div.messages', 'Mailing is forwarded successfully to 2 email addresses');
241 $this->webtestLogin();
243 $this->openCiviPage("mailing/browse/scheduled", "reset=1&scheduled=true");
245 //click report link of created mailing
246 $this->clickLink("xpath=//table//tbody/tr[td[1]/text()='Mailing $mailingName Webtest']/descendant::a[text()='Report']");
248 // verify successful forwards
249 $this->verifyText("xpath=//table//tr[td/a[text()='Forwards']]/descendant::td[2]", "2");
251 // Mailing is forwarded successfully to 2 email addresses.
252 //------end delivery verification---------
254 // //------ check with unsubscribe -------
255 // // FIX ME: there is an issue with DSN setting for Webtest, need to handle by seperate DSN setting for Webtests
256 // // build unsubscribe link
257 // require_once 'CRM/Mailing/Event/DAO/Queue.php';
258 // $eventQueue = new CRM_Mailing_Event_DAO_Queue( );
259 // $eventQueue->contact_id = $contactId;
260 // $eventQueue->find(true);
262 // // unsubscribe link
263 // $unsubscribeUrl = "civicrm/mailing/optout?reset=1&jid={$eventQueue->job_id}&qid={$eventQueue->id}&h={$eventQueue->hash}&confirm=1";
265 // // logout to unsubscribe
266 // $this->webtestLogout();
268 // // click(visit) unsubscribe path
269 // $this->open($this->sboxPath . $unsubscribeUrl);
270 // $this->waitForPageToLoad($this->getTimeoutMsec());
272 // $this->assertTrue($this->isTextPresent('Optout'));
273 // $this->assertTrue($this->isTextPresent("mailino$firstName@mailson.co.in"));
276 // $this->click('_qf_optout_next');
277 // $this->waitForPageToLoad($this->getTimeoutMsec());
279 // $this->assertTrue($this->isTextPresent('Optout'));
280 // $this->assertTrue($this->isTextPresent("mailino$firstName@mailson.co.in"));
281 // $this->assertTrue($this->isTextPresent('has been successfully opted out.'));
283 // //------ end unsubscribe -------
286 function testAdvanceSearchAndReportCheck() {
288 $this->webtestLogin();
290 $this->openCiviPage("group/add", "reset=1", "_qf_Edit_upload");
293 $groupName = 'group_' . substr(sha1(rand()), 0, 7);
296 $this->type("title", $groupName);
299 $this->type("description", "New mailing group for Webtest");
301 // enable Mailing List
302 $this->click("group_type[2]");
304 // select Visibility as Public Pages
305 $this->select("visibility", "value=Public Pages");
308 $this->clickLink("_qf_Edit_upload");
310 // Is status message correct?
311 $this->waitForText('crm-notification-container', "The Group '$groupName' has been saved.");
313 //---- create mailing contact and add to mailing Group
314 $firstName = substr(sha1(rand()), 0, 7);
315 $this->webtestAddContact($firstName, "Mailson", "mailino$firstName@mailson.co.in");
317 // Get contact id from url.
318 $contactId = $this->urlArg('cid');
320 // go to group tab and add to mailing group
321 $this->click("css=li#tab_group a");
322 $this->waitForElementPresent("_qf_GroupContact_next");
323 $this->select("group_id", "$groupName");
324 $this->clickLink("_qf_GroupContact_next", "_qf_GroupContact_next", FALSE);
326 // configure default mail-box
327 $this->openCiviPage("admin/mailSettings", "action=update&id=1&reset=1", '_qf_MailSettings_cancel-bottom');
328 $this->type('name', 'Test Domain');
329 $this->type('domain', 'example.com');
330 $this->select('protocol', 'value=1');
331 $this->clickLink('_qf_MailSettings_next-bottom');
333 // Go to Schedule and Send Mailing form
334 $this->openCiviPage('mailing/send', 'reset=1', '_qf_Group_cancel');
336 //-------select recipients----------
339 $mailingName = substr(sha1(rand()), 0, 7);
340 $this->type("name", "Mailing $mailingName Webtest");
342 // Add the test mailing group
343 $this->select("includeGroups-f", "$groupName");
347 $this->click("_qf_Group_next");
348 $this->waitForElementPresent("_qf_Settings_cancel");
350 //--------track and respond----------
352 // check for default settings options
353 $this->assertChecked("url_tracking");
354 $this->assertChecked("open_tracking");
356 // do check count for Recipient
357 $this->assertElementContainsText('css=.messages', "Total Recipients: 1");
359 // click next with default settings
360 $this->clickLink("_qf_Settings_next");
362 // fill subject for mailing
363 $this->type("subject", "Test subject {$mailingName} for Webtest");
365 // check for default option enabled
366 $this->assertChecked("CIVICRM_QFID_1_upload_type");
368 // HTML format message
369 $HTMLMessage = "This is HTML formatted content for Mailing {$mailingName} Webtest.";
370 $this->fillRichTextField("html_message", $HTMLMessage);
372 // Open Plain-text Format pane and type text format msg
373 $this->click("//fieldset[@id='compose_id']/div[2]/div[1]");
374 $this->type("text_message", "This is text formatted content for Mailing {$mailingName} Webtest.");
376 // select default header and footer ( with label )
377 $this->select("header_id", "label=Mailing Header");
378 $this->select("footer_id", "label=Mailing Footer");
380 // do check count for Recipient
381 $this->assertElementContainsText('css=.messages', "Total Recipients: 1");
383 // click next with nominal content
384 $this->clickLink("_qf_Upload_upload", "_qf_Test_cancel");
386 // do check count for Recipient
387 $this->assertElementContainsText('css=.messages', "Total Recipients: 1");
390 $this->clickLink("_qf_Test_next", "_qf_Schedule_cancel");
392 //----------Schedule or Send------------
394 // do check for default option enabled
395 $this->assertChecked("now");
397 // do check count for Recipient
398 $this->assertElementContainsText('css=.messages', "Total Recipients: 1");
400 // finally schedule the mail by clicking submit
401 $this->clickLink("_qf_Schedule_next");
403 //----------end New Mailing-------------
405 //check redirected page to Scheduled and Sent Mailings and verify for mailing name
406 $this->assertElementContainsText('page-title', "Find Mailings");
407 $this->assertElementContainsText("xpath=//table[@class='selector row-highlight']/tbody//tr//td", "Mailing $mailingName Webtest");
409 // directly send schedule mailing -- not working right now
410 $this->openCiviPage("mailing/queue", "reset=1");
412 //click report link of created mailing
413 $this->clickLink("xpath=//table//tbody/tr[td[1]/text()='Mailing $mailingName Webtest']/descendant::a[text()='Report']");
415 $mailingReportUrl = $this->getLocation();
416 // do check again for recipient group
417 $this->assertElementContainsText("xpath=//fieldset/legend[text()='Recipients']/../table/tbody//tr/td", "Members of $groupName");
419 // verify successful deliveries
420 $this->verifyText("xpath=//table//tr[td/a[text()='Successful Deliveries']]/descendant::td[2]", preg_quote("1 (100.00%)"));
422 $summaryInfoLinks = array('Intended Recipients', 'Successful Deliveries', 'Tracked Opens', 'Click-throughs', 'Forwards', 'Replies', 'Bounces', 'Unsubscribe Requests','Opt-out Requests');
424 //check for report and adv search links
425 foreach($summaryInfoLinks as $value) {
426 $this->assertTrue($this->isElementPresent("xpath=//fieldset/legend[text()='Delivery Summary']/../table//tr[td/a[text()='{$value}']]/descendant::td[3]/span/a[1][text()='Report']"), "Report link missing for {$value}");
427 $this->assertTrue($this->isElementPresent("xpath=//fieldset/legend[text()='Delivery Summary']/../table//tr[td/a[text()='{$value}']]/descendant::td[3]/span/a[2][text()='Advanced Search']"), "Advance Search link missing for {$value}");
429 // verify mailing name
430 $this->verifyText("xpath=//table//tr[td[1]/text()='Mailing Name']/descendant::td[2]", preg_quote("Mailing $mailingName Webtest"));
432 // verify mailing subject
433 $this->verifyText("xpath=//table//tr[td[1]/text()='Subject']/descendant::td[2]", preg_quote("Test subject $mailingName for Webtest"));
435 // after asserts do clicks and confirm filters
438 'Intended Recipients' =>
440 'report' => array('report_name' => 'Mailing Details', 'Mailing' => "Mailing $mailingName Webtest"),
441 'search' => array('Mailing Name IN' => "\"Mailing {$mailingName} Webtest")
443 'Successful Deliveries' =>
445 'report' => array('report_name' => 'Mailing Details', 'Mailing' => "Mailing $mailingName Webtest",
446 "Delivery Status" => " Successful"),
447 'search' => array('Mailing Name IN' => "\"Mailing {$mailingName} Webtest", 'Mailing Delivery -' => "Successful")
451 'report' => array('report_name' => 'Mail Opened', 'Mailing' => "Mailing $mailingName Webtest"),
452 'search' => array('Mailing Name IN' => "\"Mailing {$mailingName} Webtest", 'Mailing: Trackable Opens -' => "Opened")
456 'report' => array('report_name' => 'Mail Clickthroughs', 'Mailing' => "Mailing $mailingName Webtest"),
457 'search' => array('Mailing Name IN' => "\"Mailing {$mailingName} Webtest", 'Mailing: Trackable URL Clicks -' => "Clicked")
461 'report' => array('report_name' => 'Mailing Details', 'Mailing' => "Mailing $mailingName Webtest",
462 'Forwarded' => 'Is equal to Yes'),
463 'search' => array('Mailing Name IN' => "\"Mailing {$mailingName} Webtest", 'Mailing: -' => "Forwards")
467 'report' => array('report_name' => 'Mailing Details', 'Mailing' => "Mailing $mailingName Webtest",
468 'Replied' => 'Is equal to Yes'),
469 'search' => array('Mailing Name IN' => "\"Mailing {$mailingName} Webtest", 'Mailing: Trackable Replies -' => "Replied")
473 'report' => array('report_name' => 'Mail Bounces', 'Mailing' => "Mailing $mailingName Webtest"),
474 'search' => array('Mailing Name IN' => "\"Mailing {$mailingName} Webtest", 'Mailing Delivery -' => "Bounced")
476 'Unsubscribe Requests' =>
478 'report' => array('report_name' => 'Mailing Details', 'Mailing' => "Mailing $mailingName Webtest",
479 'Unsubscribed' => 'Is equal to Yes'),
480 'search' => array('Mailing Name IN' => "\"Mailing {$mailingName} Webtest", 'Mailing: -' => "Unsubscribe Requests")
482 'Opt-out Requests' =>
484 'report' => array('report_name' => 'Mailing Details', 'Mailing' => "Mailing $mailingName Webtest",
485 'Opted-out' => 'Is equal to Yes'),
486 'search' => array('Mailing Name IN' => "\"Mailing {$mailingName} Webtest", 'Mailing: -' => "Opt-out Requests")
489 $this->criteriaCheck($criteriaCheck, $mailingReportUrl);
492 function criteriaCheck($criteriaCheck, $mailingReportUrl) {
493 foreach($criteriaCheck as $key => $infoFilter) {
494 foreach($infoFilter as $entity => $dataToCheck) {
495 $this->open($mailingReportUrl);
496 if ($entity == "report") {
497 $this->clickLink("xpath=//fieldset/legend[text()='Delivery Summary']/../table//tr[td/a[text()='{$key}']]/descendant::td[3]/span/a[1][text()='Report']");
499 $this->clickLink("xpath=//fieldset/legend[text()='Delivery Summary']/../table//tr[td/a[text()='{$key}']]/descendant::td[3]/span/a[2][text()='Advanced Search']");
501 $this-> _verifyCriteria($key, $dataToCheck, $entity);
506 function _verifyCriteria($summaryInfo, $dataToCheck, $entity) {
507 foreach($dataToCheck as $key => $value) {
508 if ($entity == 'report') {
509 if ($key == 'report_name') {
510 $this->assertElementContainsText('page-title', "{$value}");
513 $this->assertTrue($this->isElementPresent("xpath=//form//div[3]/table/tbody//tr/th[contains(text(),'{$key}')]/../td[contains(text(),'{$value}')]"),"Criteria check for {$key} failed for Report for {$summaryInfo}");
515 $this->assertElementContainsText('page-title', "Advanced Search");
516 $assertedValue = $this->isElementPresent("xpath=//div[@class='crm-results-block']//div[@class='qill'][contains(text(),'{$key} {$value}')]");
517 if (!$assertedValue) {
518 $assertedValue = $this->isTextPresent("{$key} {$value}");
520 $this->assertTrue($assertedValue,"Criteria check for {$key} failed for Advance Search for {$summaryInfo}");