Merge pull request #3251 from agh1/empowered-by
[civicrm-core.git] / tests / phpunit / WebTest / Mailing / MailingTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
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. |
13 | |
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. |
18 | |
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 +--------------------------------------------------------------------+
25 */
26
27 require_once 'CiviTest/CiviSeleniumTestCase.php';
28 class WebTest_Mailing_MailingTest extends CiviSeleniumTestCase {
29
30 protected function setUp() {
31 parent::setUp();
32 }
33
34 function testAddMailing() {
35 $this->webtestLogin();
36
37 //----do create test mailing group
38 $this->openCiviPage("group/add", "reset=1", "_qf_Edit_upload");
39
40 // make group name
41 $groupName = 'group_' . substr(sha1(rand()), 0, 7);
42
43 // fill group name
44 $this->type("title", $groupName);
45
46 // fill description
47 $this->type("description", "New mailing group for Webtest");
48
49 // enable Mailing List
50 $this->click("group_type[2]");
51
52 // select Visibility as Public Pages
53 $this->select("visibility", "value=Public Pages");
54
55 // Clicking save.
56 $this->clickLink("_qf_Edit_upload");
57
58 // Is status message correct?
59 $this->waitForText('crm-notification-container', "The Group '$groupName' has been saved.");
60
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");
64
65 // Get contact id from url.
66 $contactId = $this->urlArg('cid');
67
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);
73
74 // configure default mail-box
75 $this->setupDefaultMailbox();
76
77 $this->openCiviPage("mailing/send", "reset=1", "_qf_Group_cancel");
78
79 //-------select recipients----------
80
81 // fill mailing name
82 $mailingName = substr(sha1(rand()), 0, 7);
83 $this->type("name", "Mailing $mailingName Webtest");
84
85 // Add the test mailing group
86 $this->select("includeGroups-f", "$groupName");
87 $this->click("add");
88
89 // click next
90 $this->clickLink("_qf_Group_next", "_qf_Settings_cancel", FALSE);
91
92 //--------track and respond----------
93
94 // check for default settings options
95 $this->assertChecked("url_tracking");
96 $this->assertChecked("open_tracking");
97
98 // do check count for Recipient
99 $this->assertElementContainsText('css=.messages', "Total Recipients: 1");
100
101 // no need tracking for this test
102
103 // click next with default settings
104 $this->clickLink("_qf_Settings_next", "_qf_Upload_cancel");
105
106 //--------Mailing content------------
107 // let from email address be default
108
109 // fill subject for mailing
110 $this->type("subject", "Test subject {$mailingName} for Webtest");
111
112 // check for default option enabled
113 $this->assertChecked("CIVICRM_QFID_1_upload_type");
114
115 // HTML format message
116 $HTMLMessage = "This is HTML formatted content for Mailing {$mailingName} Webtest.";
117 $this->fillRichTextField("html_message", $HTMLMessage);
118
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.");
122
123 // select default header and footer ( with label )
124 $this->select("header_id", "label=Mailing Header");
125 $this->select("footer_id", "label=Mailing Footer");
126
127 // do check count for Recipient
128 $this->assertElementContainsText('css=.messages', "Total Recipients: 1");
129
130 // click next with nominal content
131 $this->clickLink("_qf_Upload_upload", "_qf_Test_cancel");
132
133 //---------------Test------------------
134
135 ////////--Commenting test mailing and mailing preview (test mailing and preview not presently working).
136
137 // send test mailing
138 //$this->type("test_email", "mailino@mailson.co.in");
139 //$this->click("sendtest");
140
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)."));
143
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"));
147
148 ////////
149
150 // do check count for Recipient
151 $this->assertElementContainsText('css=.messages', "Total Recipients: 1");
152
153 // click next
154 $this->clickLink("_qf_Test_next", "_qf_Schedule_cancel");
155
156 //----------Schedule or Send------------
157
158 // do check for default option enabled
159 $this->assertChecked("now");
160
161 // do check count for Recipient
162 $this->assertElementContainsText('css=.messages', "Total Recipients: 1");
163
164 // finally schedule the mail by clicking submit
165 $this->clickLink("_qf_Schedule_next");
166
167 //----------end New Mailing-------------
168
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");
172
173 //--------- mail delivery verification---------
174 // test undelivered report
175
176 // click report link of created mailing
177 $this->clickLink("xpath=//table//tbody/tr[td[1]/text()='Mailing $mailingName Webtest']/descendant::a[text()='Report']");
178
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.");
181
182 // do check for recipient group
183 $this->assertElementContainsText("xpath=//fieldset/legend[text()='Recipients']/../table/tbody//tr/td", "Members of $groupName");
184
185 // directly send schedule mailing -- not working right now
186 $this->openCiviPage("mailing/queue", "reset=1");
187
188 //click report link of created mailing
189 $this->clickLink("xpath=//table//tbody/tr[td[1]/text()='Mailing $mailingName Webtest']/descendant::a[text()='Report']");
190
191 // do check again for recipient group
192 $this->assertElementContainsText("xpath=//fieldset/legend[text()='Recipients']/../table/tbody//tr/td", "Members of $groupName");
193
194 // verify intended recipients
195 $this->verifyText("xpath=//table//tr[td/a[text()='Intended Recipients']]/descendant::td[2]", preg_quote("1"));
196
197 // verify successful deliveries
198 $this->verifyText("xpath=//table//tr[td/a[text()='Successful Deliveries']]/descendant::td[2]", preg_quote("1 (100.00%)"));
199
200 // verify status
201 $this->verifyText("xpath=//table//tr[td[1]/text()='Status']/descendant::td[2]", preg_quote("Complete"));
202
203 // verify mailing name
204 $this->verifyText("xpath=//table//tr[td[1]/text()='Mailing Name']/descendant::td[2]", preg_quote("Mailing $mailingName Webtest"));
205
206 // verify mailing subject
207 $this->verifyText("xpath=//table//tr[td[1]/text()='Subject']/descendant::td[2]", preg_quote("Test subject $mailingName for Webtest"));
208
209 //---- check for delivery detail--
210
211 $this->clickLink("link=Successful Deliveries");
212
213 // check for open page
214 $this->assertElementContainsText( 'page-title', "Successful Deliveries");
215
216 // verify email
217 $this->verifyText("xpath=//table[@id='mailing_event']/tbody//tr/td[2]", preg_quote("mailino$firstName@mailson.co.in"));
218
219 $eventQueue = new CRM_Mailing_Event_DAO_Queue();
220 $eventQueue->contact_id = $contactId;
221 $eventQueue->find(TRUE);
222
223 $permission = array('edit-1-access-civimail-subscribeunsubscribe-pages');
224 $this->changePermissions($permission);
225 $this->webtestLogout();
226
227 // build forward url
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);
230
231 $this->type("email_0", substr(sha1(rand()), 0, 7) . '@example.com');
232 $this->type("email_1", substr(sha1(rand()), 0, 7) . '@example.com');
233
234 $this->click("comment_show");
235 $this->type("forward_comment", "Test Message");
236
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');
240
241 $this->webtestLogin();
242
243 $this->openCiviPage("mailing/browse/scheduled", "reset=1&scheduled=true");
244
245 //click report link of created mailing
246 $this->clickLink("xpath=//table//tbody/tr[td[1]/text()='Mailing $mailingName Webtest']/descendant::a[text()='Report']");
247
248 // verify successful forwards
249 $this->verifyText("xpath=//table//tr[td/a[text()='Forwards']]/descendant::td[2]", "2");
250
251 // Mailing is forwarded successfully to 2 email addresses.
252 //------end delivery verification---------
253
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);
261
262 // // unsubscribe link
263 // $unsubscribeUrl = "civicrm/mailing/optout?reset=1&jid={$eventQueue->job_id}&qid={$eventQueue->id}&h={$eventQueue->hash}&confirm=1";
264
265 // // logout to unsubscribe
266 // $this->webtestLogout();
267
268 // // click(visit) unsubscribe path
269 // $this->open($this->sboxPath . $unsubscribeUrl);
270 // $this->waitForPageToLoad($this->getTimeoutMsec());
271
272 // $this->assertTrue($this->isTextPresent('Optout'));
273 // $this->assertTrue($this->isTextPresent("mailino$firstName@mailson.co.in"));
274
275 // // unsubscribe
276 // $this->click('_qf_optout_next');
277 // $this->waitForPageToLoad($this->getTimeoutMsec());
278
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.'));
282
283 // //------ end unsubscribe -------
284 }
285
286 function testAdvanceSearchAndReportCheck() {
287
288 $this->webtestLogin();
289
290 $this->openCiviPage("group/add", "reset=1", "_qf_Edit_upload");
291
292 // make group name
293 $groupName = 'group_' . substr(sha1(rand()), 0, 7);
294
295 // fill group name
296 $this->type("title", $groupName);
297
298 // fill description
299 $this->type("description", "New mailing group for Webtest");
300
301 // enable Mailing List
302 $this->click("group_type[2]");
303
304 // select Visibility as Public Pages
305 $this->select("visibility", "value=Public Pages");
306
307 // Clicking save.
308 $this->clickLink("_qf_Edit_upload");
309
310 // Is status message correct?
311 $this->waitForText('crm-notification-container', "The Group '$groupName' has been saved.");
312
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");
316
317 // Get contact id from url.
318 $contactId = $this->urlArg('cid');
319
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);
325
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');
332
333 // Go to Schedule and Send Mailing form
334 $this->openCiviPage('mailing/send', 'reset=1', '_qf_Group_cancel');
335
336 //-------select recipients----------
337
338 // fill mailing name
339 $mailingName = substr(sha1(rand()), 0, 7);
340 $this->type("name", "Mailing $mailingName Webtest");
341
342 // Add the test mailing group
343 $this->select("includeGroups-f", "$groupName");
344 $this->click("add");
345
346 // click next
347 $this->click("_qf_Group_next");
348 $this->waitForElementPresent("_qf_Settings_cancel");
349
350 //--------track and respond----------
351
352 // check for default settings options
353 $this->assertChecked("url_tracking");
354 $this->assertChecked("open_tracking");
355
356 // do check count for Recipient
357 $this->assertElementContainsText('css=.messages', "Total Recipients: 1");
358
359 // click next with default settings
360 $this->clickLink("_qf_Settings_next");
361
362 // fill subject for mailing
363 $this->type("subject", "Test subject {$mailingName} for Webtest");
364
365 // check for default option enabled
366 $this->assertChecked("CIVICRM_QFID_1_upload_type");
367
368 // HTML format message
369 $HTMLMessage = "This is HTML formatted content for Mailing {$mailingName} Webtest.";
370 $this->fillRichTextField("html_message", $HTMLMessage);
371
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.");
375
376 // select default header and footer ( with label )
377 $this->select("header_id", "label=Mailing Header");
378 $this->select("footer_id", "label=Mailing Footer");
379
380 // do check count for Recipient
381 $this->assertElementContainsText('css=.messages', "Total Recipients: 1");
382
383 // click next with nominal content
384 $this->clickLink("_qf_Upload_upload", "_qf_Test_cancel");
385
386 // do check count for Recipient
387 $this->assertElementContainsText('css=.messages', "Total Recipients: 1");
388
389 // click next
390 $this->clickLink("_qf_Test_next", "_qf_Schedule_cancel");
391
392 //----------Schedule or Send------------
393
394 // do check for default option enabled
395 $this->assertChecked("now");
396
397 // do check count for Recipient
398 $this->assertElementContainsText('css=.messages', "Total Recipients: 1");
399
400 // finally schedule the mail by clicking submit
401 $this->clickLink("_qf_Schedule_next");
402
403 //----------end New Mailing-------------
404
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");
408
409 // directly send schedule mailing -- not working right now
410 $this->openCiviPage("mailing/queue", "reset=1");
411
412 //click report link of created mailing
413 $this->clickLink("xpath=//table//tbody/tr[td[1]/text()='Mailing $mailingName Webtest']/descendant::a[text()='Report']");
414
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");
418
419 // verify successful deliveries
420 $this->verifyText("xpath=//table//tr[td/a[text()='Successful Deliveries']]/descendant::td[2]", preg_quote("1 (100.00%)"));
421
422 $summaryInfoLinks = array('Intended Recipients', 'Successful Deliveries', 'Tracked Opens', 'Click-throughs', 'Forwards', 'Replies', 'Bounces', 'Unsubscribe Requests','Opt-out Requests');
423
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}");
428 }
429 // verify mailing name
430 $this->verifyText("xpath=//table//tr[td[1]/text()='Mailing Name']/descendant::td[2]", preg_quote("Mailing $mailingName Webtest"));
431
432 // verify mailing subject
433 $this->verifyText("xpath=//table//tr[td[1]/text()='Subject']/descendant::td[2]", preg_quote("Test subject $mailingName for Webtest"));
434
435 // after asserts do clicks and confirm filters
436 $criteriaCheck =
437 array(
438 'Intended Recipients' =>
439 array(
440 'report' => array('report_name' => 'Mailing Details', 'Mailing' => "Mailing $mailingName Webtest"),
441 'search' => array('Mailing Name IN' => "\"Mailing {$mailingName} Webtest")
442 ),
443 'Successful Deliveries' =>
444 array(
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")
448 ),
449 'Tracked Opens' =>
450 array(
451 'report' => array('report_name' => 'Mail Opened', 'Mailing' => "Mailing $mailingName Webtest"),
452 'search' => array('Mailing Name IN' => "\"Mailing {$mailingName} Webtest", 'Mailing: Trackable Opens -' => "Opened")
453 ),
454 'Click-throughs' =>
455 array(
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")
458 ),
459 'Forwards' =>
460 array(
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")
464 ),
465 'Replies' =>
466 array(
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")
470 ),
471 'Bounces' =>
472 array(
473 'report' => array('report_name' => 'Mail Bounces', 'Mailing' => "Mailing $mailingName Webtest"),
474 'search' => array('Mailing Name IN' => "\"Mailing {$mailingName} Webtest", 'Mailing Delivery -' => "Bounced")
475 ),
476 'Unsubscribe Requests' =>
477 array(
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")
481 ),
482 'Opt-out Requests' =>
483 array(
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")
487 ),
488 );
489 $this->criteriaCheck($criteriaCheck, $mailingReportUrl);
490 }
491
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']");
498 } else {
499 $this->clickLink("xpath=//fieldset/legend[text()='Delivery Summary']/../table//tr[td/a[text()='{$key}']]/descendant::td[3]/span/a[2][text()='Advanced Search']");
500 }
501 $this-> _verifyCriteria($key, $dataToCheck, $entity);
502 }
503 }
504 }
505
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}");
511 continue;
512 }
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}");
514 } else {
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}");
519 }
520 $this->assertTrue($assertedValue,"Criteria check for {$key} failed for Advance Search for {$summaryInfo}");
521 }
522 }
523 }
524 }