diff --git a/test/TNEFAttachmentTest.php b/test/TNEFAttachmentTest.php index b79230c..fe2397b 100644 --- a/test/TNEFAttachmentTest.php +++ b/test/TNEFAttachmentTest.php @@ -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); @@ -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() { @@ -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; } } diff --git a/test/testfiles/MAPI_ATTACH_DATA_OBJ.list b/test/testfiles/MAPI_ATTACH_DATA_OBJ.list index 6aa060d..ac3702b 100644 --- a/test/testfiles/MAPI_ATTACH_DATA_OBJ.list +++ b/test/testfiles/MAPI_ATTACH_DATA_OBJ.list @@ -1,4 +1,4 @@ -VIA_Nytt_1402.doc -VIA_Nytt_1402.pdf -VIA_Nytt_14021.htm -MAPI_ATTACH_DATA_OBJ-body.rtf \ No newline at end of file +EmbeddedRTF.rtf,45c10a4a43d0e5249146d44bc3aea596 +VIA_Nytt_1402.doc,d41d8cd98f00b204e9800998ecf8427e +VIA_Nytt_1402.pdf,d41d8cd98f00b204e9800998ecf8427e +VIA_Nytt_14021.htm,d41d8cd98f00b204e9800998ecf8427e diff --git a/test/testfiles/MAPI_ATTACH_DATA_OBJ.nested.list b/test/testfiles/MAPI_ATTACH_DATA_OBJ.nested.list new file mode 100644 index 0000000..95a9f28 --- /dev/null +++ b/test/testfiles/MAPI_ATTACH_DATA_OBJ.nested.list @@ -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 \ No newline at end of file diff --git a/test/testfiles/MAPI_OBJECT.list b/test/testfiles/MAPI_OBJECT.list index 2d889d9..6628ed2 100644 --- a/test/testfiles/MAPI_OBJECT.list +++ b/test/testfiles/MAPI_OBJECT.list @@ -1,2 +1,2 @@ -Untitled_Attachment -MAPI_OBJECT-body.rtf \ No newline at end of file +EmbeddedRTF.rtf,02c44ac31695230a1014fb4c5cbb3230 +Untitled_Attachment,d41d8cd98f00b204e9800998ecf8427e diff --git a/test/testfiles/data-before-name.list b/test/testfiles/data-before-name.list index b0751ab..12d8f82 100644 --- a/test/testfiles/data-before-name.list +++ b/test/testfiles/data-before-name.list @@ -1,4 +1,4 @@ -AUTOEXEC.BAT -CONFIG.SYS -boot.ini -data-before-name-body.rtf \ No newline at end of file +EmbeddedRTF.rtf,1ea92c02882f8f0cb655d062ee90006a +AUTOEXEC.BAT,d41d8cd98f00b204e9800998ecf8427e +CONFIG.SYS,d41d8cd98f00b204e9800998ecf8427e +boot.ini,9abbbabd47c8544e7909b4c38ba9c009 diff --git a/test/testfiles/long-filename.list b/test/testfiles/long-filename.list index ad32e2e..0bf3d62 100644 --- a/test/testfiles/long-filename.list +++ b/test/testfiles/long-filename.list @@ -1,2 +1,2 @@ -long-filename-body.rtf -allproductsmar2000.dat \ No newline at end of file +EmbeddedRTF.rtf,d1600f54f8788b352989cf898bc90406 +allproductsmar2000.dat,49a000a7ae2bb8e81a7227ad3b813e0a \ No newline at end of file diff --git a/test/testfiles/missing-filenames.list b/test/testfiles/missing-filenames.list index b2bcd97..43c9861 100644 --- a/test/testfiles/missing-filenames.list +++ b/test/testfiles/missing-filenames.list @@ -1,5 +1,5 @@ -missing-filenames-body.rtf -generpts.src -TechlibDEC99.doc -TechlibDEC99-JAN00.doc -TechlibNOV99.doc \ No newline at end of file +EmbeddedRTF.rtf,25a63ced5d5f49da486d3976c9742c6a +generpts.src,ca67140dddba62d8f778cec882152cb5 +TechlibDEC99.doc,74d3afaa391ded358785d2d7dcd9c11d +TechlibDEC99-JAN00.doc,abfefd31a4c440654292b9e35aeeaddf +TechlibNOV99.doc,e51074ae101d7598fffa0de39888069a \ No newline at end of file diff --git a/test/testfiles/multi-value-attribute.list b/test/testfiles/multi-value-attribute.list index 2667fe6..31a40e4 100644 --- a/test/testfiles/multi-value-attribute.list +++ b/test/testfiles/multi-value-attribute.list @@ -1 +1 @@ -208225__5_seconds__Voice_Mail.mp3 \ No newline at end of file +208225__5_seconds__Voice_Mail.mp3,ff6aa0bb42c486315ff79f10ad361649 \ No newline at end of file diff --git a/test/testfiles/one-file.list b/test/testfiles/one-file.list index 62deb04..6af9f89 100644 --- a/test/testfiles/one-file.list +++ b/test/testfiles/one-file.list @@ -1 +1 @@ -AUTHORS +AUTHORS,64f49fc16e0c885f7bc4c939364dd0a2 diff --git a/test/testfiles/rtf.list b/test/testfiles/rtf.list index dc8e9fb..d3b34d6 100644 --- a/test/testfiles/rtf.list +++ b/test/testfiles/rtf.list @@ -1 +1 @@ -rtf-body.rtf \ No newline at end of file +EmbeddedRTF.rtf,2d866937395fce931d93285c34e1992d \ No newline at end of file diff --git a/test/testfiles/triples.list b/test/testfiles/triples.list index eb7cbd3..5b60b4e 100644 --- a/test/testfiles/triples.list +++ b/test/testfiles/triples.list @@ -1 +1 @@ -triples-body.rtf \ No newline at end of file +EmbeddedRTF.rtf,8bf613b9e983db0601ca4e7a175cf44d \ No newline at end of file diff --git a/test/testfiles/two-files.list b/test/testfiles/two-files.list index 6f12db5..572d3d2 100644 --- a/test/testfiles/two-files.list +++ b/test/testfiles/two-files.list @@ -1,2 +1,2 @@ -AUTHORS -README +AUTHORS,64f49fc16e0c885f7bc4c939364dd0a2 +README,7b46a88a7e64bb0532f29416ea5b3116 diff --git a/test/testfiles/unicode-mapi-attr-name.list b/test/testfiles/unicode-mapi-attr-name.list index d133fb0..2702dd0 100644 --- a/test/testfiles/unicode-mapi-attr-name.list +++ b/test/testfiles/unicode-mapi-attr-name.list @@ -1,4 +1,4 @@ -spaconsole2.cfg -image001.png -image002.png -image003.png \ No newline at end of file +spaconsole2.cfg,907a560d9a3344f5426762ca169e3130 +image001.png,c123f9a9bd8d73952ede099b17ab8175 +image002.png,bf87d15cf1fd0070c19bbd1e380ce027 +image003.png,bdf717cfaee54efa8b52bfad415bc7e2 \ No newline at end of file diff --git a/test/testfiles/unicode-mapi-attr.list b/test/testfiles/unicode-mapi-attr.list index e85b45d..ae6272d 100644 --- a/test/testfiles/unicode-mapi-attr.list +++ b/test/testfiles/unicode-mapi-attr.list @@ -1 +1 @@ -example.dat \ No newline at end of file +example.dat,cc08b979e186205db2682308fb1b7c7f \ No newline at end of file