INFRA-132 - Remove white space after an opening "(" or before a closing ")"
[civicrm-core.git] / tests / phpunit / WebTest / Mailing / MailingTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
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
29 /**
30 * Class WebTest_Mailing_MailingTest
31 */
32 class WebTest_Mailing_MailingTest extends CiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
38 public function testAddMailing() {
39 $this->webtestLogin();
40
41 //----do create test mailing group
42 $this->openCiviPage("group/add", "reset=1", "_qf_Edit_upload");
43
44 // make group name
45 $groupName = 'group_' . substr(sha1(rand()), 0, 7);
46
47 // fill group name
48 $this->type("title", $groupName);
49
50 // fill description
51 $this->type("description", "New mailing group for Webtest");
52
53 // enable Mailing List
54 $this->click("group_type[2]");
55
56 // select Visibility as Public Pages
57 $this->select("visibility", "value=Public Pages");
58
59 // Clicking save.
60 $this->clickLink("_qf_Edit_upload");
61
62 // Is status message correct?
63 $this->waitForText('crm-notification-container', "The Group '$groupName' has been saved.");
64
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");
68
69 // Get contact id from url.
70 $contactId = $this->urlArg('cid');
71
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);
77
78 // configure default mail-box
79 $this->setupDefaultMailbox();
80
81 $this->openCiviPage("mailing/send", "reset=1", "_qf_Group_cancel");
82
83 //-------select recipients----------
84
85 // fill mailing name
86 $mailingName = substr(sha1(rand()), 0, 7);
87 $this->type("name", "Mailing $mailingName Webtest");
88
89 // Add the test mailing group
90 $this->select("includeGroups", "$groupName");
91
92 // click next
93 $this->clickLink("_qf_Group_next", "_qf_Settings_cancel", FALSE);
94
95 //--------track and respond----------
96
97 // check for default settings options
98 $this->assertChecked("url_tracking");
99 $this->assertChecked("open_tracking");
100
101 // do check count for Recipient
102 $this->assertElementContainsText('css=.messages', "Total Recipients: 1");
103
104 // no need tracking for this test
105
106 // click next with default settings
107 $this->clickLink("_qf_Settings_next", "_qf_Upload_cancel");
108
109 //--------Mailing content------------
110 // let from email address be default
111
112 // fill subject for mailing
113 $this->type("subject", "Test subject {$mailingName} for Webtest");
114
115 // check for default option enabled
116 $this->assertChecked("CIVICRM_QFID_1_upload_type");
117
118 // HTML format message
119 $HTMLMessage = "This is HTML formatted content for Mailing {$mailingName} Webtest.";
120 $this->fillRichTextField("html_message", $HTMLMessage);
121
122 // Open Plain-text Format pane and type text format msg
123 $this->click("//fieldset[@id='compose_id']/div[2]/div[1]");
124 $this->type("text_message", "This is text formatted content for Mailing {$mailingName} Webtest.");
125
126 // select default header and footer ( with label )
127 $this->select("header_id", "label=Mailing Header");
128 $this->select("footer_id", "label=Mailing Footer");
129
130 // do check count for Recipient
131 $this->assertElementContainsText('css=.messages', "Total Recipients: 1");
132
133 // click next with nominal content
134 $this->clickLink("_qf_Upload_upload", "_qf_Test_cancel");
135
136 //---------------Test------------------
137
138 ////////--Commenting test mailing and mailing preview (test mailing and preview not presently working).
139
140 // send test mailing
141 //$this->type("test_email", "mailino@mailson.co.in");
142 //$this->click("sendtest");
143
144 // verify status message
145 //$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)."));
146
147 // check mailing preview
148 //$this->click("//form[@id='Test']/div[2]/div[4]/div[1]");
149 //$this->assertTrue($this->isTextPresent("this is test content for Mailing $mailingName Webtest"));
150
151 ////////
152
153 // do check count for Recipient
154 $this->assertElementContainsText('css=.messages', "Total Recipients: 1");
155
156 // click next
157 $this->clickLink("_qf_Test_next", "_qf_Schedule_cancel");
158
159 //----------Schedule or Send------------
160
161 // do check for default option enabled
162 $this->assertChecked("now");
163
164 // do check count for Recipient
165 $this->assertElementContainsText('css=.messages', "Total Recipients: 1");
166
167 // finally schedule the mail by clicking submit
168 $this->clickLink("_qf_Schedule_next");
169
170 //----------end New Mailing-------------
171
172 //check redirected page to Scheduled and Sent Mailings and verify for mailing name
173 $this->assertElementContainsText('page-title', "Find Mailings");
174 $this->assertElementContainsText("xpath=//table[@class='selector row-highlight']/tbody//tr//td", "Mailing $mailingName Webtest");
175
176 //--------- mail delivery verification---------
177 // test undelivered report
178
179 // click report link of created mailing
180 $this->clickLink("xpath=//table//tbody/tr[td[1]/text()='Mailing $mailingName Webtest']/descendant::a[text()='Report']");
181
182 // verify undelivered status message
183 $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.");
184
185 // do check for recipient group
186 $this->assertElementContainsText("xpath=//fieldset/legend[text()='Recipients']/../table/tbody//tr/td", "Members of $groupName");
187
188 // directly send schedule mailing -- not working right now
189 $this->openCiviPage("mailing/queue", "reset=1");
190
191 //click report link of created mailing
192 $this->clickLink("xpath=//table//tbody/tr[td[1]/text()='Mailing $mailingName Webtest']/descendant::a[text()='Report']");
193
194 // do check again for recipient group
195 $this->assertElementContainsText("xpath=//fieldset/legend[text()='Recipients']/../table/tbody//tr/td", "Members of $groupName");
196
197 // verify intended recipients
198 $this->verifyText("xpath=//table//tr[td/a[text()='Intended Recipients']]/descendant::td[2]", preg_quote("1"));
199
200 // verify successful deliveries
201 $this->verifyText("xpath=//table//tr[td/a[text()='Successful Deliveries']]/descendant::td[2]", preg_quote("1 (100.00%)"));
202
203 // verify status
204 $this->verifyText("xpath=//table//tr[td[1]/text()='Status']/descendant::td[2]", preg_quote("Complete"));
205
206 // verify mailing name
207 $this->verifyText("xpath=//table//tr[td[1]/text()='Mailing Name']/descendant::td[2]", preg_quote("Mailing $mailingName Webtest"));
208
209 // verify mailing subject
210 $this->verifyText("xpath=//table//tr[td[1]/text()='Subject']/descendant::td[2]", preg_quote("Test subject $mailingName for Webtest"));
211
212 //---- check for delivery detail--
213
214 $this->clickLink("link=Successful Deliveries");
215
216 // check for open page
217 $this->assertElementContainsText('page-title', "Successful Deliveries");
218
219 // verify email
220 $this->verifyText("xpath=//table[@id='mailing_event']/tbody//tr/td[2]", preg_quote("mailino$firstName@mailson.co.in"));
221
222 $eventQueue = new CRM_Mailing_Event_DAO_Queue();
223 $eventQueue->contact_id = $contactId;
224 $eventQueue->find(TRUE);
225
226 $permission = array('edit-1-access-civimail-subscribeunsubscribe-pages');
227 $this->changePermissions($permission);
228 $this->webtestLogout();
229
230 // build forward url
231 $forwardUrl = array("mailing/forward", "reset=1&jid={$eventQueue->job_id}&qid={$eventQueue->id}&h={$eventQueue->hash}");
232 $this->openCiviPage($forwardUrl[0], $forwardUrl[1], NULL);
233
234 $this->type("email_0", substr(sha1(rand()), 0, 7) . '@example.com');
235 $this->type("email_1", substr(sha1(rand()), 0, 7) . '@example.com');
236
237 $this->click("comment_show");
238 $this->type("forward_comment", "Test Message");
239
240 $this->click("_qf_ForwardMailing_next-bottom");
241 $this->waitForPageToLoad($this->getTimeoutMsec());
242 $this->assertElementContainsText('css=div.messages', 'Mailing is forwarded successfully to 2 email addresses');
243
244 $this->webtestLogin();
245
246 $this->openCiviPage("mailing/browse/scheduled", "reset=1&scheduled=true");
247
248 //click report link of created mailing
249 $this->clickLink("xpath=//table//tbody/tr[td[1]/text()='Mailing $mailingName Webtest']/descendant::a[text()='Report']");
250
251 // verify successful forwards
252 $this->verifyText("xpath=//table//tr[td/a[text()='Forwards']]/descendant::td[2]", "2");
253
254 // Mailing is forwarded successfully to 2 email addresses.
255 //------end delivery verification---------
256
257 // //------ check with unsubscribe -------
258 // // FIX ME: there is an issue with DSN setting for Webtest, need to handle by seperate DSN setting for Webtests
259 // // build unsubscribe link
260 // require_once 'CRM/Mailing/Event/DAO/Queue.php';
261 // $eventQueue = new CRM_Mailing_Event_DAO_Queue( );
262 // $eventQueue->contact_id = $contactId;
263 // $eventQueue->find(true);
264
265 // // unsubscribe link
266 // $unsubscribeUrl = "civicrm/mailing/optout?reset=1&jid={$eventQueue->job_id}&qid={$eventQueue->id}&h={$eventQueue->hash}&confirm=1";
267
268 // // logout to unsubscribe
269 // $this->webtestLogout();
270
271 // // click(visit) unsubscribe path
272 // $this->open($this->sboxPath . $unsubscribeUrl);
273 // $this->waitForPageToLoad($this->getTimeoutMsec());
274
275 // $this->assertTrue($this->isTextPresent('Optout'));
276 // $this->assertTrue($this->isTextPresent("mailino$firstName@mailson.co.in"));
277
278 // // unsubscribe
279 // $this->click('_qf_optout_next');
280 // $this->waitForPageToLoad($this->getTimeoutMsec());
281
282 // $this->assertTrue($this->isTextPresent('Optout'));
283 // $this->assertTrue($this->isTextPresent("mailino$firstName@mailson.co.in"));
284 // $this->assertTrue($this->isTextPresent('has been successfully opted out.'));
285
286 // //------ end unsubscribe -------
287 }
288
289 public function testAdvanceSearchAndReportCheck() {
290
291 $this->webtestLogin();
292
293 $this->openCiviPage("group/add", "reset=1", "_qf_Edit_upload");
294
295 // make group name
296 $groupName = 'group_' . substr(sha1(rand()), 0, 7);
297
298 // fill group name
299 $this->type("title", $groupName);
300
301 // fill description
302 $this->type("description", "New mailing group for Webtest");
303
304 // enable Mailing List
305 $this->click("group_type[2]");
306
307 // select Visibility as Public Pages
308 $this->select("visibility", "value=Public Pages");
309
310 // Clicking save.
311 $this->clickLink("_qf_Edit_upload");
312
313 // Is status message correct?
314 $this->waitForText('crm-notification-container', "The Group '$groupName' has been saved.");
315
316 //---- create mailing contact and add to mailing Group
317 $firstName = substr(sha1(rand()), 0, 7);
318 $this->webtestAddContact($firstName, "Mailson", "mailino$firstName@mailson.co.in");
319
320 // Get contact id from url.
321 $contactId = $this->urlArg('cid');
322
323 // go to group tab and add to mailing group
324 $this->click("css=li#tab_group a");
325 $this->waitForElementPresent("_qf_GroupContact_next");
326 $this->select("group_id", "$groupName");
327 $this->clickLink("_qf_GroupContact_next", "_qf_GroupContact_next", FALSE);
328
329 // configure default mail-box
330 $this->openCiviPage("admin/mailSettings", "action=update&id=1&reset=1", '_qf_MailSettings_cancel-bottom');
331 $this->type('name', 'Test Domain');
332 $this->type('domain', 'example.com');
333 $this->select('protocol', 'value=1');
334 $this->clickLink('_qf_MailSettings_next-bottom');
335
336 // Go to Schedule and Send Mailing form
337 $this->openCiviPage('mailing/send', 'reset=1', '_qf_Group_cancel');
338
339 //-------select recipients----------
340
341 // fill mailing name
342 $mailingName = substr(sha1(rand()), 0, 7);
343 $this->type("name", "Mailing $mailingName Webtest");
344
345 // Add the test mailing group
346 $this->select("includeGroups", "$groupName");
347
348 // click next
349 $this->click("_qf_Group_next");
350 $this->waitForElementPresent("_qf_Settings_cancel");
351
352 //--------track and respond----------
353
354 // check for default settings options
355 $this->assertChecked("url_tracking");
356 $this->assertChecked("open_tracking");
357
358 // do check count for Recipient
359 $this->assertElementContainsText('css=.messages', "Total Recipients: 1");
360
361 // click next with default settings
362 $this->clickLink("_qf_Settings_next");
363
364 // fill subject for mailing
365 $this->type("subject", "Test subject {$mailingName} for Webtest");
366
367 // check for default option enabled
368 $this->assertChecked("CIVICRM_QFID_1_upload_type");
369
370 // HTML format message
371 $HTMLMessage = "This is HTML formatted content for Mailing {$mailingName} Webtest.";
372 $this->fillRichTextField("html_message", $HTMLMessage);
373
374 // Open Plain-text Format pane and type text format msg
375 $this->click("//fieldset[@id='compose_id']/div[2]/div[1]");
376 $this->type("text_message", "This is text formatted content for Mailing {$mailingName} Webtest.");
377
378 // select default header and footer ( with label )
379 $this->select("header_id", "label=Mailing Header");
380 $this->select("footer_id", "label=Mailing Footer");
381
382 // do check count for Recipient
383 $this->assertElementContainsText('css=.messages', "Total Recipients: 1");
384
385 // click next with nominal content
386 $this->clickLink("_qf_Upload_upload", "_qf_Test_cancel");
387
388 // do check count for Recipient
389 $this->assertElementContainsText('css=.messages', "Total Recipients: 1");
390
391 // click next
392 $this->clickLink("_qf_Test_next", "_qf_Schedule_cancel");
393
394 //----------Schedule or Send------------
395
396 // do check for default option enabled
397 $this->assertChecked("now");
398
399 // do check count for Recipient
400 $this->assertElementContainsText('css=.messages', "Total Recipients: 1");
401
402 // finally schedule the mail by clicking submit
403 $this->clickLink("_qf_Schedule_next");
404
405 //----------end New Mailing-------------
406
407 //check redirected page to Scheduled and Sent Mailings and verify for mailing name
408 $this->assertElementContainsText('page-title', "Find Mailings");
409 $this->assertElementContainsText("xpath=//table[@class='selector row-highlight']/tbody//tr//td", "Mailing $mailingName Webtest");
410
411 // directly send schedule mailing -- not working right now
412 $this->openCiviPage("mailing/queue", "reset=1");
413
414 //click report link of created mailing
415 $this->clickLink("xpath=//table//tbody/tr[td[1]/text()='Mailing $mailingName Webtest']/descendant::a[text()='Report']");
416
417 $mailingReportUrl = $this->getLocation();
418 // do check again for recipient group
419 $this->assertElementContainsText("xpath=//fieldset/legend[text()='Recipients']/../table/tbody//tr/td", "Members of $groupName");
420
421 // verify successful deliveries
422 $this->verifyText("xpath=//table//tr[td/a[text()='Successful Deliveries']]/descendant::td[2]", preg_quote("1 (100.00%)"));
423
424 $summaryInfoLinks = array('Intended Recipients', 'Successful Deliveries', 'Tracked Opens', 'Click-throughs', 'Forwards', 'Replies', 'Bounces', 'Unsubscribe Requests', 'Opt-out Requests');
425
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}");
430 }
431 // verify mailing name
432 $this->verifyText("xpath=//table//tr[td[1]/text()='Mailing Name']/descendant::td[2]", preg_quote("Mailing $mailingName Webtest"));
433
434 // verify mailing subject
435 $this->verifyText("xpath=//table//tr[td[1]/text()='Subject']/descendant::td[2]", preg_quote("Test subject $mailingName for Webtest"));
436
437 // after asserts do clicks and confirm filters
438 $criteriaCheck =
439 array(
440 'Intended Recipients' =>
441 array(
442 'report' => array('report_name' => 'Mailing Details', 'Mailing' => "Mailing $mailingName Webtest"),
443 'search' => array('Mailing Name IN' => "\"Mailing {$mailingName} Webtest")
444 ),
445 'Successful Deliveries' =>
446 array(
447 'report' => array(
448 'report_name' => 'Mailing Details',
449 'Mailing' => "Mailing $mailingName Webtest",
450 "Delivery Status" => " Successful"),
451 'search' => array('Mailing Name IN' => "\"Mailing {$mailingName} Webtest", 'Mailing Delivery -' => "Successful")
452 ),
453 'Tracked Opens' =>
454 array(
455 'report' => array('report_name' => 'Mail Opened', 'Mailing' => "Mailing $mailingName Webtest"),
456 'search' => array('Mailing Name IN' => "\"Mailing {$mailingName} Webtest", 'Mailing: Trackable Opens -' => "Opened")
457 ),
458 'Click-throughs' =>
459 array(
460 'report' => array('report_name' => 'Mail Clickthroughs', 'Mailing' => "Mailing $mailingName Webtest"),
461 'search' => array('Mailing Name IN' => "\"Mailing {$mailingName} Webtest", 'Mailing: Trackable URL Clicks -' => "Clicked")
462 ),
463 'Forwards' =>
464 array(
465 'report' => array(
466 'report_name' => 'Mailing Details',
467 'Mailing' => "Mailing $mailingName Webtest",
468 'Forwarded' => 'Is equal to Yes'),
469 'search' => array('Mailing Name IN' => "\"Mailing {$mailingName} Webtest", 'Mailing: -' => "Forwards")
470 ),
471 'Replies' =>
472 array(
473 'report' => array(
474 'report_name' => 'Mailing Details',
475 'Mailing' => "Mailing $mailingName Webtest",
476 'Replied' => 'Is equal to Yes'),
477 'search' => array('Mailing Name IN' => "\"Mailing {$mailingName} Webtest", 'Mailing: Trackable Replies -' => "Replied")
478 ),
479 'Bounces' =>
480 array(
481 'report' => array('report_name' => 'Mail Bounces', 'Mailing' => "Mailing $mailingName Webtest"),
482 'search' => array('Mailing Name IN' => "\"Mailing {$mailingName} Webtest", 'Mailing Delivery -' => "Bounced")
483 ),
484 'Unsubscribe Requests' =>
485 array(
486 'report' => array(
487 'report_name' => 'Mailing Details',
488 'Mailing' => "Mailing $mailingName Webtest",
489 'Unsubscribed' => 'Is equal to Yes'),
490 'search' => array('Mailing Name IN' => "\"Mailing {$mailingName} Webtest", 'Mailing: -' => "Unsubscribe Requests")
491 ),
492 'Opt-out Requests' =>
493 array(
494 'report' => array(
495 'report_name' => 'Mailing Details',
496 'Mailing' => "Mailing $mailingName Webtest",
497 'Opted-out' => 'Is equal to Yes'),
498 'search' => array('Mailing Name IN' => "\"Mailing {$mailingName} Webtest", 'Mailing: -' => "Opt-out Requests")
499 ),
500 );
501 $this->criteriaCheck($criteriaCheck, $mailingReportUrl);
502 }
503
504 /**
505 * @param $criteriaCheck
506 * @param $mailingReportUrl
507 */
508 public function criteriaCheck($criteriaCheck, $mailingReportUrl) {
509 foreach ($criteriaCheck as $key => $infoFilter) {
510 foreach ($infoFilter as $entity => $dataToCheck) {
511 $this->open($mailingReportUrl);
512 if ($entity == "report") {
513 $this->clickLink("xpath=//fieldset/legend[text()='Delivery Summary']/../table//tr[td/a[text()='{$key}']]/descendant::td[3]/span/a[1][text()='Report']");
514 }
515 else {
516 $this->clickLink("xpath=//fieldset/legend[text()='Delivery Summary']/../table//tr[td/a[text()='{$key}']]/descendant::td[3]/span/a[2][text()='Advanced Search']");
517 }
518 $this-> _verifyCriteria($key, $dataToCheck, $entity);
519 }
520 }
521 }
522
523 /**
524 * @param $summaryInfo
525 * @param $dataToCheck
526 * @param $entity
527 */
528 public function _verifyCriteria($summaryInfo, $dataToCheck, $entity) {
529 foreach ($dataToCheck as $key => $value) {
530 if ($entity == 'report') {
531 if ($key == 'report_name') {
532 $this->assertElementContainsText('page-title', "{$value}");
533 continue;
534 }
535 $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}");
536 }
537 else {
538 $this->assertElementContainsText('page-title', "Advanced Search");
539 $assertedValue = $this->isElementPresent("xpath=//div[@class='crm-results-block']//div[@class='qill'][contains(text(),'{$key} {$value}')]");
540 if (!$assertedValue) {
541 $assertedValue = $this->isTextPresent("{$key} {$value}");
542 }
543 $this->assertTrue($assertedValue, "Criteria check for {$key} failed for Advance Search for {$summaryInfo}");
544 }
545 }
546 }
547 }