CustomZipFormatTest.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace PhpZip\Tests;
  3. use PhpZip\Exception\ZipEntryNotFoundException;
  4. use PhpZip\Exception\ZipException;
  5. use PhpZip\Tests\Internal\Epub\EpubFile;
  6. /**
  7. * Checks the ability to create own file-type class, reader, writer and container.
  8. *
  9. * @see http://www.epubtest.org/test-books source epub files
  10. *
  11. * @internal
  12. *
  13. * @small
  14. */
  15. final class CustomZipFormatTest extends ZipTestCase
  16. {
  17. /**
  18. * @throws ZipException
  19. */
  20. public function testEpub()
  21. {
  22. $epubFile = new EpubFile();
  23. $epubFile->openFile(__DIR__ . '/resources/Advanced-v1.0.0.epub');
  24. self::assertSame($epubFile->getRootFile(), 'EPUB/package.opf');
  25. self::assertSame($epubFile->getMimeType(), 'application/epub+zip');
  26. $epubInfo = $epubFile->getEpubInfo();
  27. self::assertSame($epubInfo->toArray(), [
  28. 'title' => 'Advanced Accessibility Tests: Extended Descriptions',
  29. 'creator' => 'DAISY Consortium Transition to EPUB 3 and DIAGRAM Standards WG',
  30. 'language' => 'en-US',
  31. 'publisher' => 'DAISY Consortium and DIAGRAM Center',
  32. 'description' => 'Tests for accessible extended descriptions of images in EPUBs',
  33. 'rights' => 'This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike (CC BY-NC-SA) license.',
  34. 'date' => '2019-01-03',
  35. 'subject' => 'extended-descriptions',
  36. ]);
  37. $epubFile->deleteFromName('mimetype');
  38. self::assertFalse($epubFile->hasEntry('mimetype'));
  39. try {
  40. $epubFile->getMimeType();
  41. self::fail('deleted mimetype');
  42. } catch (ZipEntryNotFoundException $e) {
  43. self::assertSame('Zip Entry "mimetype" was not found in the archive.', $e->getMessage());
  44. }
  45. $epubFile->saveAsFile($this->outputFilename);
  46. self::assertFalse($epubFile->hasEntry('mimetype'));
  47. $epubFile->close();
  48. self::assertCorrectZipArchive($this->outputFilename);
  49. $epubFile->openFile($this->outputFilename);
  50. // file appended in EpubWriter before write
  51. self::assertTrue($epubFile->hasEntry('mimetype'));
  52. $epubFile->close();
  53. }
  54. }