Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 20 additions & 17 deletions test/TNEFAttachmentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function testDecode3()
/**
* @dataProvider tnefFileProvider
*/
public function testDecodeAuto($tnefFile, $listFile) {
public function testDecodeAuto($tnefFile, $listFile, $nestedListFile) {
$buffer = file_get_contents($tnefFile);
$attachment = new TNEFAttachment(false, true);

Expand All @@ -35,21 +35,19 @@ public function testDecodeAuto($tnefFile, $listFile) {
}
$attachment->decodeTnef($buffer);

$list = file($listFile, FILE_IGNORE_NEW_LINES + FILE_SKIP_EMPTY_LINES);
$this->assertEquals(count($list), count($attachment->files));
$decodedFiles = array_map(function(TNEFFileBase$file) {return $file->getName();}, $attachment->files);
$list = $this->readList($listFile);
$decodedFiles = array_map(function($file) {return [$file->getName(), md5($file->getContent())];}, $attachment->getFiles());

$withoutRtf = array_filter($list, array($this, "endsWithRtf"));
$withoutRtfdecoded = array_filter($decodedFiles, array($this, "endsWithRtf"));
$this->assertEquals($list, $decodedFiles);

$rtfs = array_diff($withoutRtf, $list);
$rtfsDecoded = array_diff($withoutRtfdecoded, $decodedFiles);
if ($nestedListFile === null) {
return;
}

$this->assertEquals(count($rtfs), count($rtfsDecoded));
$list = $this->readList($nestedListFile);
$decodedFiles = array_map(function($file) {return [$file->getName(), md5($file->getContent())];}, $attachment->getFilesNested());

sort($withoutRtfdecoded);
sort($withoutRtf);
$this->assertEquals($withoutRtf, $withoutRtfdecoded);
$this->assertEquals($list, $decodedFiles);
}

public static function tnefFileProvider() {
Expand All @@ -58,22 +56,27 @@ public static function tnefFileProvider() {
foreach ($tnefFiles as $tnefFile) {
$pathinfo = pathinfo($tnefFile);
$listFile = $pathinfo['dirname'] . '/' . $pathinfo['filename'] . '.list';
$nestedListFile = $pathinfo['dirname'] . '/' . $pathinfo['filename'] . '.nested.list';

$result[] = [
$tnefFile,
file_exists($listFile) ? $listFile : null,
file_exists($nestedListFile) ? $nestedListFile : null,
];
}

return $result;
}

private function endsWithRtf($value) {
$arr = explode('.', $value);
if (count($arr) < 2) {
return false;
private function readList(string $filename): array
{
$arr = [];
$handle = fopen($filename, 'r');
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$arr[] = $data;
}
fclose($handle);

return $arr[1] !== 'rtf';
return $arr;
}
}
8 changes: 4 additions & 4 deletions test/testfiles/MAPI_ATTACH_DATA_OBJ.list
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VIA_Nytt_1402.doc
VIA_Nytt_1402.pdf
VIA_Nytt_14021.htm
MAPI_ATTACH_DATA_OBJ-body.rtf
EmbeddedRTF.rtf,45c10a4a43d0e5249146d44bc3aea596
VIA_Nytt_1402.doc,d41d8cd98f00b204e9800998ecf8427e
VIA_Nytt_1402.pdf,d41d8cd98f00b204e9800998ecf8427e
VIA_Nytt_14021.htm,d41d8cd98f00b204e9800998ecf8427e
12 changes: 12 additions & 0 deletions test/testfiles/MAPI_ATTACH_DATA_OBJ.nested.list
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
EmbeddedRTF.rtf,45c10a4a43d0e5249146d44bc3aea596
VIA_Nytt_1402.doc,d41d8cd98f00b204e9800998ecf8427e
VIA_Nytt_1402.pdf,d41d8cd98f00b204e9800998ecf8427e
VIA_Nytt_14021.htm,d41d8cd98f00b204e9800998ecf8427e
EmbeddedRTF.rtf,45c10a4a43d0e5249146d44bc3aea596
VIA_Nytt_1402.doc,d41d8cd98f00b204e9800998ecf8427e
VIA_Nytt_1402.pdf,d41d8cd98f00b204e9800998ecf8427e
VIA_Nytt_14021.htm,d41d8cd98f00b204e9800998ecf8427e
EmbeddedRTF.rtf,45c10a4a43d0e5249146d44bc3aea596
VIA_Nytt_1402.doc,d41d8cd98f00b204e9800998ecf8427e
VIA_Nytt_1402.pdf,d41d8cd98f00b204e9800998ecf8427e
VIA_Nytt_14021.htm,d41d8cd98f00b204e9800998ecf8427e
4 changes: 2 additions & 2 deletions test/testfiles/MAPI_OBJECT.list
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Untitled_Attachment
MAPI_OBJECT-body.rtf
EmbeddedRTF.rtf,02c44ac31695230a1014fb4c5cbb3230
Untitled_Attachment,d41d8cd98f00b204e9800998ecf8427e
8 changes: 4 additions & 4 deletions test/testfiles/data-before-name.list
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
AUTOEXEC.BAT
CONFIG.SYS
boot.ini
data-before-name-body.rtf
EmbeddedRTF.rtf,1ea92c02882f8f0cb655d062ee90006a
AUTOEXEC.BAT,d41d8cd98f00b204e9800998ecf8427e
CONFIG.SYS,d41d8cd98f00b204e9800998ecf8427e
boot.ini,9abbbabd47c8544e7909b4c38ba9c009
4 changes: 2 additions & 2 deletions test/testfiles/long-filename.list
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
long-filename-body.rtf
allproductsmar2000.dat
EmbeddedRTF.rtf,d1600f54f8788b352989cf898bc90406
allproductsmar2000.dat,49a000a7ae2bb8e81a7227ad3b813e0a
10 changes: 5 additions & 5 deletions test/testfiles/missing-filenames.list
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
missing-filenames-body.rtf
generpts.src
TechlibDEC99.doc
TechlibDEC99-JAN00.doc
TechlibNOV99.doc
EmbeddedRTF.rtf,25a63ced5d5f49da486d3976c9742c6a
generpts.src,ca67140dddba62d8f778cec882152cb5
TechlibDEC99.doc,74d3afaa391ded358785d2d7dcd9c11d
TechlibDEC99-JAN00.doc,abfefd31a4c440654292b9e35aeeaddf
TechlibNOV99.doc,e51074ae101d7598fffa0de39888069a
2 changes: 1 addition & 1 deletion test/testfiles/multi-value-attribute.list
Original file line number Diff line number Diff line change
@@ -1 +1 @@
208225__5_seconds__Voice_Mail.mp3
208225__5_seconds__Voice_Mail.mp3,ff6aa0bb42c486315ff79f10ad361649
2 changes: 1 addition & 1 deletion test/testfiles/one-file.list
Original file line number Diff line number Diff line change
@@ -1 +1 @@
AUTHORS
AUTHORS,64f49fc16e0c885f7bc4c939364dd0a2
2 changes: 1 addition & 1 deletion test/testfiles/rtf.list
Original file line number Diff line number Diff line change
@@ -1 +1 @@
rtf-body.rtf
EmbeddedRTF.rtf,2d866937395fce931d93285c34e1992d
2 changes: 1 addition & 1 deletion test/testfiles/triples.list
Original file line number Diff line number Diff line change
@@ -1 +1 @@
triples-body.rtf
EmbeddedRTF.rtf,8bf613b9e983db0601ca4e7a175cf44d
4 changes: 2 additions & 2 deletions test/testfiles/two-files.list
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
AUTHORS
README
AUTHORS,64f49fc16e0c885f7bc4c939364dd0a2
README,7b46a88a7e64bb0532f29416ea5b3116
8 changes: 4 additions & 4 deletions test/testfiles/unicode-mapi-attr-name.list
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
spaconsole2.cfg
image001.png
image002.png
image003.png
spaconsole2.cfg,907a560d9a3344f5426762ca169e3130
image001.png,c123f9a9bd8d73952ede099b17ab8175
image002.png,bf87d15cf1fd0070c19bbd1e380ce027
image003.png,bdf717cfaee54efa8b52bfad415bc7e2
2 changes: 1 addition & 1 deletion test/testfiles/unicode-mapi-attr.list
Original file line number Diff line number Diff line change
@@ -1 +1 @@
example.dat
example.dat,cc08b979e186205db2682308fb1b7c7f