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->open($this->sboxPath
);
37 $this->webtestLogin();
39 //----do create test mailing group
41 // Go directly to the URL of the screen that you will be testing (New Group).
42 $this->openCiviPage("group/add", "reset=1", "_qf_Edit_upload");
45 $groupName = 'group_' . substr(sha1(rand()), 0, 7);
48 $this->type("title", $groupName);
51 $this->type("description", "New mailing group for Webtest");
53 // enable Mailing List
54 $this->click("group_type[2]");
56 // select Visibility as Public Pages
57 $this->select("visibility", "value=Public Pages");
60 $this->click("_qf_Edit_upload");
61 $this->waitForPageToLoad($this->getTimeoutMsec());
63 // Is status message correct?
64 $this->assertElementContainsText('crm-notification-container', "The Group '$groupName' has been saved.");
66 //---- create mailing contact and add to mailing Group
67 $firstName = substr(sha1(rand()), 0, 7);
68 $this->webtestAddContact($firstName, "Mailson", "mailino$firstName@mailson.co.in");
70 // Get contact id from url.
72 preg_match('/cid=([0-9]+)/', $this->getLocation(), $matches);
73 $contactId = $matches[1];
75 // go to group tab and add to mailing group
76 $this->click("css=li#tab_group a");
77 $this->waitForElementPresent("_qf_GroupContact_next");
78 $this->select("group_id", "$groupName");
79 $this->click("_qf_GroupContact_next");
80 $this->waitForPageToLoad($this->getTimeoutMsec());
81 $this->waitForElementPresent("_qf_GroupContact_next");
83 // configure default mail-box
84 $this->openCiviPage("admin/mailSettings", "action=update&id=1&reset=1", '_qf_MailSettings_cancel-bottom');
85 $this->type('name', 'Test Domain');
86 $this->type('domain', 'example.com');
87 $this->select('protocol', 'value=1');
88 $this->click('_qf_MailSettings_next-bottom');
89 $this->waitForPageToLoad($this->getTimeoutMsec());
91 // Go directly to Schedule and Send Mailing form
92 $this->openCiviPage("mailing/send", "reset=1", "_qf_Group_cancel");
94 //-------select recipients----------
97 $mailingName = substr(sha1(rand()), 0, 7);
98 $this->type("name", "Mailing $mailingName Webtest");
100 // Add the test mailing group
101 $this->select("includeGroups-f", "$groupName");
105 $this->click("_qf_Group_next");
106 $this->waitForElementPresent("_qf_Settings_cancel");
108 //--------track and respond----------
110 // check for default settings options
111 $this->assertChecked("url_tracking");
112 $this->assertChecked("open_tracking");
114 // do check count for Recipient
115 $this->assertElementContainsText('css=.messages', "Total Recipients: 1");
117 // no need tracking for this test
119 // click next with default settings
120 $this->click("_qf_Settings_next");
121 $this->waitForElementPresent("_qf_Upload_cancel");
123 //--------Mailing content------------
124 // let from email address be default
126 // fill subject for mailing
127 $this->type("subject", "Test subject {$mailingName} for Webtest");
129 // check for default option enabled
130 $this->assertChecked("CIVICRM_QFID_1_upload_type");
132 // HTML format message
133 $HTMLMessage = "This is HTML formatted content for Mailing {$mailingName} Webtest.";
134 $this->fillRichTextField("html_message", $HTMLMessage);
136 // Open Plain-text Format pane and type text format msg
137 $this->click("//fieldset[@id='compose_id']/div[2]/div[1]");
138 $this->type("text_message", "This is text formatted content for Mailing {$mailingName} Webtest.");
140 // select default header and footer ( with label )
141 $this->select("header_id", "label=Mailing Header");
142 $this->select("footer_id", "label=Mailing Footer");
144 // do check count for Recipient
145 $this->assertElementContainsText('css=.messages', "Total Recipients: 1");
147 // click next with nominal content
148 $this->click("_qf_Upload_upload");
149 $this->waitForElementPresent("_qf_Test_cancel");
151 //---------------Test------------------
153 ////////--Commenting test mailing and mailing preview (test mailing and preview not presently working).
156 //$this->type("test_email", "mailino@mailson.co.in");
157 //$this->click("sendtest");
159 // verify status message
160 //$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)."));
162 // check mailing preview
163 //$this->click("//form[@id='Test']/div[2]/div[4]/div[1]");
164 //$this->assertTrue($this->isTextPresent("this is test content for Mailing $mailingName Webtest"));
168 // do check count for Recipient
169 $this->assertElementContainsText('css=.messages', "Total Recipients: 1");
172 $this->click("_qf_Test_next");
173 $this->waitForElementPresent("_qf_Schedule_cancel");
175 //----------Schedule or Send------------
177 // do check for default option enabled
178 $this->assertChecked("now");
180 // do check count for Recipient
181 $this->assertElementContainsText('css=.messages', "Total Recipients: 1");
183 // finally schedule the mail by clicking submit
184 $this->click("_qf_Schedule_next");
185 $this->waitForPageToLoad($this->getTimeoutMsec());
187 //----------end New Mailing-------------
189 //check redirected page to Scheduled and Sent Mailings and verify for mailing name
190 $this->assertElementContainsText('page-title', "Scheduled and Sent Mailings");
191 $this->assertElementContainsText("xpath=//table[@class='selector']/tbody//tr//td", "Mailing $mailingName Webtest");
193 //--------- mail delivery verification---------
194 // test undelivered report
196 // click report link of created mailing
197 $this->click("xpath=//table//tbody/tr[td[1]/text()='Mailing $mailingName Webtest']/descendant::a[text()='Report']");
198 $this->waitForPageToLoad($this->getTimeoutMsec());
200 // verify undelivered status message
201 $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.");
203 // do check for recipient group
204 $this->assertElementContainsText("xpath=//fieldset/legend[text()='Recipients']/../table/tbody//tr/td", "Members of $groupName");
206 // directly send schedule mailing -- not working right now
207 $this->openCiviPage("mailing/queue", "reset=1");
209 //click report link of created mailing
210 $this->click("xpath=//table//tbody/tr[td[1]/text()='Mailing $mailingName Webtest']/descendant::a[text()='Report']");
211 $this->waitForPageToLoad($this->getTimeoutMsec());
213 // do check again for recipient group
214 $this->assertElementContainsText("xpath=//fieldset/legend[text()='Recipients']/../table/tbody//tr/td", "Members of $groupName");
216 // verify intended recipients
217 $this->verifyText("xpath=//table//tr[td/a[text()='Intended Recipients']]/descendant::td[2]", preg_quote("1"));
219 // verify successful deliveries
220 $this->verifyText("xpath=//table//tr[td/a[text()='Successful Deliveries']]/descendant::td[2]", preg_quote("1 (100.00%)"));
223 $this->verifyText("xpath=//table//tr[td[1]/text()='Status']/descendant::td[2]", preg_quote("Complete"));
225 // verify mailing name
226 $this->verifyText("xpath=//table//tr[td[1]/text()='Mailing Name']/descendant::td[2]", preg_quote("Mailing $mailingName Webtest"));
228 // verify mailing subject
229 $this->verifyText("xpath=//table//tr[td[1]/text()='Subject']/descendant::td[2]", preg_quote("Test subject $mailingName for Webtest"));
231 //---- check for delivery detail--
233 $this->click("link=Successful Deliveries");
234 $this->waitForPageToLoad($this->getTimeoutMsec());
236 // check for open page
237 $this->assertElementContainsText( 'page-title', "Successful Deliveries");
240 $this->verifyText("xpath=//table[@id='mailing_event']/tbody//tr/td[2]", preg_quote("mailino$firstName@mailson.co.in"));
242 require_once 'CRM/Mailing/Event/DAO/Queue.php';
243 $eventQueue = new CRM_Mailing_Event_DAO_Queue();
244 $eventQueue->contact_id
= $contactId;
245 $eventQueue->find(TRUE);
247 $permission = array('edit-1-access-civimail-subscribeunsubscribe-pages');
248 $this->changePermissions($permission);
249 $this->open($this->sboxPath
. "civicrm/logout?reset=1");
252 $forwardUrl = array("mailing/forward", "reset=1&jid={$eventQueue->job_id}&qid={$eventQueue->id}&h={$eventQueue->hash}");
253 $this->openCiviPage($forwardUrl[0], $forwardUrl[1]);
255 $this->type("email_0", substr(sha1(rand()), 0, 7) . '@example.com');
256 $this->type("email_1", substr(sha1(rand()), 0, 7) . '@example.com');
258 $this->click("comment_show");
259 $this->type("forward_comment", "Test Message");
261 $this->click("_qf_ForwardMailing_next-bottom");
262 $this->waitForPageToLoad($this->getTimeoutMsec());
263 $this->assertElementContainsText('css=div.messages', 'Mailing is forwarded successfully to 2 email addresses');
265 $this->open($this->sboxPath
);
266 $this->waitForPageToLoad($this->getTimeoutMsec());
267 $this->webtestLogin();
269 $this->openCiviPage("mailing/browse/scheduled", "reset=1&scheduled=true");
271 //click report link of created mailing
272 $this->click("xpath=//table//tbody/tr[td[1]/text()='Mailing $mailingName Webtest']/descendant::a[text()='Report']");
273 $this->waitForPageToLoad($this->getTimeoutMsec());
275 // verify successful forwards
276 $this->verifyText("xpath=//table//tr[td/a[text()='Forwards']]/descendant::td[2]", "2");
278 // Mailing is forwarded successfully to 2 email addresses.
279 //------end delivery verification---------
281 // //------ check with unsubscribe -------
282 // // FIX ME: there is an issue with DSN setting for Webtest, need to handle by seperate DSN setting for Webtests
283 // // build unsubscribe link
284 // require_once 'CRM/Mailing/Event/DAO/Queue.php';
285 // $eventQueue = new CRM_Mailing_Event_DAO_Queue( );
286 // $eventQueue->contact_id = $contactId;
287 // $eventQueue->find(true);
289 // // unsubscribe link
290 // $unsubscribeUrl = "civicrm/mailing/optout?reset=1&jid={$eventQueue->job_id}&qid={$eventQueue->id}&h={$eventQueue->hash}&confirm=1";
292 // // logout to unsubscribe
293 // $this->open($this->sboxPath . 'civicrm/logout?reset=1');
294 // $this->waitForPageToLoad($this->getTimeoutMsec());
296 // // click(visit) unsubscribe path
297 // $this->open($this->sboxPath . $unsubscribeUrl);
298 // $this->waitForPageToLoad($this->getTimeoutMsec());
300 // $this->assertTrue($this->isTextPresent('Optout'));
301 // $this->assertTrue($this->isTextPresent("mailino$firstName@mailson.co.in"));
304 // $this->click('_qf_optout_next');
305 // $this->waitForPageToLoad($this->getTimeoutMsec());
307 // $this->assertTrue($this->isTextPresent('Optout'));
308 // $this->assertTrue($this->isTextPresent("mailino$firstName@mailson.co.in"));
309 // $this->assertTrue($this->isTextPresent('has been successfully opted out.'));
311 // //------ end unsubscribe -------
314 function testAdvanceSearchAndReportCheck() {
316 $this->open($this->sboxPath
);
317 $this->webtestLogin();
319 // Go directly to the URL of the screen that you will be testing (New Group).
320 $this->openCiviPage("group/add", "reset=1", "_qf_Edit_upload");
323 $groupName = 'group_' . substr(sha1(rand()), 0, 7);
326 $this->type("title", $groupName);
329 $this->type("description", "New mailing group for Webtest");
331 // enable Mailing List
332 $this->click("group_type[2]");
334 // select Visibility as Public Pages
335 $this->select("visibility", "value=Public Pages");
338 $this->click("_qf_Edit_upload");
339 $this->waitForPageToLoad($this->getTimeoutMsec());
341 // Is status message correct?
342 $this->assertElementContainsText('crm-notification-container', "The Group '$groupName' has been saved.");
344 //---- create mailing contact and add to mailing Group
345 $firstName = substr(sha1(rand()), 0, 7);
346 $this->webtestAddContact($firstName, "Mailson", "mailino$firstName@mailson.co.in");
348 // Get contact id from url.
350 preg_match('/cid=([0-9]+)/', $this->getLocation(), $matches);
351 $contactId = $matches[1];
353 // go to group tab and add to mailing group
354 $this->click("css=li#tab_group a");
355 $this->waitForElementPresent("_qf_GroupContact_next");
356 $this->select("group_id", "$groupName");
357 $this->click("_qf_GroupContact_next");
358 $this->waitForPageToLoad($this->getTimeoutMsec());
359 $this->waitForElementPresent("_qf_GroupContact_next");
361 // configure default mail-box
362 $this->openCiviPage("admin/mailSettings", "action=update&id=1&reset=1", '_qf_MailSettings_cancel-bottom');
363 $this->type('name', 'Test Domain');
364 $this->type('domain', 'example.com');
365 $this->select('protocol', 'value=1');
366 $this->click('_qf_MailSettings_next-bottom');
367 $this->waitForPageToLoad($this->getTimeoutMsec());
369 // Go directly to Schedule and Send Mailing form
370 $this->open($this->sboxPath
. "civicrm/mailing/send?reset=1");
371 $this->waitForElementPresent("_qf_Group_cancel");
373 //-------select recipients----------
376 $mailingName = substr(sha1(rand()), 0, 7);
377 $this->type("name", "Mailing $mailingName Webtest");
379 // Add the test mailing group
380 $this->select("includeGroups-f", "$groupName");
384 $this->click("_qf_Group_next");
385 $this->waitForElementPresent("_qf_Settings_cancel");
387 //--------track and respond----------
389 // check for default settings options
390 $this->assertChecked("url_tracking");
391 $this->assertChecked("open_tracking");
393 // do check count for Recipient
394 $this->assertElementContainsText('css=.messages', "Total Recipients: 1");
396 // click next with default settings
397 $this->click("_qf_Settings_next");
398 $this->waitForElementPresent("_qf_Upload_cancel");
400 // fill subject for mailing
401 $this->type("subject", "Test subject {$mailingName} for Webtest");
403 // check for default option enabled
404 $this->assertChecked("CIVICRM_QFID_1_upload_type");
406 // HTML format message
407 $HTMLMessage = "This is HTML formatted content for Mailing {$mailingName} Webtest.";
408 $this->fillRichTextField("html_message", $HTMLMessage);
410 // Open Plain-text Format pane and type text format msg
411 $this->click("//fieldset[@id='compose_id']/div[2]/div[1]");
412 $this->type("text_message", "This is text formatted content for Mailing {$mailingName} Webtest.");
414 // select default header and footer ( with label )
415 $this->select("header_id", "label=Mailing Header");
416 $this->select("footer_id", "label=Mailing Footer");
418 // do check count for Recipient
419 $this->assertElementContainsText('css=.messages', "Total Recipients: 1");
421 // click next with nominal content
422 $this->click("_qf_Upload_upload");
423 $this->waitForElementPresent("_qf_Test_cancel");
425 // do check count for Recipient
426 $this->assertElementContainsText('css=.messages', "Total Recipients: 1");
429 $this->click("_qf_Test_next");
430 $this->waitForElementPresent("_qf_Schedule_cancel");
432 //----------Schedule or Send------------
434 // do check for default option enabled
435 $this->assertChecked("now");
437 // do check count for Recipient
438 $this->assertElementContainsText('css=.messages', "Total Recipients: 1");
440 // finally schedule the mail by clicking submit
441 $this->click("_qf_Schedule_next");
442 $this->waitForPageToLoad($this->getTimeoutMsec());
444 //----------end New Mailing-------------
446 //check redirected page to Scheduled and Sent Mailings and verify for mailing name
447 $this->assertElementContainsText('page-title', "Scheduled and Sent Mailings");
448 $this->assertElementContainsText("xpath=//table[@class='selector']/tbody//tr//td", "Mailing $mailingName Webtest");
450 // directly send schedule mailing -- not working right now
451 $this->openCiviPage("mailing/queue", "reset=1");
453 //click report link of created mailing
454 $this->click("xpath=//table//tbody/tr[td[1]/text()='Mailing $mailingName Webtest']/descendant::a[text()='Report']");
455 $this->waitForPageToLoad($this->getTimeoutMsec());
457 $mailingReportUrl = $this->getLocation();
458 // do check again for recipient group
459 $this->assertElementContainsText("xpath=//fieldset/legend[text()='Recipients']/../table/tbody//tr/td", "Members of $groupName");
461 // verify successful deliveries
462 $this->verifyText("xpath=//table//tr[td/a[text()='Successful Deliveries']]/descendant::td[2]", preg_quote("1 (100.00%)"));
464 $summaryInfoLinks = array('Intended Recipients', 'Successful Deliveries', 'Tracked Opens', 'Click-throughs', 'Forwards', 'Replies', 'Bounces', 'Unsubscribe Requests','Opt-out Requests');
466 //check for report and adv search links
467 foreach($summaryInfoLinks as $value) {
468 $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}");
469 $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}");
471 // verify mailing name
472 $this->verifyText("xpath=//table//tr[td[1]/text()='Mailing Name']/descendant::td[2]", preg_quote("Mailing $mailingName Webtest"));
474 // verify mailing subject
475 $this->verifyText("xpath=//table//tr[td[1]/text()='Subject']/descendant::td[2]", preg_quote("Test subject $mailingName for Webtest"));
477 // after asserts do clicks and confirm filters
480 'Intended Recipients' =>
482 'report' => array('report_name' => 'Mailing Details', 'Mailing' => "Mailing $mailingName Webtest"),
483 'search' => array('Mailing Name IN' => "\"Mailing {$mailingName} Webtest")
485 'Successful Deliveries' =>
487 'report' => array('report_name' => 'Mailing Details', 'Mailing' => "Mailing $mailingName Webtest",
488 "Delivery Status" => " Successful"),
489 'search' => array('Mailing Name IN' => "\"Mailing {$mailingName} Webtest", 'Mailing Delivery -' => "Successful")
493 'report' => array('report_name' => 'Mail Opened', 'Mailing' => "Mailing $mailingName Webtest"),
494 'search' => array('Mailing Name IN' => "\"Mailing {$mailingName} Webtest", 'Mailing: Trackable Opens -' => "Opened")
498 'report' => array('report_name' => 'Mail Clickthroughs', 'Mailing' => "Mailing $mailingName Webtest"),
499 'search' => array('Mailing Name IN' => "\"Mailing {$mailingName} Webtest", 'Mailing: Trackable URL Clicks -' => "Clicked")
503 'report' => array('report_name' => 'Mailing Details', 'Mailing' => "Mailing $mailingName Webtest",
504 'Forwarded' => 'Is equal to Yes'),
505 'search' => array('Mailing Name IN' => "\"Mailing {$mailingName} Webtest", 'Mailing: -' => "Forwards")
509 'report' => array('report_name' => 'Mailing Details', 'Mailing' => "Mailing $mailingName Webtest",
510 'Replied' => 'Is equal to Yes'),
511 'search' => array('Mailing Name IN' => "\"Mailing {$mailingName} Webtest", 'Mailing: Trackable Replies -' => "Replied")
515 'report' => array('report_name' => 'Mail Bounces', 'Mailing' => "Mailing $mailingName Webtest"),
516 'search' => array('Mailing Name IN' => "\"Mailing {$mailingName} Webtest", 'Mailing Delivery -' => "Bounced")
518 'Unsubscribe Requests' =>
520 'report' => array('report_name' => 'Mailing Details', 'Mailing' => "Mailing $mailingName Webtest",
521 'Unsubscribed' => 'Is equal to Yes'),
522 'search' => array('Mailing Name IN' => "\"Mailing {$mailingName} Webtest", 'Mailing: -' => "Unsubscribe Requests")
524 'Opt-out Requests' =>
526 'report' => array('report_name' => 'Mailing Details', 'Mailing' => "Mailing $mailingName Webtest",
527 'Opted-out' => 'Is equal to Yes'),
528 'search' => array('Mailing Name IN' => "\"Mailing {$mailingName} Webtest", 'Mailing: -' => "Opt-out Requests")
531 $this->criteriaCheck($criteriaCheck, $mailingReportUrl);
534 function criteriaCheck($criteriaCheck, $mailingReportUrl) {
535 foreach($criteriaCheck as $key => $infoFilter) {
536 foreach($infoFilter as $entity => $dataToCheck) {
537 $this->open($mailingReportUrl);
538 if ($entity == "report") {
539 $this->click("xpath=//fieldset/legend[text()='Delivery Summary']/../table//tr[td/a[text()='{$key}']]/descendant::td[3]/span/a[1][text()='Report']");
541 $this->click("xpath=//fieldset/legend[text()='Delivery Summary']/../table//tr[td/a[text()='{$key}']]/descendant::td[3]/span/a[2][text()='Advanced Search']");
543 $this->waitForPageToLoad($this->getTimeoutMsec());
544 $this-> _verifyCriteria($key, $dataToCheck, $entity);
549 function _verifyCriteria($summaryInfo, $dataToCheck, $entity) {
550 foreach($dataToCheck as $key => $value) {
551 if ($entity == 'report') {
552 if ($key == 'report_name') {
553 $this->assertElementContainsText('page-title', "{$value}");
556 $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}");
558 $this->assertElementContainsText('page-title', "Advanced Search");
559 $assertedValue = $this->isElementPresent("xpath=//div[@class='crm-results-block']//div[@class='qill'][contains(text(),'{$key} {$value}')]");
560 if (!$assertedValue) {
561 $assertedValue = $this->isTextPresent("{$key} {$value}");
563 $this->assertTrue($assertedValue,"Criteria check for {$key} failed for Advance Search for {$summaryInfo}");