diff --git a/tests/Fetch/Test/AttachmentTest.php b/tests/Fetch/Test/AttachmentTest.php index 09d4d4d..3e652e1 100644 --- a/tests/Fetch/Test/AttachmentTest.php +++ b/tests/Fetch/Test/AttachmentTest.php @@ -18,8 +18,94 @@ namespace Fetch\Test; */ class AttachmentTest extends \PHPUnit_Framework_TestCase { + + public static function getAttachments($MessageId) + { + $server = ServerTest::getServer(); + $message = new \Fetch\Message($MessageId, $server); + $attachments = $message->getAttachments(); + $returnAttachments = array(); + foreach($attachments as $attachment) + $returnAttachments[$attachment->getFileName()] = $attachment; + return $returnAttachments; + } + public function testGetData() { + $attachments = static::getAttachments('6'); + $attachment_RCA = $attachments['RCA_Indian_Head_test_pattern.JPG.zip']; + $md5_RCA = '3e9b6f02551590a7bcfff5d50b5b7b20'; + $this->assertEquals($md5_RCA, md5($attachment_RCA->getData())); + + $attachment_TestCard = $attachments['Test_card.png.zip']; + $md5_TestCard = '94c40bd83fbfa03b29bf1811f9aaccea'; + $this->assertEquals($md5_TestCard, md5($attachment_TestCard->getData())); + } + + public function testGetMimeType() + { + $attachments = static::getAttachments('6'); + + $attachment_RCA = $attachments['RCA_Indian_Head_test_pattern.JPG.zip']; + $mimetype_RCA = 'application/zip'; + $this->assertEquals($mimetype_RCA, $attachment_RCA->getMimeType()); + + $attachment_TestCard = $attachments['Test_card.png.zip']; + $mimetype_TestCard = 'application/zip'; + $this->assertEquals($mimetype_TestCard, $attachment_TestCard->getMimeType()); + } + + public function testGetSize() + { + $attachments = static::getAttachments('6'); + + $attachment_RCA = $attachments['RCA_Indian_Head_test_pattern.JPG.zip']; + $size_RCA = 378338; + $this->assertEquals($size_RCA, $attachment_RCA->getSize()); + + $attachment_TestCard = $attachments['Test_card.png.zip']; + $size_TestCard = 32510; + $this->assertEquals($size_TestCard, $attachment_TestCard->getSize()); + } + + public function testGetStructure() + { + $attachments = static::getAttachments('6'); + + $attachment_RCA = $attachments['RCA_Indian_Head_test_pattern.JPG.zip']; + $structure_RCA = $attachment_RCA->getStructure(); + + $this->assertObjectHasAttribute('type', $structure_RCA); + $this->assertEquals(3, $structure_RCA->type); + + $this->assertObjectHasAttribute('subtype', $structure_RCA); + $this->assertEquals('ZIP', $structure_RCA->subtype); + + $this->assertObjectHasAttribute('bytes', $structure_RCA); + $this->assertEquals(378338, $structure_RCA->bytes); + } + + public function testSaveToDirectory() + { + $attachments = static::getAttachments('6'); + + $attachment_RCA = $attachments['RCA_Indian_Head_test_pattern.JPG.zip']; + + $tmpdir = rtrim(sys_get_temp_dir(), '/') . '/'; + $filepath = $tmpdir . 'RCA_Indian_Head_test_pattern.JPG.zip'; + + $attachment_RCA->saveToDirectory($tmpdir); + + $this->assertFileExists($filepath); + $this->assertEquals(md5(file_get_contents($filepath)), md5($attachment_RCA->getData())); + } + + + static function tearDownAfterClass() + { + $tmpdir = rtrim(sys_get_temp_dir(), '/') . '/'; + $filepath = $tmpdir . 'RCA_Indian_Head_test_pattern.JPG.zip'; + unlink($filepath); } } diff --git a/tests/resources/Attachments/RCA_Indian_Head_test_pattern.JPG b/tests/resources/Attachments/RCA_Indian_Head_test_pattern.JPG new file mode 100644 index 0000000..eff419b Binary files /dev/null and b/tests/resources/Attachments/RCA_Indian_Head_test_pattern.JPG differ diff --git a/tests/resources/Attachments/RCA_Indian_Head_test_pattern.JPG.zip b/tests/resources/Attachments/RCA_Indian_Head_test_pattern.JPG.zip new file mode 100644 index 0000000..93087cf Binary files /dev/null and b/tests/resources/Attachments/RCA_Indian_Head_test_pattern.JPG.zip differ diff --git a/tests/resources/Attachments/Test_card.png b/tests/resources/Attachments/Test_card.png new file mode 100644 index 0000000..372c2a2 Binary files /dev/null and b/tests/resources/Attachments/Test_card.png differ diff --git a/tests/resources/Attachments/Test_card.png.zip b/tests/resources/Attachments/Test_card.png.zip new file mode 100644 index 0000000..3097791 Binary files /dev/null and b/tests/resources/Attachments/Test_card.png.zip differ