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_Mailing_MailingTest
extends CiviSeleniumTestCase
{
31 protected function setUp() {
35 function testAddMailing() {
36 $this->webtestLogin();
38 //----do create test mailing group
40 $this->openCiviPage("group/add", "reset=1", "_qf_Edit_upload");
43 $groupName = 'group_' . substr(sha1(rand()), 0, 7);
46 $this->type("title", $groupName);
49 $this->type("description", "New mailing group for Webtest");
51 // enable Mailing List
52 $this->click("group_type[2]");
54 // select Visibility as Public Pages
55 $this->select("visibility", "value=Public Pages");
58 $this->click("_qf_Edit_upload");
59 $this->waitForPageToLoad($this->getTimeoutMsec());
61 // Is status message correct?
62 $this->assertElementContainsText('crm-notification-container', "The Group '$groupName' has been saved.");
64 //---- create mailing contact and add to mailing Group
65 $firstName = substr(sha1(rand()), 0, 7);
66 $this->webtestAddContact($firstName, "Mailson", "mailino$firstName@mailson.co.in");
68 // Get contact id from url.
70 preg_match('/cid=([0-9]+)/', $this->getLocation(), $matches);
71 $contactId = $matches[1];
73 // go to group tab and add to mailing group
74 $this->click("css=li#tab_group a");
75 $this->waitForElementPresent("_qf_GroupContact_next");
76 $this->select("group_id", "$groupName");
77 $this->click("_qf_GroupContact_next");
78 $this->waitForPageToLoad($this->getTimeoutMsec());
79 $this->waitForElementPresent("_qf_GroupContact_next");
81 // configure default mail-box
82 $this->setupDefaultMailbox();
84 $this->openCiviPage("mailing/send", "reset=1", "_qf_Group_cancel");
86 //-------select recipients----------
89 $mailingName = substr(sha1(rand()), 0, 7);
90 $this->type("name", "Mailing $mailingName Webtest");
92 // Add the test mailing group
93 $this->select("includeGroups-f", "$groupName");
97 $this->click("_qf_Group_next");
98 $this->waitForElementPresent("_qf_Settings_cancel");
100 //--------track and respond----------
102 // check for default settings options
103 $this->assertChecked("url_tracking");
104 $this->assertChecked("open_tracking");
106 // do check count for Recipient
107 $this->assertElementContainsText('css=.messages', "Total Recipients: 1");
109 // no need tracking for this test
111 // click next with default settings
112 $this->click("_qf_Settings_next");
113 $this->waitForElementPresent("_qf_Upload_cancel");
115 //--------Mailing content------------
116 // let from email address be default
118 // fill subject for mailing
119 $this->type("subject", "Test subject {$mailingName} for Webtest");
121 // check for default option enabled
122 $this->assertChecked("CIVICRM_QFID_1_upload_type");
124 // HTML format message
125 $HTMLMessage = "This is HTML formatted content for Mailing {$mailingName} Webtest.";
126 $this->fillRichTextField("html_message", $HTMLMessage);
128 // Open Plain-text Format pane and type text format msg
129 $this->click("//fieldset[@id='compose_id']/div[2]/div[1]");
130 $this->type("text_message", "This is text formatted content for Mailing {$mailingName} Webtest.");
132 // select default header and footer ( with label )
133 $this->select("header_id", "label=Mailing Header");
134 $this->select("footer_id", "label=Mailing Footer");
136 // do check count for Recipient
137 $this->assertElementContainsText('css=.messages', "Total Recipients: 1");
139 // click next with nominal content
140 $this->click("_qf_Upload_upload");
141 $this->waitForElementPresent("_qf_Test_cancel");
143 //---------------Test------------------
145 ////////--Commenting test mailing and mailing preview (test mailing and preview not presently working).
148 //$this->type("test_email", "mailino@mailson.co.in");
149 //$this->click("sendtest");
151 // verify status message
152 //$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)."));
154 // check mailing preview
155 //$this->click("//form[@id='Test']/div[2]/div[4]/div[1]");
156 //$this->assertTrue($this->isTextPresent("this is test content for Mailing $mailingName Webtest"));
160 // do check count for Recipient
161 $this->assertElementContainsText('css=.messages', "Total Recipients: 1");
164 $this->click("_qf_Test_next");
165 $this->waitForElementPresent("_qf_Schedule_cancel");
167 //----------Schedule or Send------------
169 // do check for default option enabled
170 $this->assertChecked("now");
172 // do check count for Recipient
173 $this->assertElementContainsText('css=.messages', "Total Recipients: 1");
175 // finally schedule the mail by clicking submit
176 $this->click("_qf_Schedule_next");
177 $this->waitForPageToLoad($this->getTimeoutMsec());
179 //----------end New Mailing-------------
181 //check redirected page to Scheduled and Sent Mailings and verify for mailing name
182 $this->assertElementContainsText('page-title', "Scheduled and Sent Mailings");
183 $this->assertElementContainsText("xpath=//table[@class='selector']/tbody//tr//td", "Mailing $mailingName Webtest");
185 //--------- mail delivery verification---------
186 // test undelivered report
188 // click report link of created mailing
189 $this->click("xpath=//table//tbody/tr[td[1]/text()='Mailing $mailingName Webtest']/descendant::a[text()='Report']");
190 $this->waitForPageToLoad($this->getTimeoutMsec());
192 // verify undelivered status message
193 $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.");
195 // do check for recipient group
196 $this->assertElementContainsText("xpath=//fieldset/legend[text()='Recipients']/../table/tbody//tr/td", "Members of $groupName");
198 // directly send schedule mailing -- not working right now
199 $this->openCiviPage("mailing/queue", "reset=1");
201 //click report link of created mailing
202 $this->click("xpath=//table//tbody/tr[td[1]/text()='Mailing $mailingName Webtest']/descendant::a[text()='Report']");
203 $this->waitForPageToLoad($this->getTimeoutMsec());
205 // do check again for recipient group
206 $this->assertElementContainsText("xpath=//fieldset/legend[text()='Recipients']/../table/tbody//tr/td", "Members of $groupName");
208 // verify intended recipients
209 $this->verifyText("xpath=//table//tr[td/a[text()='Intended Recipients']]/descendant::td[2]", preg_quote("1"));
211 // verify successful deliveries
212 $this->verifyText("xpath=//table//tr[td/a[text()='Successful Deliveries']]/descendant::td[2]", preg_quote("1 (100.00%)"));
215 $this->verifyText("xpath=//table//tr[td[1]/text()='Status']/descendant::td[2]", preg_quote("Complete"));
217 // verify mailing name
218 $this->verifyText("xpath=//table//tr[td[1]/text()='Mailing Name']/descendant::td[2]", preg_quote("Mailing $mailingName Webtest"));
220 // verify mailing subject
221 $this->verifyText("xpath=//table//tr[td[1]/text()='Subject']/descendant::td[2]", preg_quote("Test subject $mailingName for Webtest"));
223 //---- check for delivery detail--
225 $this->click("link=Successful Deliveries");
226 $this->waitForPageToLoad($this->getTimeoutMsec());
228 // check for open page
229 $this->assertElementContainsText( 'page-title', "Successful Deliveries");
232 $this->verifyText("xpath=//table[@id='mailing_event']/tbody//tr/td[2]", preg_quote("mailino$firstName@mailson.co.in"));
234 $eventQueue = new CRM_Mailing_Event_DAO_Queue();
235 $eventQueue->contact_id
= $contactId;
236 $eventQueue->find(TRUE);
238 $permission = array('edit-1-access-civimail-subscribeunsubscribe-pages');
239 $this->changePermissions($permission);
240 $this->webtestLogout();
243 $forwardUrl = array("mailing/forward", "reset=1&jid={$eventQueue->job_id}&qid={$eventQueue->id}&h={$eventQueue->hash}");
244 $this->openCiviPage($forwardUrl[0], $forwardUrl[1], NULL);
246 $this->type("email_0", substr(sha1(rand()), 0, 7) . '@example.com');
247 $this->type("email_1", substr(sha1(rand()), 0, 7) . '@example.com');
249 $this->click("comment_show");
250 $this->type("forward_comment", "Test Message");
252 $this->click("_qf_ForwardMailing_next-bottom");
253 $this->waitForPageToLoad($this->getTimeoutMsec());
254 $this->assertElementContainsText('css=div.messages', 'Mailing is forwarded successfully to 2 email addresses');
256 $this->waitForPageToLoad($this->getTimeoutMsec());
257 $this->webtestLogin();
259 $this->openCiviPage("mailing/browse/scheduled", "reset=1&scheduled=true");
261 //click report link of created mailing
262 $this->click("xpath=//table//tbody/tr[td[1]/text()='Mailing $mailingName Webtest']/descendant::a[text()='Report']");
263 $this->waitForPageToLoad($this->getTimeoutMsec());
265 // verify successful forwards
266 $this->verifyText("xpath=//table//tr[td/a[text()='Forwards']]/descendant::td[2]", "2");
268 // Mailing is forwarded successfully to 2 email addresses.
269 //------end delivery verification---------
271 // //------ check with unsubscribe -------
272 // // FIX ME: there is an issue with DSN setting for Webtest, need to handle by seperate DSN setting for Webtests
273 // // build unsubscribe link
274 // require_once 'CRM/Mailing/Event/DAO/Queue.php';
275 // $eventQueue = new CRM_Mailing_Event_DAO_Queue( );
276 // $eventQueue->contact_id = $contactId;
277 // $eventQueue->find(true);
279 // // unsubscribe link
280 // $unsubscribeUrl = "civicrm/mailing/optout?reset=1&jid={$eventQueue->job_id}&qid={$eventQueue->id}&h={$eventQueue->hash}&confirm=1";
282 // // logout to unsubscribe
283 // $this->webtestLogout();
285 // // click(visit) unsubscribe path
286 // $this->open($this->sboxPath . $unsubscribeUrl);
287 // $this->waitForPageToLoad($this->getTimeoutMsec());
289 // $this->assertTrue($this->isTextPresent('Optout'));
290 // $this->assertTrue($this->isTextPresent("mailino$firstName@mailson.co.in"));
293 // $this->click('_qf_optout_next');
294 // $this->waitForPageToLoad($this->getTimeoutMsec());
296 // $this->assertTrue($this->isTextPresent('Optout'));
297 // $this->assertTrue($this->isTextPresent("mailino$firstName@mailson.co.in"));
298 // $this->assertTrue($this->isTextPresent('has been successfully opted out.'));
300 // //------ end unsubscribe -------
303 function testAdvanceSearchAndReportCheck() {
305 $this->webtestLogin();
307 $this->openCiviPage("group/add", "reset=1", "_qf_Edit_upload");
310 $groupName = 'group_' . substr(sha1(rand()), 0, 7);
313 $this->type("title", $groupName);
316 $this->type("description", "New mailing group for Webtest");
318 // enable Mailing List
319 $this->click("group_type[2]");
321 // select Visibility as Public Pages
322 $this->select("visibility", "value=Public Pages");
325 $this->click("_qf_Edit_upload");
326 $this->waitForPageToLoad($this->getTimeoutMsec());
328 // Is status message correct?
329 $this->assertElementContainsText('crm-notification-container', "The Group '$groupName' has been saved.");
331 //---- create mailing contact and add to mailing Group
332 $firstName = substr(sha1(rand()), 0, 7);
333 $this->webtestAddContact($firstName, "Mailson", "mailino$firstName@mailson.co.in");
335 // Get contact id from url.
337 preg_match('/cid=([0-9]+)/', $this->getLocation(), $matches);
338 $contactId = $matches[1];
340 // go to group tab and add to mailing group
341 $this->click("css=li#tab_group a");
342 $this->waitForElementPresent("_qf_GroupContact_next");
343 $this->select("group_id", "$groupName");
344 $this->click("_qf_GroupContact_next");
345 $this->waitForPageToLoad($this->getTimeoutMsec());
346 $this->waitForElementPresent("_qf_GroupContact_next");
348 // configure default mail-box
349 $this->openCiviPage("admin/mailSettings", "action=update&id=1&reset=1", '_qf_MailSettings_cancel-bottom');
350 $this->type('name', 'Test Domain');
351 $this->type('domain', 'example.com');
352 $this->select('protocol', 'value=1');
353 $this->click('_qf_MailSettings_next-bottom');
354 $this->waitForPageToLoad($this->getTimeoutMsec());
356 // Go to Schedule and Send Mailing form
357 $this->openCiviPage('mailing/send', 'reset=1', '_qf_Group_cancel');
359 //-------select recipients----------
362 $mailingName = substr(sha1(rand()), 0, 7);
363 $this->type("name", "Mailing $mailingName Webtest");
365 // Add the test mailing group
366 $this->select("includeGroups-f", "$groupName");
370 $this->click("_qf_Group_next");
371 $this->waitForElementPresent("_qf_Settings_cancel");
373 //--------track and respond----------
375 // check for default settings options
376 $this->assertChecked("url_tracking");
377 $this->assertChecked("open_tracking");
379 // do check count for Recipient
380 $this->assertElementContainsText('css=.messages', "Total Recipients: 1");
382 // click next with default settings
383 $this->click("_qf_Settings_next");
384 $this->waitForElementPresent("_qf_Upload_cancel");
386 // fill subject for mailing
387 $this->type("subject", "Test subject {$mailingName} for Webtest");
389 // check for default option enabled
390 $this->assertChecked("CIVICRM_QFID_1_upload_type");
392 // HTML format message
393 $HTMLMessage = "This is HTML formatted content for Mailing {$mailingName} Webtest.";
394 $this->fillRichTextField("html_message", $HTMLMessage);
396 // Open Plain-text Format pane and type text format msg
397 $this->click("//fieldset[@id='compose_id']/div[2]/div[1]");
398 $this->type("text_message", "This is text formatted content for Mailing {$mailingName} Webtest.");
400 // select default header and footer ( with label )
401 $this->select("header_id", "label=Mailing Header");
402 $this->select("footer_id", "label=Mailing Footer");
404 // do check count for Recipient
405 $this->assertElementContainsText('css=.messages', "Total Recipients: 1");
407 // click next with nominal content
408 $this->click("_qf_Upload_upload");
409 $this->waitForElementPresent("_qf_Test_cancel");
411 // do check count for Recipient
412 $this->assertElementContainsText('css=.messages', "Total Recipients: 1");
415 $this->click("_qf_Test_next");
416 $this->waitForElementPresent("_qf_Schedule_cancel");
418 //----------Schedule or Send------------
420 // do check for default option enabled
421 $this->assertChecked("now");
423 // do check count for Recipient
424 $this->assertElementContainsText('css=.messages', "Total Recipients: 1");
426 // finally schedule the mail by clicking submit
427 $this->click("_qf_Schedule_next");
428 $this->waitForPageToLoad($this->getTimeoutMsec());
430 //----------end New Mailing-------------
432 //check redirected page to Scheduled and Sent Mailings and verify for mailing name
433 $this->assertElementContainsText('page-title', "Scheduled and Sent Mailings");
434 $this->assertElementContainsText("xpath=//table[@class='selector']/tbody//tr//td", "Mailing $mailingName Webtest");
436 // directly send schedule mailing -- not working right now
437 $this->openCiviPage("mailing/queue", "reset=1");
439 //click report link of created mailing
440 $this->click("xpath=//table//tbody/tr[td[1]/text()='Mailing $mailingName Webtest']/descendant::a[text()='Report']");
441 $this->waitForPageToLoad($this->getTimeoutMsec());
443 $mailingReportUrl = $this->getLocation();
444 // do check again for recipient group
445 $this->assertElementContainsText("xpath=//fieldset/legend[text()='Recipients']/../table/tbody//tr/td", "Members of $groupName");
447 // verify successful deliveries
448 $this->verifyText("xpath=//table//tr[td/a[text()='Successful Deliveries']]/descendant::td[2]", preg_quote("1 (100.00%)"));
450 $summaryInfoLinks = array('Intended Recipients', 'Successful Deliveries', 'Tracked Opens', 'Click-throughs', 'Forwards', 'Replies', 'Bounces', 'Unsubscribe Requests','Opt-out Requests');
452 //check for report and adv search links
453 foreach($summaryInfoLinks as $value) {
454 $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}");
455 $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}");
457 // verify mailing name
458 $this->verifyText("xpath=//table//tr[td[1]/text()='Mailing Name']/descendant::td[2]", preg_quote("Mailing $mailingName Webtest"));
460 // verify mailing subject
461 $this->verifyText("xpath=//table//tr[td[1]/text()='Subject']/descendant::td[2]", preg_quote("Test subject $mailingName for Webtest"));
463 // after asserts do clicks and confirm filters
466 'Intended Recipients' =>
468 'report' => array('report_name' => 'Mailing Details', 'Mailing' => "Mailing $mailingName Webtest"),
469 'search' => array('Mailing Name IN' => "\"Mailing {$mailingName} Webtest")
471 'Successful Deliveries' =>
473 'report' => array('report_name' => 'Mailing Details', 'Mailing' => "Mailing $mailingName Webtest",
474 "Delivery Status" => " Successful"),
475 'search' => array('Mailing Name IN' => "\"Mailing {$mailingName} Webtest", 'Mailing Delivery -' => "Successful")
479 'report' => array('report_name' => 'Mail Opened', 'Mailing' => "Mailing $mailingName Webtest"),
480 'search' => array('Mailing Name IN' => "\"Mailing {$mailingName} Webtest", 'Mailing: Trackable Opens -' => "Opened")
484 'report' => array('report_name' => 'Mail Clickthroughs', 'Mailing' => "Mailing $mailingName Webtest"),
485 'search' => array('Mailing Name IN' => "\"Mailing {$mailingName} Webtest", 'Mailing: Trackable URL Clicks -' => "Clicked")
489 'report' => array('report_name' => 'Mailing Details', 'Mailing' => "Mailing $mailingName Webtest",
490 'Forwarded' => 'Is equal to Yes'),
491 'search' => array('Mailing Name IN' => "\"Mailing {$mailingName} Webtest", 'Mailing: -' => "Forwards")
495 'report' => array('report_name' => 'Mailing Details', 'Mailing' => "Mailing $mailingName Webtest",
496 'Replied' => 'Is equal to Yes'),
497 'search' => array('Mailing Name IN' => "\"Mailing {$mailingName} Webtest", 'Mailing: Trackable Replies -' => "Replied")
501 'report' => array('report_name' => 'Mail Bounces', 'Mailing' => "Mailing $mailingName Webtest"),
502 'search' => array('Mailing Name IN' => "\"Mailing {$mailingName} Webtest", 'Mailing Delivery -' => "Bounced")
504 'Unsubscribe Requests' =>
506 'report' => array('report_name' => 'Mailing Details', 'Mailing' => "Mailing $mailingName Webtest",
507 'Unsubscribed' => 'Is equal to Yes'),
508 'search' => array('Mailing Name IN' => "\"Mailing {$mailingName} Webtest", 'Mailing: -' => "Unsubscribe Requests")
510 'Opt-out Requests' =>
512 'report' => array('report_name' => 'Mailing Details', 'Mailing' => "Mailing $mailingName Webtest",
513 'Opted-out' => 'Is equal to Yes'),
514 'search' => array('Mailing Name IN' => "\"Mailing {$mailingName} Webtest", 'Mailing: -' => "Opt-out Requests")
517 $this->criteriaCheck($criteriaCheck, $mailingReportUrl);
520 function criteriaCheck($criteriaCheck, $mailingReportUrl) {
521 foreach($criteriaCheck as $key => $infoFilter) {
522 foreach($infoFilter as $entity => $dataToCheck) {
523 $this->open($mailingReportUrl);
524 if ($entity == "report") {
525 $this->click("xpath=//fieldset/legend[text()='Delivery Summary']/../table//tr[td/a[text()='{$key}']]/descendant::td[3]/span/a[1][text()='Report']");
527 $this->click("xpath=//fieldset/legend[text()='Delivery Summary']/../table//tr[td/a[text()='{$key}']]/descendant::td[3]/span/a[2][text()='Advanced Search']");
529 $this->waitForPageToLoad($this->getTimeoutMsec());
530 $this-> _verifyCriteria($key, $dataToCheck, $entity);
535 function _verifyCriteria($summaryInfo, $dataToCheck, $entity) {
536 foreach($dataToCheck as $key => $value) {
537 if ($entity == 'report') {
538 if ($key == 'report_name') {
539 $this->assertElementContainsText('page-title', "{$value}");
542 $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}");
544 $this->assertElementContainsText('page-title', "Advanced Search");
545 $assertedValue = $this->isElementPresent("xpath=//div[@class='crm-results-block']//div[@class='qill'][contains(text(),'{$key} {$value}')]");
546 if (!$assertedValue) {
547 $assertedValue = $this->isTextPresent("{$key} {$value}");
549 $this->assertTrue($assertedValue,"Criteria check for {$key} failed for Advance Search for {$summaryInfo}");