|
|
@@ -404,7 +404,11 @@ class ZipFileTest extends ZipTestCase
|
|
|
$zipFile->openFile($this->outputFilename);
|
|
|
$zipFile->rename($oldName, $newName);
|
|
|
$zipFile->addFromString('file1.txt', 'content');
|
|
|
- $zipFile->rename('file1.txt', 'file2.txt');
|
|
|
+ $zipFile->addFromString('file2.txt', 'content');
|
|
|
+ $zipFile->addFromString('file3.txt', 'content');
|
|
|
+ $zipFile->rename('file1.txt', 'file_long_name.txt');
|
|
|
+ $zipFile->rename('file2.txt', 'file4.txt');
|
|
|
+ $zipFile->rename('file3.txt', 'fi.txt');
|
|
|
$zipFile->saveAsFile($this->outputFilename);
|
|
|
$zipFile->close();
|
|
|
|
|
|
@@ -414,7 +418,11 @@ class ZipFileTest extends ZipTestCase
|
|
|
self::assertFalse(isset($zipFile[$oldName]));
|
|
|
self::assertTrue(isset($zipFile[$newName]));
|
|
|
self::assertFalse(isset($zipFile['file1.txt']));
|
|
|
- self::assertTrue(isset($zipFile['file2.txt']));
|
|
|
+ self::assertFalse(isset($zipFile['file2.txt']));
|
|
|
+ self::assertFalse(isset($zipFile['file3.txt']));
|
|
|
+ self::assertTrue(isset($zipFile['file_long_name.txt']));
|
|
|
+ self::assertTrue(isset($zipFile['file4.txt']));
|
|
|
+ self::assertTrue(isset($zipFile['fi.txt']));
|
|
|
$zipFile->close();
|
|
|
}
|
|
|
|
|
|
@@ -1737,119 +1745,6 @@ class ZipFileTest extends ZipTestCase
|
|
|
$zipFile->rewrite();
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Test zip alignment.
|
|
|
- */
|
|
|
- public function testZipAlignSourceZip()
|
|
|
- {
|
|
|
- $zipFile = new ZipFile();
|
|
|
- for ($i = 0; $i < 100; $i++) {
|
|
|
- $zipFile->addFromString(
|
|
|
- 'entry' . $i . '.txt',
|
|
|
- CryptoUtil::randomBytes(mt_rand(100, 4096)),
|
|
|
- ZipFileInterface::METHOD_STORED
|
|
|
- );
|
|
|
- }
|
|
|
- $zipFile->saveAsFile($this->outputFilename);
|
|
|
- $zipFile->close();
|
|
|
-
|
|
|
- self::assertCorrectZipArchive($this->outputFilename);
|
|
|
-
|
|
|
- $result = self::doZipAlignVerify($this->outputFilename);
|
|
|
- if ($result === null) {
|
|
|
- return;
|
|
|
- } // zip align not installed
|
|
|
-
|
|
|
- // check not zip align
|
|
|
- self::assertFalse($result);
|
|
|
-
|
|
|
- $zipFile->openFile($this->outputFilename);
|
|
|
- $zipFile->setZipAlign(4);
|
|
|
- $zipFile->saveAsFile($this->outputFilename);
|
|
|
- $zipFile->close();
|
|
|
-
|
|
|
- self::assertCorrectZipArchive($this->outputFilename);
|
|
|
-
|
|
|
- $result = self::doZipAlignVerify($this->outputFilename, true);
|
|
|
- self::assertNotNull($result);
|
|
|
-
|
|
|
- // check zip align
|
|
|
- self::assertTrue($result);
|
|
|
- }
|
|
|
-
|
|
|
- public function testZipAlignNewFiles()
|
|
|
- {
|
|
|
- $zipFile = new ZipFile();
|
|
|
- for ($i = 0; $i < 100; $i++) {
|
|
|
- $zipFile->addFromString(
|
|
|
- 'entry' . $i . '.txt',
|
|
|
- CryptoUtil::randomBytes(mt_rand(100, 4096)),
|
|
|
- ZipFileInterface::METHOD_STORED
|
|
|
- );
|
|
|
- }
|
|
|
- $zipFile->setZipAlign(4);
|
|
|
- $zipFile->saveAsFile($this->outputFilename);
|
|
|
- $zipFile->close();
|
|
|
-
|
|
|
- self::assertCorrectZipArchive($this->outputFilename);
|
|
|
-
|
|
|
- $result = self::doZipAlignVerify($this->outputFilename);
|
|
|
- if ($result === null) {
|
|
|
- return;
|
|
|
- } // zip align not installed
|
|
|
- // check not zip align
|
|
|
- self::assertTrue($result);
|
|
|
- }
|
|
|
-
|
|
|
- public function testZipAlignFromModifiedZipArchive()
|
|
|
- {
|
|
|
- $zipFile = new ZipFile();
|
|
|
- for ($i = 0; $i < 100; $i++) {
|
|
|
- $zipFile->addFromString(
|
|
|
- 'entry' . $i . '.txt',
|
|
|
- CryptoUtil::randomBytes(mt_rand(100, 4096)),
|
|
|
- ZipFileInterface::METHOD_STORED
|
|
|
- );
|
|
|
- }
|
|
|
- $zipFile->saveAsFile($this->outputFilename);
|
|
|
- $zipFile->close();
|
|
|
-
|
|
|
- self::assertCorrectZipArchive($this->outputFilename);
|
|
|
-
|
|
|
- $result = self::doZipAlignVerify($this->outputFilename);
|
|
|
- if ($result === null) {
|
|
|
- return;
|
|
|
- } // zip align not installed
|
|
|
-
|
|
|
- // check not zip align
|
|
|
- self::assertFalse($result);
|
|
|
-
|
|
|
- $zipFile->openFile($this->outputFilename);
|
|
|
- $zipFile->deleteFromRegex("~entry2[\d]+\.txt$~s");
|
|
|
- for ($i = 0; $i < 100; $i++) {
|
|
|
- $isStored = (bool)mt_rand(0, 1);
|
|
|
-
|
|
|
- $zipFile->addFromString(
|
|
|
- 'entry_new_' . ($isStored ? 'stored' : 'deflated') . '_' . $i . '.txt',
|
|
|
- CryptoUtil::randomBytes(mt_rand(100, 4096)),
|
|
|
- $isStored ?
|
|
|
- ZipFileInterface::METHOD_STORED :
|
|
|
- ZipFileInterface::METHOD_DEFLATED
|
|
|
- );
|
|
|
- }
|
|
|
- $zipFile->setZipAlign(4);
|
|
|
- $zipFile->saveAsFile($this->outputFilename);
|
|
|
- $zipFile->close();
|
|
|
-
|
|
|
- self::assertCorrectZipArchive($this->outputFilename);
|
|
|
-
|
|
|
- $result = self::doZipAlignVerify($this->outputFilename, true);
|
|
|
- self::assertNotNull($result);
|
|
|
-
|
|
|
- // check zip align
|
|
|
- self::assertTrue($result);
|
|
|
- }
|
|
|
-
|
|
|
public function testFilename0()
|
|
|
{
|
|
|
$zipFile = new ZipFile();
|