synchronizeUsers minor fixups
[civicrm-core.git] / tests / phpunit / WebTest / Mailing / SpoolTest.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
81621fee 4 | CiviCRM version 4.7 |
6a488035 5 +--------------------------------------------------------------------+
e7112fa7 6 | Copyright CiviCRM LLC (c) 2004-2015 |
6a488035
TO
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 +--------------------------------------------------------------------+
d25dd0ee 25 */
6a488035 26
6a488035
TO
27require_once 'CiviTest/CiviSeleniumTestCase.php';
28require_once 'CiviTest/CiviMailUtils.php';
29require_once 'ezc/Base/src/ezc_bootstrap.php';
30require_once 'ezc/autoload/mail_autoload.php';
e9479dcf
EM
31
32/**
33 * Class WebTest_Mailing_SpoolTest
34 */
6a488035
TO
35class WebTest_Mailing_SpoolTest extends CiviSeleniumTestCase {
36
37 protected function setUp() {
38 parent::setUp();
39 }
40
00be9182 41 public function testSpooledMailing() {
6a488035 42
6a488035
TO
43 $this->webtestLogin();
44
45 // Start spooling mail
6c6e6187 46 $mut = new CiviMailUtils($this, TRUE);
6a488035
TO
47
48 // Add a contact
49 $fname = substr(sha1(rand()), 0, 6);
50 $lname = substr(sha1(rand()), 0, 6);
51 $email = $this->webtestAddContact($fname, $lname, TRUE);
52
53 // Get the contact id of the newly added contact
a471a3b6 54 $cid = $this->urlArg('cid');
6a488035
TO
55
56 // Send an email to the added contact
acd28991 57 $this->openCiviPage("activity/email/add", "action=add&reset=1&cid={$cid}&selectedChild=activity&atype=3");
76e86fd8
CW
58 $this->type('subject', 'test spool');
59 $this->fillRichTextField('html_message', 'Unit tests keep children safe.');
60 $this->click("_qf_Email_upload");
6a488035
TO
61
62 // Retrieve an ezc mail object version of the email
76e86fd8 63 $msg = $mut->getMostRecentEmail('ezc');
6a488035 64
76e86fd8
CW
65 $this->assertNotEmpty($msg, 'Mail message empty or not found.');
66 $this->assertEquals($msg->subject, 'test spool');
67 // should really walk through the 'to' array, but this is legal according to the docs
68 $this->assertContains($email, implode(';', $msg->to), 'Recipient incorrect.');
6a488035 69
76e86fd8
CW
70 $context = new ezcMailPartWalkContext(array(get_class($this), 'mailWalkCallback'));
71 $msg->walkParts($context, $msg);
6a488035
TO
72
73 /*
74 * Now try a regular activity with cc to assignee
75 */
76 $this->WebtestAddActivity();
76e86fd8
CW
77 $msg = $mut->getMostRecentEmail('raw');
78 $this->assertNotEmpty($msg, 'Mail message empty or not found.');
79 $this->assertContains('Subject: This is subject of test activity', $msg, 'Subject of email is wrong.');
6a488035
TO
80
81 $mut->stop();
82 }
83
4cbe18b8
EM
84 /**
85 * @param $context
86 * @param $mailPart
87 */
76e86fd8
CW
88 public static function mailWalkCallback($context, $mailPart) {
89 if ($mailPart instanceof ezcMailText) {
90 self::assertEquals($mailPart->subType, 'html');
91 self::assertContains('Unit tests keep children safe', $mailPart->generateBody());
6a488035
TO
92 }
93
94 $disp = $mailPart->contentDisposition;
76e86fd8
CW
95 if ($disp) {
96
6a488035
TO
97 }
98 }
96025800 99
6a488035 100}