This repository was archived by the owner on Jan 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 110
/
Copy pathMboxMessageOldTest.php
102 lines (85 loc) · 3.14 KB
/
MboxMessageOldTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace ZendTest\Mail\Storage;
use PHPUnit\Framework\TestCase;
class MboxMessageOldTest extends TestCase
{
protected $mboxOriginalFile;
protected $mboxFile;
protected $tmpdir;
public function setUp()
{
if ($this->tmpdir == null) {
if (getenv('TESTS_ZEND_MAIL_TEMPDIR') != null) {
$this->tmpdir = getenv('TESTS_ZEND_MAIL_TEMPDIR');
} else {
$this->tmpdir = __DIR__ . '/../_files/test.tmp/';
}
if (! file_exists($this->tmpdir)) {
mkdir($this->tmpdir);
}
$count = 0;
$dh = opendir($this->tmpdir);
while (readdir($dh) !== false) {
++$count;
}
closedir($dh);
if ($count != 2) {
$this->markTestSkipped('Are you sure your tmp dir is a valid empty dir?');
return;
}
}
$this->mboxOriginalFile = __DIR__ . '/../_files/test.mbox/INBOX';
$this->mboxFile = $this->tmpdir . 'INBOX';
copy($this->mboxOriginalFile, $this->mboxFile);
}
public function tearDown()
{
unlink($this->mboxFile);
}
public function testFetchHeader()
{
$mail = new TestAsset\MboxOldMessage(['filename' => $this->mboxFile]);
$subject = $mail->getMessage(1)->subject;
$this->assertEquals('Simple Message', $subject);
}
/*
public function testFetchTopBody()
{
$mail = new TestAsset\MboxOldMessage(array('filename' => $this->mboxFile));
$content = $mail->getHeader(3, 1)->getContent();
$this->assertEquals('Fair river! in thy bright, clear flow', trim($content));
}
*/
public function testFetchMessageHeader()
{
$mail = new TestAsset\MboxOldMessage(['filename' => $this->mboxFile]);
$subject = $mail->getMessage(1)->subject;
$this->assertEquals('Simple Message', $subject);
}
public function testFetchMessageBody()
{
$mail = new TestAsset\MboxOldMessage(['filename' => $this->mboxFile]);
$content = $mail->getMessage(3)->getContent();
list($content) = explode("\n", $content, 2);
$this->assertEquals('Fair river! in thy bright, clear flow', trim($content));
}
public function testShortMbox()
{
$fh = fopen($this->mboxFile, 'w');
fputs($fh, "From \r\nSubject: test\r\nFrom \r\nSubject: test2\r\n");
fclose($fh);
$mail = new TestAsset\MboxOldMessage(['filename' => $this->mboxFile]);
$this->assertEquals($mail->countMessages(), 2);
$this->assertEquals($mail->getMessage(1)->subject, 'test');
$this->assertEquals($mail->getMessage(1)->getContent(), '');
$this->assertEquals($mail->getMessage(2)->subject, 'test2');
$this->assertEquals($mail->getMessage(2)->getContent(), '');
}
}