Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ewilan-riviere committed Dec 6, 2023
1 parent 58e3207 commit 83d3c75
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 16 deletions.
2 changes: 1 addition & 1 deletion tests/AudiobookTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
20 changes: 20 additions & 0 deletions tests/BookIdentifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
],
]);
6 changes: 3 additions & 3 deletions tests/CbaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion tests/EbookTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
1 change: 0 additions & 1 deletion tests/EntityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion tests/EpubChaptersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
18 changes: 9 additions & 9 deletions tests/EpubTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -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);
Expand All @@ -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();
Expand All @@ -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();
});
Expand All @@ -165,15 +165,15 @@
$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);
});

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,
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 83d3c75

Please sign in to comment.