123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- <?php
- namespace PhpZip\Tests;
- use PhpZip\Constants\ZipCompressionMethod;
- use PhpZip\Constants\ZipEncryptionMethod;
- use PhpZip\Constants\ZipPlatform;
- use PhpZip\Exception\ZipEntryNotFoundException;
- use PhpZip\Exception\ZipException;
- use PhpZip\Model\ZipInfo;
- use PhpZip\ZipFile;
- /**
- * Testing the {@see ZipInfo} class.
- *
- * {@see ZipInfo} is {@deprecated}. Use the {@see ZipEntry} class.
- *
- * @internal
- *
- * @small
- */
- final class ZipInfoTest extends ZipTestCase
- {
- public function testZipAllInfo()
- {
- $zipFile = new ZipFile();
- $zipFile['entry'] = 'contents';
- $zipFile['entry 2'] = 'contents';
- $zipAllInfo = $zipFile->getAllInfo();
- $zipFile->close();
- self::assertCount(2, $zipAllInfo);
- self::assertContainsOnlyInstancesOf(ZipInfo::class, $zipAllInfo);
- }
- /**
- * @throws ZipEntryNotFoundException
- * @throws ZipException
- */
- public function testZipEntryInfo()
- {
- $zipFile = new ZipFile();
- $zipFile['entry'] = 'contents';
- $zipFile['entry 2'] = 'contents';
- $zipInfo = $zipFile->getEntryInfo('entry');
- $zipFile->close();
- self::assertInstanceOf(ZipInfo::class, $zipInfo);
- }
- /**
- * @throws ZipEntryNotFoundException
- * @throws ZipException
- */
- public function testZipInfoEntryNotFound()
- {
- $this->expectException(
- ZipEntryNotFoundException::class
- );
- $this->expectExceptionMessage(
- 'Zip Entry "unknown.name" was not found in the archive.'
- );
- $zipFile = new ZipFile();
- $zipFile->getEntryInfo('unknown.name');
- }
- /**
- * @throws ZipEntryNotFoundException
- * @throws ZipException
- */
- public function testZipInfo()
- {
- $zipFile = new ZipFile();
- $zipFile->openFile(__DIR__ . '/resources/Advanced-v1.0.0.epub');
- $entryName = 'META-INF/container.xml';
- $zipEntry = $zipFile->getEntry($entryName);
- $zipInfo = $zipFile->getEntryInfo($entryName);
- $zipFile->close();
- self::assertSame($zipInfo->getName(), $zipEntry->getName());
- self::assertSame($zipInfo->isFolder(), $zipEntry->isDirectory());
- self::assertSame($zipInfo->getSize(), $zipEntry->getUncompressedSize());
- self::assertSame($zipInfo->getCompressedSize(), $zipEntry->getCompressedSize());
- self::assertSame($zipInfo->getMtime(), $zipEntry->getMTime()->getTimestamp());
- self::assertSame(
- $zipInfo->getCtime(),
- $zipEntry->getCTime() !== null ? $zipEntry->getCTime()->getTimestamp() : null
- );
- self::assertSame(
- $zipInfo->getAtime(),
- $zipEntry->getATime() !== null ? $zipEntry->getATime()->getTimestamp() : null
- );
- self::assertNotEmpty($zipInfo->getAttributes());
- self::assertSame($zipInfo->isEncrypted(), $zipEntry->isEncrypted());
- self::assertSame($zipInfo->getComment(), $zipEntry->getComment());
- self::assertSame($zipInfo->getCrc(), $zipEntry->getCrc());
- self::assertSame(
- $zipInfo->getMethod(),
- ZipCompressionMethod::getCompressionMethodName($zipEntry->getCompressionMethod())
- );
- self::assertSame(
- $zipInfo->getMethodName(),
- ZipCompressionMethod::getCompressionMethodName($zipEntry->getCompressionMethod())
- );
- self::assertSame(
- $zipInfo->getEncryptionMethodName(),
- ZipEncryptionMethod::getEncryptionMethodName($zipEntry->getEncryptionMethod())
- );
- self::assertSame($zipInfo->getPlatform(), ZipPlatform::getPlatformName($zipEntry->getExtractedOS()));
- self::assertSame(ZipInfo::getPlatformName($zipEntry), ZipPlatform::getPlatformName($zipEntry->getExtractedOS()));
- self::assertSame($zipInfo->getVersion(), $zipEntry->getExtractVersion());
- self::assertNull($zipInfo->getEncryptionMethod());
- self::assertSame($zipInfo->getCompressionLevel(), $zipEntry->getCompressionLevel());
- self::assertSame($zipInfo->getCompressionMethod(), $zipEntry->getCompressionMethod());
- self::assertNotEmpty($zipInfo->toArray());
- }
- }
|