/** * simple test that checks that the given filenames and contents can be grepped from the * uncompressed zip file * * No check for format correctness */ public function test_createfile() { $zip = new Zip(); $dir = dirname(__FILE__) . '/zip'; $tdir = ltrim($dir, '/'); $tmp = tempnam(sys_get_temp_dir(), 'dwziptest'); $zip->create($tmp); $zip->setCompression(0); $zip->AddFile("{$dir}/testdata1.txt", "{$dir}/testdata1.txt", 0); $zip->AddFile("{$dir}/foobar/testdata2.txt", 'noway/testdata2.txt', 0); $zip->addData('another/testdata3.txt', 'testcontent3', 0, 0); $zip->close(); $this->assertTrue(filesize($tmp) > 30); //arbitrary non-zero number $data = file_get_contents($tmp); $this->assertTrue(strpos($data, 'testcontent1') !== false, 'Content in ZIP'); $this->assertTrue(strpos($data, 'testcontent2') !== false, 'Content in ZIP'); $this->assertTrue(strpos($data, 'testcontent3') !== false, 'Content in ZIP'); // fullpath might be too long to be stored as full path FS#2802 $this->assertTrue(strpos($data, "{$tdir}") !== false, "Path in ZIP '{$tdir}'"); $this->assertTrue(strpos($data, "testdata1.txt") !== false, 'File in ZIP'); $this->assertTrue(strpos($data, 'noway/testdata2.txt') !== false, 'Path in ZIP'); $this->assertTrue(strpos($data, 'another/testdata3.txt') !== false, 'Path in ZIP'); // fullpath might be too long to be stored as full path FS#2802 $this->assertTrue(strpos($data, "{$tdir}/foobar") === false, 'Path not in ZIP'); $this->assertTrue(strpos($data, "foobar.txt") === false, 'File not in ZIP'); $this->assertTrue(strpos($data, "foobar") === false, 'Path not in ZIP'); @unlink($tmp); }
/** * Create an archive and unpack it again */ public function test_dogfood() { $input = glob(dirname(__FILE__) . '/../src/*'); $archive = sys_get_temp_dir() . '/dwziptest' . md5(time()) . '.zip'; $extract = sys_get_temp_dir() . '/dwziptest' . md5(time() + 1); $zip = new Zip(); $zip->create($archive); foreach ($input as $path) { $file = basename($path); $zip->addFile($path, $file); } $zip->close(); $this->assertFileExists($archive); $zip = new Zip(); $zip->open($archive); $zip->extract($extract, '', '/FileInfo\\.php/', '/.*\\.php/'); $this->assertFileExists("{$extract}/Tar.php"); $this->assertFileExists("{$extract}/Zip.php"); $this->assertFileNotExists("{$extract}/FileInfo.php"); self::rdelete($extract); unlink($archive); }