diff options
author | Matthieu Napoli <matthieu@mnapoli.fr> | 2014-10-03 00:57:43 +0400 |
---|---|---|
committer | Matthieu Napoli <matthieu@mnapoli.fr> | 2014-10-03 00:57:43 +0400 |
commit | f29c9380249d95fe004d6f2652dfdb318aea0784 (patch) | |
tree | f2af227dac62daa885f173077984917a79cc36ef /tests/PHPUnit/Core | |
parent | 699f9cd8bd84ee53c8b4e65e948052dbd8858d10 (diff) |
Extracted the decompressing classes into a standalone Decompress component
Diffstat (limited to 'tests/PHPUnit/Core')
-rwxr-xr-x | tests/PHPUnit/Core/Unzip/empty.zip | 0 | ||||
-rw-r--r-- | tests/PHPUnit/Core/Unzip/relative.zip | bin | 128 -> 0 bytes | |||
-rwxr-xr-x | tests/PHPUnit/Core/Unzip/test.gz | bin | 41 -> 0 bytes | |||
-rwxr-xr-x | tests/PHPUnit/Core/Unzip/test.tar.gz | bin | 202 -> 0 bytes | |||
-rw-r--r-- | tests/PHPUnit/Core/Unzip/zaabs.zip | bin | 132 -> 0 bytes | |||
-rw-r--r-- | tests/PHPUnit/Core/Unzip/zaatt.zip | bin | 128 -> 0 bytes | |||
-rw-r--r-- | tests/PHPUnit/Core/UnzipTest.php | 217 |
7 files changed, 0 insertions, 217 deletions
diff --git a/tests/PHPUnit/Core/Unzip/empty.zip b/tests/PHPUnit/Core/Unzip/empty.zip deleted file mode 100755 index e69de29bb2..0000000000 --- a/tests/PHPUnit/Core/Unzip/empty.zip +++ /dev/null diff --git a/tests/PHPUnit/Core/Unzip/relative.zip b/tests/PHPUnit/Core/Unzip/relative.zip Binary files differdeleted file mode 100644 index 2388859d52..0000000000 --- a/tests/PHPUnit/Core/Unzip/relative.zip +++ /dev/null diff --git a/tests/PHPUnit/Core/Unzip/test.gz b/tests/PHPUnit/Core/Unzip/test.gz Binary files differdeleted file mode 100755 index 113cbed07f..0000000000 --- a/tests/PHPUnit/Core/Unzip/test.gz +++ /dev/null diff --git a/tests/PHPUnit/Core/Unzip/test.tar.gz b/tests/PHPUnit/Core/Unzip/test.tar.gz Binary files differdeleted file mode 100755 index b9cc91965d..0000000000 --- a/tests/PHPUnit/Core/Unzip/test.tar.gz +++ /dev/null diff --git a/tests/PHPUnit/Core/Unzip/zaabs.zip b/tests/PHPUnit/Core/Unzip/zaabs.zip Binary files differdeleted file mode 100644 index c5517f940d..0000000000 --- a/tests/PHPUnit/Core/Unzip/zaabs.zip +++ /dev/null diff --git a/tests/PHPUnit/Core/Unzip/zaatt.zip b/tests/PHPUnit/Core/Unzip/zaatt.zip Binary files differdeleted file mode 100644 index 91e0c4864a..0000000000 --- a/tests/PHPUnit/Core/Unzip/zaatt.zip +++ /dev/null diff --git a/tests/PHPUnit/Core/UnzipTest.php b/tests/PHPUnit/Core/UnzipTest.php deleted file mode 100644 index 12f754c8b7..0000000000 --- a/tests/PHPUnit/Core/UnzipTest.php +++ /dev/null @@ -1,217 +0,0 @@ -<?php -/** - * Piwik - free/libre analytics platform - * - * @link http://piwik.org - * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later - */ -use Piwik\Unzip\Gzip; -use Piwik\Unzip; -use Piwik\Unzip\PclZip; -use Piwik\Unzip\Tar; -use Piwik\Unzip\ZipArchive; - -class UnzipTest extends PHPUnit_Framework_TestCase -{ - /** - * @group Core - */ - public function testRelativePath() - { - clearstatcache(); - $extractDir = PIWIK_USER_PATH . '/tmp/latest/'; - $test = 'relative'; - $filename = dirname(__FILE__) . '/Unzip/' . $test . '.zip'; - - if (class_exists('ZipArchive', false)) { - $unzip = Unzip::factory('ZipArchive', $filename); - $res = $unzip->extract($extractDir); - $this->assertEquals(1, count($res)); - $this->assertFileExists($extractDir . $test . '.txt'); - $this->assertFileNotExists(dirname(__FILE__) . '/' . $test . '.txt'); - $this->assertFileNotExists(dirname(__FILE__) . '/../../tests/' . $test . '.txt'); - unlink($extractDir . $test . '.txt'); - - $unzip = new ZipArchive($filename); - $res = $unzip->extract($extractDir); - $this->assertEquals(1, count($res)); - $this->assertFileExists($extractDir . $test . '.txt'); - $this->assertFileNotExists(dirname(__FILE__) . '/' . $test . '.txt'); - $this->assertFileNotExists(dirname(__FILE__) . '/../../tests/' . $test . '.txt'); - unlink($extractDir . $test . '.txt'); - } - - $unzip = Unzip::factory('PclZip', $filename); - $res = $unzip->extract($extractDir); - $this->assertEquals(1, count($res)); - $this->assertFileExists($extractDir . $test . '.txt'); - $this->assertFileNotExists(dirname(__FILE__) . '/' . $test . '.txt'); - $this->assertFileNotExists(dirname(__FILE__) . '/../../tests/' . $test . '.txt'); - unlink($extractDir . $test . '.txt'); - - $unzip = new PclZip($filename); - $res = $unzip->extract($extractDir); - $this->assertEquals(1, count($res)); - $this->assertFileExists($extractDir . $test . '.txt'); - $this->assertFileNotExists(dirname(__FILE__) . '/' . $test . '.txt'); - $this->assertFileNotExists(dirname(__FILE__) . '/../../tests/' . $test . '.txt'); - unlink($extractDir . $test . '.txt'); - } - - /** - * @group Core - */ - public function testRelativePathAttack() - { - clearstatcache(); - $extractDir = PIWIK_USER_PATH . '/tmp/latest/'; - $test = 'zaatt'; - $filename = dirname(__FILE__) . '/Unzip/' . $test . '.zip'; - - if (class_exists('ZipArchive', false)) { - $unzip = new ZipArchive($filename); - $res = $unzip->extract($extractDir); - $this->assertEquals(0, $res); - $this->assertFileNotExists($extractDir . $test . '.txt'); - $this->assertFileNotExists($extractDir . '../' . $test . '.txt'); - $this->assertFileNotExists(dirname(__FILE__) . '/' . $test . '.txt'); - $this->assertFileNotExists(dirname(__FILE__) . '/../' . $test . '.txt'); - $this->assertFileNotExists(dirname(__FILE__) . '/../../' . $test . '.txt'); - } - - $unzip = new PclZip($filename); - $res = $unzip->extract($extractDir); - $this->assertEquals(0, $res); - $this->assertFileNotExists($extractDir . $test . '.txt'); - $this->assertFileNotExists($extractDir . '../' . $test . '.txt'); - $this->assertFileNotExists(dirname(__FILE__) . '/' . $test . '.txt'); - $this->assertFileNotExists(dirname(__FILE__) . '/../' . $test . '.txt'); - $this->assertFileNotExists(dirname(__FILE__) . '/../../' . $test . '.txt'); - } - - /** - * @group Core - */ - public function testAbsolutePathAttack() - { - clearstatcache(); - $extractDir = PIWIK_USER_PATH . '/tmp/latest/'; - $test = 'zaabs'; - $filename = dirname(__FILE__) . '/Unzip/' . $test . '.zip'; - - if (class_exists('ZipArchive', false)) { - $unzip = new ZipArchive($filename); - $res = $unzip->extract($extractDir); - $this->assertEquals(0, $res); - $this->assertFileNotExists($extractDir . $test . '.txt'); - $this->assertFileNotExists(dirname(__FILE__) . '/' . $test . '.txt'); - } - - $unzip = new PclZip($filename); - $res = $unzip->extract($extractDir); - $this->assertEquals(0, $res); - $this->assertFileNotExists($extractDir . $test . '.txt'); - $this->assertFileNotExists(dirname(__FILE__) . '/' . $test . '.txt'); - } - - /** - * @group Core - */ - public function testUnzipErrorInfo() - { - clearstatcache(); - $filename = dirname(__FILE__) . '/Unzip/zaabs.zip'; - - $unzip = new ZipArchive($filename); - $this->assertContains('No error', $unzip->errorInfo()); - } - - /** - * @group Core - */ - public function testUnzipEmptyFile() - { - clearstatcache(); - $filename = dirname(__FILE__) . '/Unzip/empty.zip'; - $extractDir = PIWIK_USER_PATH . '/tmp/latest/'; - - $unzip = new ZipArchive($filename); - $res = $unzip->extract($extractDir); - $this->assertEquals(0, $res); - } - - /** - * @group Core - */ - public function testUnzipNotExistingFile() - { - clearstatcache(); - $filename = dirname(__FILE__) . '/Unzip/NotExisting.zip'; - - try { - new ZipArchive($filename); - } catch (Exception $e) { - return; - } - $this->fail('Exception not raised'); - } - - /** - * @group Core - */ - public function testUnzipInvalidFile2() - { - clearstatcache(); - $extractDir = PIWIK_USER_PATH . '/tmp/latest/'; - $filename = dirname(__FILE__) . '/Unzip/NotExisting.zip'; - - $unzip = new PclZip($filename); - $res = $unzip->extract($extractDir); - $this->assertEquals(0, $res); - - $this->assertContains('PCLZIP_ERR_MISSING_FILE', $unzip->errorInfo()); - } - - /** - * @group Core - */ - public function testGzipFile() - { - $extractDir = PIWIK_USER_PATH . '/tmp/latest/'; - $extractFile = $extractDir . 'testgz.txt'; - $filename = dirname(__FILE__) . '/Unzip/test.gz'; - - $unzip = new Gzip($filename); - $res = $unzip->extract($extractFile); - $this->assertTrue($res); - - $this->assertFileContentsEquals('TESTSTRING', $extractFile); - } - - /** - * @group Core - */ - public function testTarGzFile() - { - $extractDir = PIWIK_USER_PATH . '/tmp/latest/'; - $filename = dirname(__FILE__) . '/Unzip/test.tar.gz'; - - $unzip = new Tar($filename, 'gz'); - $res = $unzip->extract($extractDir); - $this->assertTrue($res); - - $this->assertFileContentsEquals('TESTDATA', $extractDir . 'tarout1.txt'); - $this->assertFileContentsEquals('MORETESTDATA', $extractDir . 'tardir/tarout2.txt'); - } - - private function assertFileContentsEquals($expectedContent, $path) - { - $this->assertTrue(file_exists($path)); - - $fd = fopen($path, 'rb'); - $actualContent = fread($fd, filesize($path)); - fclose($fd); - - $this->assertEquals($expectedContent, $actualContent); - } -} |