3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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';
30 * Class WebTest_Mailing_MailingTest
32 class WebTest_Mailing_MailingTest
extends CiviSeleniumTestCase
{
34 protected function setUp() {
38 public function testAddMailing() {
39 $this->webtestLogin();
41 //----do create test mailing 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->clickLink("_qf_Edit_upload");
62 // Is status message correct?
63 $this->waitForText('crm-notification-container', "The Group '$groupName' has been saved.");
65 //---- create mailing contact and add to mailing Group
66 $firstName = substr(sha1(rand()), 0, 7);
67 $this->webtestAddContact($firstName, "Mailson", "mailino$firstName@mailson.co.in");
69 // Get contact id from url.
70 $contactId = $this->urlArg('cid');
72 // go to group tab and add to mailing group
73 $this->click("css=li#tab_group a");
74 $this->waitForElementPresent("_qf_GroupContact_next");
75 $this->select("group_id", "$groupName");
76 $this->clickLink("_qf_GroupContact_next", "_qf_GroupContact_next", FALSE);
78 // configure default mail-box
79 $this->setupDefaultMailbox();
81 $this->openCiviPage("a/#/mailing/new");
83 //-------select recipients----------
84 $tokens = ' {domain.address}{action.optOutUrl}';
87 $mailingName = substr(sha1(rand()), 0, 7);
88 $this->waitForElementPresent("xpath=//input[@name='mailingName']");
89 $this->type("xpath=//input[@name='mailingName']", "Mailing $mailingName Webtest");
91 // Add the test mailing group
92 $this->select2("s2id_crmUiId_8", $groupName, TRUE);
94 // do check count for Recipient
95 $this->waitForTextPresent("~1 recipient");
97 // fill subject for mailing
98 $this->type("xpath=//input[@name='subject']", "Test subject {$mailingName} for Webtest");
100 // HTML format message
101 $HTMLMessage = "This is HTML formatted content for Mailing {$mailingName} Webtest.";
102 $this->fillRichTextField("crmUiId_1", $HTMLMessage . $tokens);
104 // FIXME: Selenium can't access content in an iframe
105 //$this->click("xpath=//div[@class='preview-popup']//a[text()='Preview as HTML']");
106 //$this->waitForTextPresent($HTMLMessage);
107 //$this->waitForAjaxContent();
108 //$this->click("xpath=//button[@title='Close']");
110 // Open Plain-text Format pane and type text format msg
111 $this->click("//div[starts-with(text(),'Plain Text')]");
112 $this->type("xpath=//*[@name='body_text']", "This is text formatted content for Mailing {$mailingName} Webtest.$tokens");
114 $this->click("xpath=//div[@class='preview-popup']//a[text()='Preview as Plain Text']");
115 $this->waitForTextPresent("This is text formatted content for Mailing {$mailingName} Webtest.");
116 $this->waitForAjaxContent();
117 $this->click("xpath=//button[@title='Close']");
119 // select default header and footer ( with label )
120 $this->click("xpath=//ul/li/a[text()='Header and Footer']");
121 $this->select2("s2id_crmUiId_10", "Mailing Header");
122 $this->select2("s2id_crmUiId_11", "Mailing Footer");
124 //--------track and respond----------
126 // check for default settings options
127 $this->click("xpath=//ul/li/a[text()='Tracking']");
128 $this->assertChecked("url_tracking");
129 $this->assertChecked("open_tracking");
131 // click next with default settings
132 $this->click("xpath=//div[@class='crm-wizard-buttons']/button[text()='Next']");
134 $this->waitForTextPresent("Mailing $mailingName Webtest");
135 $this->click("xpath=//div[@class='content']//a[text()='~1 recipient']");
136 $this->webtestVerifyTabularData(array("$firstName Mailson" => "mailino$firstName@mailson.co.in"));
137 $this->click("xpath=//button[@title='Close']");
138 $this->waitForTextPresent("(Include: $groupName)");
140 //----------Schedule or Send------------
142 // do check for default option enabled
143 $this->assertChecked("xpath=//input[@id='schedule-send-now']");
145 // click next with nominal content
146 $this->click("xpath=//center/a/div[text()='Submit Mailing']");
148 //---------------Test------------------
150 ////////--Commenting test mailing and mailing preview (test mailing and preview not presently working).
153 //$this->type("test_email", "mailino@mailson.co.in");
154 //$this->click("sendtest");
156 // verify status message
157 //$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)."));
159 // check mailing preview
160 //$this->click("//form[@id='Test']/div[2]/div[4]/div[1]");
161 //$this->assertTrue($this->isTextPresent("this is test content for Mailing $mailingName Webtest"));
165 //----------end New Mailing-------------
167 //check redirected page to Scheduled and Sent Mailings and verify for mailing name
168 $this->waitForTextPresent("Find Mailings");
169 $this->assertElementContainsText("xpath=//table[@class='selector row-highlight']/tbody//tr//td", "Mailing $mailingName Webtest");
171 //--------- mail delivery verification---------
172 // test undelivered report
174 // click report link of created mailing
175 $this->clickLink("xpath=//table//tbody/tr[td[1]/text()='Mailing $mailingName Webtest']/descendant::a[text()='Report']");
177 // verify undelivered status message
178 $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.");
180 // do check for recipient group
181 $this->assertElementContainsText("xpath=//fieldset/legend[text()='Recipients']/../table/tbody//tr/td", "Members of $groupName");
183 // directly send schedule mailing -- not working right now
184 $this->openCiviPage("mailing/queue", "reset=1");
186 //click report link of created mailing
187 $this->clickLink("xpath=//table//tbody/tr[td[1]/text()='Mailing $mailingName Webtest']/descendant::a[text()='Report']");
189 // do check again for recipient group
190 $this->assertElementContainsText("xpath=//fieldset/legend[text()='Recipients']/../table/tbody//tr/td", "Members of $groupName");
192 // verify intended recipients
193 $this->verifyText("xpath=//table//tr[td/a[text()='Intended Recipients']]/descendant::td[2]", preg_quote("1"));
195 // verify successful deliveries
196 $this->verifyText("xpath=//table//tr[td/a[text()='Successful Deliveries']]/descendant::td[2]", preg_quote("1 (100.00%)"));
199 $this->verifyText("xpath=//table//tr[td[1]/text()='Status']/descendant::td[2]", preg_quote("Complete"));
201 // verify mailing name
202 $this->verifyText("xpath=//table//tr[td[1]/text()='Mailing Name']/descendant::td[2]", preg_quote("Mailing $mailingName Webtest"));
204 // verify mailing subject
205 $this->verifyText("xpath=//table//tr[td[1]/text()='Subject']/descendant::td[2]", preg_quote("Test subject $mailingName for Webtest"));
207 //---- check for delivery detail--
209 $this->clickLink("link=Successful Deliveries");
211 // check for open page
212 $this->waitForTextPresent("Successful Deliveries");
215 $this->verifyText("xpath=//table[@id='mailing_event']/tbody//tr/td[3]", preg_quote("mailino$firstName@mailson.co.in"));
217 $eventQueue = new CRM_Mailing_Event_DAO_Queue();
218 $eventQueue->contact_id
= $contactId;
219 $eventQueue->find(TRUE);
221 $permission = array('edit-1-access-civimail-subscribeunsubscribe-pages');
222 $this->changePermissions($permission);
223 $this->webtestLogout();
228 "reset=1&jid={$eventQueue->job_id}&qid={$eventQueue->id}&h={$eventQueue->hash}",
230 $this->openCiviPage($forwardUrl[0], $forwardUrl[1], NULL);
232 $this->type("email_0", substr(sha1(rand()), 0, 7) . '@example.com');
233 $this->type("email_1", substr(sha1(rand()), 0, 7) . '@example.com');
235 $this->click("comment_show");
236 $this->type("forward_comment", "Test Message");
238 $this->click("_qf_ForwardMailing_next-bottom");
239 $this->waitForPageToLoad($this->getTimeoutMsec());
240 $this->assertElementContainsText('css=div.messages', 'Mailing is forwarded successfully to 2 email addresses');
242 $this->webtestLogin();
244 $this->openCiviPage("mailing/browse/scheduled", "reset=1&scheduled=true");
246 //click report link of created mailing
247 $this->clickLink("xpath=//table//tbody/tr[td[1]/text()='Mailing $mailingName Webtest']/descendant::a[text()='Report']");
249 // verify successful forwards
250 $this->verifyText("xpath=//table//tr[td/a[text()='Forwards']]/descendant::td[2]", "2");
252 // Mailing is forwarded successfully to 2 email addresses.
253 //------end delivery verification---------
255 // //------ check with unsubscribe -------
256 // // FIX ME: there is an issue with DSN setting for Webtest, need to handle by seperate DSN setting for Webtests
257 // // build unsubscribe link
258 // require_once 'CRM/Mailing/Event/DAO/Queue.php';
259 // $eventQueue = new CRM_Mailing_Event_DAO_Queue( );
260 // $eventQueue->contact_id = $contactId;
261 // $eventQueue->find(true);
263 // // unsubscribe link
264 // $unsubscribeUrl = "civicrm/mailing/optout?reset=1&jid={$eventQueue->job_id}&qid={$eventQueue->id}&h={$eventQueue->hash}&confirm=1";
266 // // logout to unsubscribe
267 // $this->webtestLogout();
269 // // click(visit) unsubscribe path
270 // $this->open($this->sboxPath . $unsubscribeUrl);
271 // $this->waitForPageToLoad($this->getTimeoutMsec());
273 // $this->assertTrue($this->isTextPresent('Optout'));
274 // $this->assertTrue($this->isTextPresent("mailino$firstName@mailson.co.in"));
277 // $this->click('_qf_optout_next');
278 // $this->waitForPageToLoad($this->getTimeoutMsec());
280 // $this->assertTrue($this->isTextPresent('Optout'));
281 // $this->assertTrue($this->isTextPresent("mailino$firstName@mailson.co.in"));
282 // $this->assertTrue($this->isTextPresent('has been successfully opted out.'));
284 // //------ end unsubscribe -------
287 public function testAdvanceSearchAndReportCheck() {
289 $this->webtestLogin();
291 $this->openCiviPage("group/add", "reset=1", "_qf_Edit_upload");
294 $groupName = 'group_' . substr(sha1(rand()), 0, 7);
297 $this->type("title", $groupName);
300 $this->type("description", "New mailing group for Webtest");
302 // enable Mailing List
303 $this->click("group_type[2]");
305 // select Visibility as Public Pages
306 $this->select("visibility", "value=Public Pages");
309 $this->clickLink("_qf_Edit_upload");
311 // Is status message correct?
312 $this->waitForText('crm-notification-container', "The Group '$groupName' has been saved.");
314 //---- create mailing contact and add to mailing Group
315 $firstName = substr(sha1(rand()), 0, 7);
316 $this->webtestAddContact($firstName, "Mailson", "mailino$firstName@mailson.co.in");
318 // Get contact id from url.
319 $contactId = $this->urlArg('cid');
321 // go to group tab and add to mailing group
322 $this->click("css=li#tab_group a");
323 $this->waitForElementPresent("_qf_GroupContact_next");
324 $this->select("group_id", "$groupName");
325 $this->clickLink("_qf_GroupContact_next", "_qf_GroupContact_next", FALSE);
327 // configure default mail-box
328 $this->openCiviPage("admin/mailSettings", "action=update&id=1&reset=1", '_qf_MailSettings_cancel-bottom');
329 $this->type('name', 'Test Domain');
330 $this->type('domain', 'example.com');
331 $this->select('protocol', 'value=1');
332 $this->clickLink('_qf_MailSettings_next-bottom');
334 $this->openCiviPage("a/#/mailing/new");
336 //-------select recipients----------
337 $tokens = ' {domain.address}{action.optOutUrl}';
340 $mailingName = substr(sha1(rand()), 0, 7);
341 $this->waitForElementPresent("xpath=//input[@name='mailingName']");
342 $this->type("xpath=//input[@name='mailingName']", "Mailing $mailingName Webtest");
344 // Add the test mailing group
345 $this->select2("s2id_crmUiId_8", $groupName, TRUE);
347 // do check count for Recipient
348 $this->waitForTextPresent("~1 recipient");
350 // fill subject for mailing
351 $this->type("xpath=//input[@name='subject']", "Test subject {$mailingName} for Webtest");
353 // HTML format message
354 $HTMLMessage = "This is HTML formatted content for Mailing {$mailingName} Webtest.";
355 $this->fillRichTextField("crmUiId_1", $HTMLMessage . $tokens);
357 // FIXME: Selenium can't access content in an iframe
358 //$this->click("xpath=//div[@class='preview-popup']//a[text()='Preview as HTML']");
359 //$this->waitForElementPresent($HTMLMessage);
360 //$this->waitForAjaxContent();
361 //$this->click("xpath=//button[@title='Close']");
363 // Open Plain-text Format pane and type text format msg
364 $this->click("//div[starts-with(text(),'Plain Text')]");
365 $this->type("xpath=//*[@name='body_text']", "This is text formatted content for Mailing {$mailingName} Webtest.$tokens");
367 $this->click("xpath=//div[@class='preview-popup']//a[text()='Preview as Plain Text']");
368 $this->waitForTextPresent("This is text formatted content for Mailing {$mailingName} Webtest.");
369 $this->waitForAjaxContent();
370 $this->click("xpath=//button[@title='Close']");
372 // select default header and footer ( with label )
373 $this->click("xpath=//ul/li/a[text()='Header and Footer']");
374 $this->select2("s2id_crmUiId_10", "Mailing Header");
375 $this->select2("s2id_crmUiId_11", "Mailing Footer");
377 //--------track and respond----------
379 // check for default settings options
380 $this->click("xpath=//ul/li/a[text()='Tracking']");
381 $this->assertChecked("url_tracking");
382 $this->assertChecked("open_tracking");
384 // click next with default settings
385 $this->click("xpath=//div[@class='crm-wizard-buttons']/button[text()='Next']");
387 $this->waitForTextPresent("Mailing $mailingName Webtest");
388 $this->click("xpath=//div[@class='content']//a[text()='~1 recipient']");
389 $this->webtestVerifyTabularData(array("$firstName Mailson" => "mailino$firstName@mailson.co.in"));
390 $this->click("xpath=//button[@title='Close']");
391 $this->waitForTextPresent("(Include: $groupName)");
393 //----------Schedule or Send------------
395 // do check for default option enabled
396 $this->assertChecked("xpath=//input[@id='schedule-send-now']");
398 // click next with nominal content
399 $this->click("xpath=//center/a/div[text()='Submit Mailing']");
401 //----------end New Mailing-------------
403 //check redirected page to Scheduled and Sent Mailings and verify for mailing name
404 $this->waitForTextPresent("Find Mailings");
405 $this->assertElementContainsText("xpath=//table[@class='selector row-highlight']/tbody//tr//td", "Mailing $mailingName Webtest");
407 // directly send schedule mailing -- not working right now
408 $this->openCiviPage("mailing/queue", "reset=1");
410 //click report link of created mailing
411 $this->clickLink("xpath=//table//tbody/tr[td[1]/text()='Mailing $mailingName Webtest']/descendant::a[text()='Report']");
413 $mailingReportUrl = $this->getLocation();
414 // do check again for recipient group
415 $this->assertElementContainsText("xpath=//fieldset/legend[text()='Recipients']/../table/tbody//tr/td", "Members of $groupName");
417 // verify successful deliveries
418 $this->verifyText("xpath=//table//tr[td/a[text()='Successful Deliveries']]/descendant::td[2]", preg_quote("1 (100.00%)"));
420 $summaryInfoLinks = array(
421 'Intended Recipients',
422 'Successful Deliveries',
428 'Unsubscribe Requests',
432 //check for report and adv search links
433 foreach ($summaryInfoLinks as $value) {
434 $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}");
435 $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}");
437 // verify mailing name
438 $this->verifyText("xpath=//table//tr[td[1]/text()='Mailing Name']/descendant::td[2]", preg_quote("Mailing $mailingName Webtest"));
440 // verify mailing subject
441 $this->verifyText("xpath=//table//tr[td[1]/text()='Subject']/descendant::td[2]", preg_quote("Test subject $mailingName for Webtest"));
443 // after asserts do clicks and confirm filters
444 $criteriaCheck = array(
445 'Intended Recipients' => array(
446 'report' => array('report_name' => 'Mailing Details', 'Mailing' => "Mailing $mailingName Webtest"),
447 'search' => array('Mailing Name IN' => "\"Mailing {$mailingName} Webtest"),
449 'Successful Deliveries' => array(
451 'report_name' => 'Mailing Details',
452 'Mailing' => "Mailing $mailingName Webtest",
453 "Delivery Status" => " Successful",
456 'Mailing Name IN' => "\"Mailing {$mailingName} Webtest",
457 'Mailing Delivery -' => "Successful",
460 'Tracked Opens' => array(
461 'report' => array('report_name' => 'Mail Opened', 'Mailing' => "Mailing $mailingName Webtest"),
463 'Mailing Name IN' => "\"Mailing {$mailingName} Webtest",
464 'Mailing: Trackable Opens -' => "Opened",
467 'Click-throughs' => array(
468 'report' => array('report_name' => 'Mail Clickthroughs', 'Mailing' => "Mailing $mailingName Webtest"),
470 'Mailing Name IN' => "\"Mailing {$mailingName} Webtest",
471 'Mailing: Trackable URL Clicks -' => "Clicked",
476 'report_name' => 'Mailing Details',
477 'Mailing' => "Mailing $mailingName Webtest",
478 'Forwarded' => 'Is equal to Yes',
480 'search' => array('Mailing Name IN' => "\"Mailing {$mailingName} Webtest", 'Mailing: -' => "Forwards"),
484 'report_name' => 'Mailing Details',
485 'Mailing' => "Mailing $mailingName Webtest",
486 'Replied' => 'Is equal to Yes',
489 'Mailing Name IN' => "\"Mailing {$mailingName} Webtest",
490 'Mailing: Trackable Replies -' => "Replied",
494 'report' => array('report_name' => 'Mail Bounces', 'Mailing' => "Mailing $mailingName Webtest"),
496 'Mailing Name IN' => "\"Mailing {$mailingName} Webtest",
497 'Mailing Delivery -' => "Bounced",
500 'Unsubscribe Requests' => array(
502 'report_name' => 'Mailing Details',
503 'Mailing' => "Mailing $mailingName Webtest",
504 'Unsubscribed' => 'Is equal to Yes',
507 'Mailing Name IN' => "\"Mailing {$mailingName} Webtest",
508 'Mailing: -' => "Unsubscribe Requests",
511 'Opt-out Requests' => array(
513 'report_name' => 'Mailing Details',
514 'Mailing' => "Mailing $mailingName Webtest",
515 'Opted-out' => 'Is equal to Yes',
518 'Mailing Name IN' => "\"Mailing {$mailingName} Webtest",
519 'Mailing: -' => "Opt-out Requests",
523 $this->criteriaCheck($criteriaCheck, $mailingReportUrl);
527 * @param $criteriaCheck
528 * @param $mailingReportUrl
530 public function criteriaCheck($criteriaCheck, $mailingReportUrl) {
531 foreach ($criteriaCheck as $key => $infoFilter) {
532 foreach ($infoFilter as $entity => $dataToCheck) {
533 $this->open($mailingReportUrl);
534 if ($entity == "report") {
535 $this->clickLink("xpath=//fieldset/legend[text()='Delivery Summary']/../table//tr[td/a[text()='{$key}']]/descendant::td[3]/span/a[1][text()='Report']");
538 $this->clickLink("xpath=//fieldset/legend[text()='Delivery Summary']/../table//tr[td/a[text()='{$key}']]/descendant::td[3]/span/a[2][text()='Advanced Search']");
540 $this->_verifyCriteria($key, $dataToCheck, $entity);
546 * @param $summaryInfo
547 * @param $dataToCheck
550 public function _verifyCriteria($summaryInfo, $dataToCheck, $entity) {
551 foreach ($dataToCheck as $key => $value) {
552 if ($entity == 'report') {
553 if ($key == 'report_name') {
554 $this->waitForTextPresent("{$value}");
557 $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}");
560 $this->waitForTextPresent("Advanced Search");
561 $assertedValue = $this->isElementPresent("xpath=//div[@class='crm-results-block']//div[@class='qill'][contains(text(),'{$key} {$value}')]");
562 if (!$assertedValue) {
563 $assertedValue = $this->isTextPresent("{$key} {$value}");
565 $this->assertTrue($assertedValue, "Criteria check for {$key} failed for Advance Search for {$summaryInfo}");