From 83d3c7551c87f4ef157ff54d33793df985a6b486 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ewilan=20Rivi=C3=A8re?= Date: Wed, 6 Dec 2023 10:57:17 +0100 Subject: [PATCH] add more tests --- tests/AudiobookTest.php | 2 +- tests/BookIdentifierTest.php | 20 ++++++++++++++++++++ tests/CbaTest.php | 6 +++--- tests/EbookTest.php | 2 +- tests/EntityTest.php | 1 - tests/EpubChaptersTest.php | 2 +- tests/EpubTest.php | 18 +++++++++--------- 7 files changed, 35 insertions(+), 16 deletions(-) diff --git a/tests/AudiobookTest.php b/tests/AudiobookTest.php index 816ce75..3a58b31 100644 --- a/tests/AudiobookTest.php +++ b/tests/AudiobookTest.php @@ -9,7 +9,7 @@ expect($ebook->getpath())->toBe($path); - $metadata = $ebook->getMetadata(); + $metadata = $ebook->getParser(); expect($metadata->getAudiobook()->getAudio())->toBeArray(); expect($metadata->getAudiobook()->toArray())->toBeArray(); expect($metadata->getAudiobook()->toJson())->toBeString(); diff --git a/tests/BookIdentifierTest.php b/tests/BookIdentifierTest.php index aa59d68..b686a87 100644 --- a/tests/BookIdentifierTest.php +++ b/tests/BookIdentifierTest.php @@ -73,3 +73,23 @@ 'value' => 'customkey', ], ]); + +it('can use without autoDetect', function (?string $scheme, ?string $value) { + $item = new BookIdentifier($value, $scheme, autoDetect: false); + + expect($item->getValue())->toBe($value); + expect($item->getScheme())->toBe($scheme); +})->with([ + [ + 'scheme' => 'isbn13', + 'value' => '9788075836663', + ], + [ + 'scheme' => null, + 'value' => 'ASvHBAAAQBAJ', + ], + [ + 'scheme' => 'custom', + 'value' => null, + ], +]); diff --git a/tests/CbaTest.php b/tests/CbaTest.php index e0e7b07..e694149 100644 --- a/tests/CbaTest.php +++ b/tests/CbaTest.php @@ -22,7 +22,7 @@ it('can parse no metadata', function () { $ebook = Ebook::read(CBZ_NO_METADATA); - expect($ebook->hasMetadata())->toBeFalse(); + expect($ebook->hasParser())->toBeFalse(); }); it('can parse ComicInfo basic', function () { @@ -70,7 +70,7 @@ expect($ebook)->toBeInstanceOf(Ebook::class); expect($ebook->getFormat())->toBe(EbookFormatEnum::CBA); expect($ebook->getpath())->toBe($path); - expect($ebook->hasMetadata())->toBeTrue(); + expect($ebook->hasParser())->toBeTrue(); expect($ebook->getTitle())->toBe('You Had One Job'); expect($ebook->getSeries())->toBe('Fantastic Four'); @@ -116,7 +116,7 @@ it('can parse CbamTemplate', function (string $path) { $ebook = Ebook::read($path); - $cbam = $ebook->getMetadata()->getCba()?->getCbam(); + $cbam = $ebook->getParser()->getCba()?->getCbam(); if (! $cbam) { throw new Exception('CBAM is null'); diff --git a/tests/EbookTest.php b/tests/EbookTest.php index 2b6e5c4..7c45b6f 100644 --- a/tests/EbookTest.php +++ b/tests/EbookTest.php @@ -41,7 +41,7 @@ $parser = $ebook->getParser(); expect($parser)->toBeInstanceOf(EbookParser::class); - expect($ebook->getMetadata())->toBeInstanceOf(EbookParser::class); + expect($ebook->getParser())->toBeInstanceOf(EbookParser::class); expect($ebook->getMetaTitle()->getUniqueFilename())->toBeString(); diff --git a/tests/EntityTest.php b/tests/EntityTest.php index 05f58bc..3eff140 100644 --- a/tests/EntityTest.php +++ b/tests/EntityTest.php @@ -106,7 +106,6 @@ $item = new BookMeta($name, $contents); expect($item->getName())->toBe($name); - expect($item->getContent())->toBe($contents); expect($item->getContents())->toBe($contents); expect($item->toArray())->toBe([ 'name' => $name, diff --git a/tests/EpubChaptersTest.php b/tests/EpubChaptersTest.php index db340f2..a5b9529 100644 --- a/tests/EpubChaptersTest.php +++ b/tests/EpubChaptersTest.php @@ -5,7 +5,7 @@ it('can parse epub chapters', function () { $ebook = Ebook::read(EPUB); - $chapters = $ebook->getMetadata()->getEpub()->getChapters(); + $chapters = $ebook->getParser()->getEpub()->getChapters(); expect($chapters)->toBeArray(); expect($chapters)->toHaveCount(41); diff --git a/tests/EpubTest.php b/tests/EpubTest.php index eda4d27..10aafad 100644 --- a/tests/EpubTest.php +++ b/tests/EpubTest.php @@ -16,7 +16,7 @@ expect($ebook->getpath())->toBe(EPUB); expect($ebook->getFilename())->toBe($filename); expect($ebook->getBasename())->toBe($basename); - expect($ebook->hasMetadata())->toBeTrue(); + expect($ebook->hasParser())->toBeTrue(); expect($ebook)->toBeInstanceOf(Ebook::class); expect($ebook->getTitle())->toBe('The Clan of the Cave Bear'); @@ -46,7 +46,7 @@ expect($ebook->getExtra('contributor'))->toBeString(); expect($ebook->getExtra('contributora'))->toBeNull(); - $metadata = $ebook->getMetadata(); + $metadata = $ebook->getParser(); expect($metadata->toArray())->toBeArray(); expect($metadata->toJson())->toBeString(); expect(Ebook::isValid(EPUB))->toBeTrue(); @@ -87,7 +87,7 @@ }); it('can read epub metadata', function () { - $epub = Ebook::read(EPUB)->getMetadata()?->getEpub(); + $epub = Ebook::read(EPUB)->getParser()?->getEpub(); $container = $epub->getContainer(); $opf = $epub->getOpf(); @@ -112,7 +112,7 @@ }); it('can read content', function () { - $html = Ebook::read(EPUB)->getMetadata()?->getEpub()?->getHtml(); + $html = Ebook::read(EPUB)->getParser()?->getEpub()?->getHtml(); foreach ($html as $value) { expect($value)->toBeInstanceOf(EpubHtml::class); @@ -128,7 +128,7 @@ it('can read ncx', function () { $ebook = Ebook::read(EPUB); - $toc = $ebook->getMetadata()?->getEpub()?->getNcx(); + $toc = $ebook->getParser()?->getEpub()?->getNcx(); if ($toc) { expect($toc->getHead())->toBeArray(); @@ -143,7 +143,7 @@ it('can build EPUB render', function () { $ebook = Ebook::read(EPUB); - $chapters = $ebook->getMetadata()->getEpub()->getChapters(); + $chapters = $ebook->getParser()->getEpub()->getChapters(); expect($chapters)->toBeArray(); }); @@ -165,7 +165,7 @@ $ebook = Ebook::read(EPUB_BAD_FILE); expect(Ebook::isValid(EPUB_BAD_FILE))->toBeFalse(); - expect($ebook->hasMetadata())->toBeFalse(); + expect($ebook->hasParser())->toBeFalse(); expect($ebook->isBadFile())->toBeTrue(); expect(fn () => $ebook->getArchive()->filter('opf'))->not()->toThrow(Exception::class); }); @@ -173,7 +173,7 @@ it('can handle bad epub', function (string $epub) { $ebook = Ebook::read($epub); - expect($ebook->hasMetadata())->toBeFalse(); + expect($ebook->hasParser())->toBeFalse(); })->with([ EPUB_NO_CONTAINER, EPUB_NO_OPF, @@ -221,7 +221,7 @@ expect($path)->toBeReadableFile(); expect(fileIsValidImg($path))->toBeFalse(); - $module = $ebook->getMetadata()->getEpub(); + $module = $ebook->getParser()->getEpub(); $html = $module->getHtml(); expect($html)->toBeArray()