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