diff --git a/library/Zend/Filter/Compress/Zip.php b/library/Zend/Filter/Compress/Zip.php index 81403534212..5a6f01a095d 100644 --- a/library/Zend/Filter/Compress/Zip.php +++ b/library/Zend/Filter/Compress/Zip.php @@ -184,13 +184,12 @@ public function compress($content) */ public function decompress($content) { - $archive = $this->getArchive(); + $archive = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, realpath($content)); if (empty($archive) || !file_exists($archive)) { throw new Exception\RuntimeException('ZIP Archive not found'); } - $archive = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, realpath($content)); $zip = new ZipArchive(); $res = $zip->open($archive); diff --git a/tests/ZendTest/Filter/Compress/ZipTest.php b/tests/ZendTest/Filter/Compress/ZipTest.php index fe9c87c9307..8bf0a9b2ae6 100644 --- a/tests/ZendTest/Filter/Compress/ZipTest.php +++ b/tests/ZendTest/Filter/Compress/ZipTest.php @@ -297,4 +297,31 @@ public function testDecompressWillThrowExceptionWhenDecompressingWithNoTarget() $content = file_get_contents($this->tmp . '/_compress'); $this->assertEquals('compress me', $content); } + + public function testDecompressWhenNoArchieveInClass() + { + if (!constant('TESTS_ZEND_FILTER_COMPRESS_ZIP_ENABLED')) { + $this->markTestSkipped('ZIP compression tests are currently disabled'); + } + + $filter = new ZipCompression( + array( + 'archive' => $this->tmp . '/compressed.zip', + 'target' => $this->tmp . '/_compress' + ) + ); + + $content = $filter->compress('compress me'); + $this->assertEquals($this->tmp . DIRECTORY_SEPARATOR . 'compressed.zip', $content); + + $filter = new ZipCompression( + array( + 'target' => $this->tmp . '/_compress' + ) + ); + $content = $filter->decompress($content); + $this->assertEquals($this->tmp . DIRECTORY_SEPARATOR, $content); + $content = file_get_contents($this->tmp . '/_compress'); + $this->assertEquals('compress me', $content); + } }