3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
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';
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----------
86 $mailingName = substr(sha1(rand()), 0, 7);
87 $this->waitForElementPresent("xpath=//input[@name='mailingName']");
88 $this->type("xpath=//input[@name='mailingName']", "Mailing $mailingName Webtest");
90 // Add the test mailing group
91 $this->select2("s2id_crmUiId_8", $groupName, TRUE);
93 // do check count for Recipient
94 $this->waitForTextPresent("~1 recipient");
96 // fill subject for mailing
97 $this->type("xpath=//input[@name='subject']", "Test subject {$mailingName} for Webtest");
99 // HTML format message
100 $HTMLMessage = "This is HTML formatted content for Mailing {$mailingName} Webtest.";
101 $this->fillRichTextField("crmUiId_1", $HTMLMessage);
102 $this->click("xpath=//div[@class='preview-popup']//a[text()='Preview as HTML']");
103 $this->waitForTextPresent($HTMLMessage);
104 $this->waitForAjaxContent();
105 $this->click("xpath=//button[@title='Close']");
107 // Open Plain-text Format pane and type text format msg
108 $this->click("//div[text()='Plain Text']");
109 $this->type("xpath=//*[@name='body_text']", "This is text formatted content for Mailing {$mailingName} Webtest.");
111 $this->click("xpath=//div[@class='preview-popup']//a[text()='Preview as Plain Text']");
112 $this->waitForTextPresent("This is text formatted content for Mailing {$mailingName} Webtest.");
113 $this->waitForAjaxContent();
114 $this->click("xpath=//button[@title='Close']");
116 // select default header and footer ( with label )
117 $this->click("xpath=//ul/li/a[text()='Header and Footer']");
118 $this->select2("s2id_crmUiId_10", "Mailing Header");
119 $this->select2("s2id_crmUiId_11", "Mailing Footer");
121 //--------track and respond----------
123 // check for default settings options
124 $this->click("xpath=//ul/li/a[text()='Tracking']");
125 $this->assertChecked("url_tracking");
126 $this->assertChecked("open_tracking");
128 // click next with default settings
129 $this->click("xpath=//div[@class='crm-wizard-buttons']/button[text()='Next']");
131 $this->waitForTextPresent("Mailing $mailingName Webtest");
132 $this->click("xpath=//div[@class='content']//a[text()='~1 recipient']");
133 $this->webtestVerifyTabularData(array("$firstName Mailson" => "mailino$firstName@mailson.co.in"));
134 $this->click("xpath=//button[@title='Close']");
135 $this->waitForTextPresent("(Include: $groupName)");
137 //----------Schedule or Send------------
139 // do check for default option enabled
140 $this->assertChecked("xpath=//input[@id='schedule-send-now']");
142 // click next with nominal content
143 $this->click("xpath=//center/a/div[text()='Submit Mailing']");
145 //---------------Test------------------
147 ////////--Commenting test mailing and mailing preview (test mailing and preview not presently working).
150 //$this->type("test_email", "mailino@mailson.co.in");
151 //$this->click("sendtest");
153 // verify status message
154 //$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)."));
156 // check mailing preview
157 //$this->click("//form[@id='Test']/div[2]/div[4]/div[1]");
158 //$this->assertTrue($this->isTextPresent("this is test content for Mailing $mailingName Webtest"));
162 //----------end New Mailing-------------
164 //check redirected page to Scheduled and Sent Mailings and verify for mailing name
165 $this->waitForTextPresent("Find Mailings");
166 $this->assertElementContainsText("xpath=//table[@class='selector row-highlight']/tbody//tr//td", "Mailing $mailingName Webtest");
168 //--------- mail delivery verification---------
169 // test undelivered report
171 // click report link of created mailing
172 $this->clickLink("xpath=//table//tbody/tr[td[1]/text()='Mailing $mailingName Webtest']/descendant::a[text()='Report']");
174 // verify undelivered status message
175 $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.");
177 // do check for recipient group
178 $this->assertElementContainsText("xpath=//fieldset/legend[text()='Recipients']/../table/tbody//tr/td", "Members of $groupName");
180 // directly send schedule mailing -- not working right now
181 $this->openCiviPage("mailing/queue", "reset=1");
183 //click report link of created mailing
184 $this->clickLink("xpath=//table//tbody/tr[td[1]/text()='Mailing $mailingName Webtest']/descendant::a[text()='Report']");
186 // do check again for recipient group
187 $this->assertElementContainsText("xpath=//fieldset/legend[text()='Recipients']/../table/tbody//tr/td", "Members of $groupName");
189 // verify intended recipients
190 $this->verifyText("xpath=//table//tr[td/a[text()='Intended Recipients']]/descendant::td[2]", preg_quote("1"));
192 // verify successful deliveries
193 $this->verifyText("xpath=//table//tr[td/a[text()='Successful Deliveries']]/descendant::td[2]", preg_quote("1 (100.00%)"));
196 $this->verifyText("xpath=//table//tr[td[1]/text()='Status']/descendant::td[2]", preg_quote("Complete"));
198 // verify mailing name
199 $this->verifyText("xpath=//table//tr[td[1]/text()='Mailing Name']/descendant::td[2]", preg_quote("Mailing $mailingName Webtest"));
201 // verify mailing subject
202 $this->verifyText("xpath=//table//tr[td[1]/text()='Subject']/descendant::td[2]", preg_quote("Test subject $mailingName for Webtest"));
204 //---- check for delivery detail--
206 $this->clickLink("link=Successful Deliveries");
208 // check for open page
209 $this->waitForTextPresent("Successful Deliveries");
212 $this->verifyText("xpath=//table[@id='mailing_event']/tbody//tr/td[3]", preg_quote("mailino$firstName@mailson.co.in"));
214 $eventQueue = new CRM_Mailing_Event_DAO_Queue();
215 $eventQueue->contact_id
= $contactId;
216 $eventQueue->find(TRUE);
218 $permission = array('edit-1-access-civimail-subscribeunsubscribe-pages');
219 $this->changePermissions($permission);
220 $this->webtestLogout();
225 "reset=1&jid={$eventQueue->job_id}&qid={$eventQueue->id}&h={$eventQueue->hash}",
227 $this->openCiviPage($forwardUrl[0], $forwardUrl[1], NULL);
229 $this->type("email_0", substr(sha1(rand()), 0, 7) . '@example.com');
230 $this->type("email_1", substr(sha1(rand()), 0, 7) . '@example.com');
232 $this->click("comment_show");
233 $this->type("forward_comment", "Test Message");
235 $this->click("_qf_ForwardMailing_next-bottom");
236 $this->waitForPageToLoad($this->getTimeoutMsec());
237 $this->assertElementContainsText('css=div.messages', 'Mailing is forwarded successfully to 2 email addresses');
239 $this->webtestLogin();
241 $this->openCiviPage("mailing/browse/scheduled", "reset=1&scheduled=true");
243 //click report link of created mailing
244 $this->clickLink("xpath=//table//tbody/tr[td[1]/text()='Mailing $mailingName Webtest']/descendant::a[text()='Report']");
246 // verify successful forwards
247 $this->verifyText("xpath=//table//tr[td/a[text()='Forwards']]/descendant::td[2]", "2");
249 // Mailing is forwarded successfully to 2 email addresses.
250 //------end delivery verification---------
252 // //------ check with unsubscribe -------
253 // // FIX ME: there is an issue with DSN setting for Webtest, need to handle by seperate DSN setting for Webtests
254 // // build unsubscribe link
255 // require_once 'CRM/Mailing/Event/DAO/Queue.php';
256 // $eventQueue = new CRM_Mailing_Event_DAO_Queue( );
257 // $eventQueue->contact_id = $contactId;
258 // $eventQueue->find(true);
260 // // unsubscribe link
261 // $unsubscribeUrl = "civicrm/mailing/optout?reset=1&jid={$eventQueue->job_id}&qid={$eventQueue->id}&h={$eventQueue->hash}&confirm=1";
263 // // logout to unsubscribe
264 // $this->webtestLogout();
266 // // click(visit) unsubscribe path
267 // $this->open($this->sboxPath . $unsubscribeUrl);
268 // $this->waitForPageToLoad($this->getTimeoutMsec());
270 // $this->assertTrue($this->isTextPresent('Optout'));
271 // $this->assertTrue($this->isTextPresent("mailino$firstName@mailson.co.in"));
274 // $this->click('_qf_optout_next');
275 // $this->waitForPageToLoad($this->getTimeoutMsec());
277 // $this->assertTrue($this->isTextPresent('Optout'));
278 // $this->assertTrue($this->isTextPresent("mailino$firstName@mailson.co.in"));
279 // $this->assertTrue($this->isTextPresent('has been successfully opted out.'));
281 // //------ end unsubscribe -------
284 public function testAdvanceSearchAndReportCheck() {
286 $this->webtestLogin();
288 $this->openCiviPage("group/add", "reset=1", "_qf_Edit_upload");
291 $groupName = 'group_' . substr(sha1(rand()), 0, 7);
294 $this->type("title", $groupName);
297 $this->type("description", "New mailing group for Webtest");
299 // enable Mailing List
300 $this->click("group_type[2]");
302 // select Visibility as Public Pages
303 $this->select("visibility", "value=Public Pages");
306 $this->clickLink("_qf_Edit_upload");
308 // Is status message correct?
309 $this->waitForText('crm-notification-container', "The Group '$groupName' has been saved.");
311 //---- create mailing contact and add to mailing Group
312 $firstName = substr(sha1(rand()), 0, 7);
313 $this->webtestAddContact($firstName, "Mailson", "mailino$firstName@mailson.co.in");
315 // Get contact id from url.
316 $contactId = $this->urlArg('cid');
318 // go to group tab and add to mailing group
319 $this->click("css=li#tab_group a");
320 $this->waitForElementPresent("_qf_GroupContact_next");
321 $this->select("group_id", "$groupName");
322 $this->clickLink("_qf_GroupContact_next", "_qf_GroupContact_next", FALSE);
324 // configure default mail-box
325 $this->openCiviPage("admin/mailSettings", "action=update&id=1&reset=1", '_qf_MailSettings_cancel-bottom');
326 $this->type('name', 'Test Domain');
327 $this->type('domain', 'example.com');
328 $this->select('protocol', 'value=1');
329 $this->clickLink('_qf_MailSettings_next-bottom');
331 $this->openCiviPage("a/#/mailing/new");
333 //-------select recipients----------
336 $mailingName = substr(sha1(rand()), 0, 7);
337 $this->waitForElementPresent("xpath=//input[@name='mailingName']");
338 $this->type("xpath=//input[@name='mailingName']", "Mailing $mailingName Webtest");
340 // Add the test mailing group
341 $this->select2("s2id_crmUiId_8", $groupName, TRUE);
343 // do check count for Recipient
344 $this->waitForTextPresent("~1 recipient");
346 // fill subject for mailing
347 $this->type("xpath=//input[@name='subject']", "Test subject {$mailingName} for Webtest");
349 // HTML format message
350 $HTMLMessage = "This is HTML formatted content for Mailing {$mailingName} Webtest.";
351 $this->fillRichTextField("crmUiId_1", $HTMLMessage);
352 $this->click("xpath=//div[@class='preview-popup']//a[text()='Preview as HTML']");
353 $this->waitForElementPresent($HTMLMessage);
354 $this->waitForAjaxContent();
355 $this->click("xpath=//button[@title='Close']");
357 // Open Plain-text Format pane and type text format msg
358 $this->click("//div[text()='Plain Text']");
359 $this->type("xpath=//*[@name='body_text']", "This is text formatted content for Mailing {$mailingName} Webtest.");
361 $this->click("xpath=//div[@class='preview-popup']//a[text()='Preview as Plain Text']");
362 $this->waitForTextPresent("This is text formatted content for Mailing {$mailingName} Webtest.");
363 $this->waitForAjaxContent();
364 $this->click("xpath=//button[@title='Close']");
366 // select default header and footer ( with label )
367 $this->click("xpath=//ul/li/a[text()='Header and Footer']");
368 $this->select2("s2id_crmUiId_10", "Mailing Header");
369 $this->select2("s2id_crmUiId_11", "Mailing Footer");
371 //--------track and respond----------
373 // check for default settings options
374 $this->click("xpath=//ul/li/a[text()='Tracking']");
375 $this->assertChecked("url_tracking");
376 $this->assertChecked("open_tracking");
378 // click next with default settings
379 $this->click("xpath=//div[@class='crm-wizard-buttons']/button[text()='Next']");
381 $this->waitForTextPresent("Mailing $mailingName Webtest");
382 $this->click("xpath=//div[@class='content']//a[text()='~1 recipient']");
383 $this->webtestVerifyTabularData(array("$firstName Mailson" => "mailino$firstName@mailson.co.in"));
384 $this->click("xpath=//button[@title='Close']");
385 $this->waitForTextPresent("(Include: $groupName)");
387 //----------Schedule or Send------------
389 // do check for default option enabled
390 $this->assertChecked("xpath=//input[@id='schedule-send-now']");
392 // click next with nominal content
393 $this->click("xpath=//center/a/div[text()='Submit Mailing']");
395 //----------end New Mailing-------------
397 //check redirected page to Scheduled and Sent Mailings and verify for mailing name
398 $this->waitForTextPresent("Find Mailings");
399 $this->assertElementContainsText("xpath=//table[@class='selector row-highlight']/tbody//tr//td", "Mailing $mailingName Webtest");
401 // directly send schedule mailing -- not working right now
402 $this->openCiviPage("mailing/queue", "reset=1");
404 //click report link of created mailing
405 $this->clickLink("xpath=//table//tbody/tr[td[1]/text()='Mailing $mailingName Webtest']/descendant::a[text()='Report']");
407 $mailingReportUrl = $this->getLocation();
408 // do check again for recipient group
409 $this->assertElementContainsText("xpath=//fieldset/legend[text()='Recipients']/../table/tbody//tr/td", "Members of $groupName");
411 // verify successful deliveries
412 $this->verifyText("xpath=//table//tr[td/a[text()='Successful Deliveries']]/descendant::td[2]", preg_quote("1 (100.00%)"));
414 $summaryInfoLinks = array(
415 'Intended Recipients',
416 'Successful Deliveries',
422 'Unsubscribe Requests',
426 //check for report and adv search links
427 foreach ($summaryInfoLinks as $value) {
428 $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}");
429 $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}");
431 // verify mailing name
432 $this->verifyText("xpath=//table//tr[td[1]/text()='Mailing Name']/descendant::td[2]", preg_quote("Mailing $mailingName Webtest"));
434 // verify mailing subject
435 $this->verifyText("xpath=//table//tr[td[1]/text()='Subject']/descendant::td[2]", preg_quote("Test subject $mailingName for Webtest"));
437 // after asserts do clicks and confirm filters
438 $criteriaCheck = array(
439 'Intended Recipients' => array(
440 'report' => array('report_name' => 'Mailing Details', 'Mailing' => "Mailing $mailingName Webtest"),
441 'search' => array('Mailing Name IN' => "\"Mailing {$mailingName} Webtest"),
443 'Successful Deliveries' => array(
445 'report_name' => 'Mailing Details',
446 'Mailing' => "Mailing $mailingName Webtest",
447 "Delivery Status" => " Successful",
450 'Mailing Name IN' => "\"Mailing {$mailingName} Webtest",
451 'Mailing Delivery -' => "Successful",
454 'Tracked Opens' => array(
455 'report' => array('report_name' => 'Mail Opened', 'Mailing' => "Mailing $mailingName Webtest"),
457 'Mailing Name IN' => "\"Mailing {$mailingName} Webtest",
458 'Mailing: Trackable Opens -' => "Opened",
461 'Click-throughs' => array(
462 'report' => array('report_name' => 'Mail Clickthroughs', 'Mailing' => "Mailing $mailingName Webtest"),
464 'Mailing Name IN' => "\"Mailing {$mailingName} Webtest",
465 'Mailing: Trackable URL Clicks -' => "Clicked",
470 'report_name' => 'Mailing Details',
471 'Mailing' => "Mailing $mailingName Webtest",
472 'Forwarded' => 'Is equal to Yes',
474 'search' => array('Mailing Name IN' => "\"Mailing {$mailingName} Webtest", 'Mailing: -' => "Forwards"),
478 'report_name' => 'Mailing Details',
479 'Mailing' => "Mailing $mailingName Webtest",
480 'Replied' => 'Is equal to Yes',
483 'Mailing Name IN' => "\"Mailing {$mailingName} Webtest",
484 'Mailing: Trackable Replies -' => "Replied",
488 'report' => array('report_name' => 'Mail Bounces', 'Mailing' => "Mailing $mailingName Webtest"),
490 'Mailing Name IN' => "\"Mailing {$mailingName} Webtest",
491 'Mailing Delivery -' => "Bounced",
494 'Unsubscribe Requests' => array(
496 'report_name' => 'Mailing Details',
497 'Mailing' => "Mailing $mailingName Webtest",
498 'Unsubscribed' => 'Is equal to Yes',
501 'Mailing Name IN' => "\"Mailing {$mailingName} Webtest",
502 'Mailing: -' => "Unsubscribe Requests",
505 'Opt-out Requests' => array(
507 'report_name' => 'Mailing Details',
508 'Mailing' => "Mailing $mailingName Webtest",
509 'Opted-out' => 'Is equal to Yes',
512 'Mailing Name IN' => "\"Mailing {$mailingName} Webtest",
513 'Mailing: -' => "Opt-out Requests",
517 $this->criteriaCheck($criteriaCheck, $mailingReportUrl);
521 * @param $criteriaCheck
522 * @param $mailingReportUrl
524 public function criteriaCheck($criteriaCheck, $mailingReportUrl) {
525 foreach ($criteriaCheck as $key => $infoFilter) {
526 foreach ($infoFilter as $entity => $dataToCheck) {
527 $this->open($mailingReportUrl);
528 if ($entity == "report") {
529 $this->clickLink("xpath=//fieldset/legend[text()='Delivery Summary']/../table//tr[td/a[text()='{$key}']]/descendant::td[3]/span/a[1][text()='Report']");
532 $this->clickLink("xpath=//fieldset/legend[text()='Delivery Summary']/../table//tr[td/a[text()='{$key}']]/descendant::td[3]/span/a[2][text()='Advanced Search']");
534 $this->_verifyCriteria($key, $dataToCheck, $entity);
540 * @param $summaryInfo
541 * @param $dataToCheck
544 public function _verifyCriteria($summaryInfo, $dataToCheck, $entity) {
545 foreach ($dataToCheck as $key => $value) {
546 if ($entity == 'report') {
547 if ($key == 'report_name') {
548 $this->waitForTextPresent("{$value}");
551 $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}");
554 $this->waitForTextPresent("Advanced Search");
555 $assertedValue = $this->isElementPresent("xpath=//div[@class='crm-results-block']//div[@class='qill'][contains(text(),'{$key} {$value}')]");
556 if (!$assertedValue) {
557 $assertedValue = $this->isTextPresent("{$key} {$value}");
559 $this->assertTrue($assertedValue, "Criteria check for {$key} failed for Advance Search for {$summaryInfo}");