generated from spatie/package-skeleton-php
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- `OpdsEngine` property `xml` is now `content` - `getXml()` is now `getContent()` - add setter `setContent()` and `setResponse()`
- Loading branch information
1 parent
9551674
commit e0d7455
Showing
8 changed files
with
190 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
use Kiwilan\Opds\OpdsConfig; | ||
|
||
it('can use setter', function () { | ||
$config = new OpdsConfig(); | ||
|
||
$config->setName('Gallica'); | ||
$config->setAuthor('Hadrien Gardeur'); | ||
$config->setAuthorUrl('https://example.com'); | ||
$config->setIconUrl('https://example.com/favicon.ico'); | ||
$config->setStartUrl('https://example.com/opds'); | ||
$config->setSearchUrl('https://example.com/opds/search'); | ||
$config->setSearchQuery('query'); | ||
$config->setVersionQuery('v'); | ||
$config->setUpdated(new DateTime()); | ||
$config->usePagination(); | ||
$config->setMaxItemsPerPage(10); | ||
$config->forceJson(); | ||
|
||
expect($config->getName())->toBe('Gallica'); | ||
expect($config->getAuthor())->toBe('Hadrien Gardeur'); | ||
expect($config->getAuthorUrl())->toBe('https://example.com'); | ||
expect($config->getIconUrl())->toBe('https://example.com/favicon.ico'); | ||
expect($config->getStartUrl())->toBe('https://example.com/opds'); | ||
expect($config->getSearchUrl())->toBe('https://example.com/opds/search'); | ||
expect($config->getSearchQuery())->toBe('query'); | ||
expect($config->getVersionQuery())->toBe('v'); | ||
expect($config->getUpdated())->toBeInstanceOf(DateTime::class); | ||
expect($config->isUsePagination())->toBeTrue(); | ||
expect($config->getMaxItemsPerPage())->toBe(10); | ||
expect($config->isForceJson())->toBeTrue(); | ||
}); | ||
|
||
it('can use slug', function () { | ||
$empty = null; | ||
$slug = OpdsConfig::slug($empty); | ||
|
||
expect($slug)->toBeNull(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
use Kiwilan\Opds\Engine\OpdsXmlEngine; | ||
use Kiwilan\Opds\Opds; | ||
use Kiwilan\Opds\OpdsResponse; | ||
|
||
it('can fail on bad content', function () { | ||
$html = '<!DOCTYPE html>'; | ||
|
||
$opds = Opds::make(); | ||
$engine = OpdsXmlEngine::make($opds); | ||
$engine->setContent([$html]); | ||
$engine->setResponse($html); | ||
|
||
expect($engine->getContent())->toBe([$html]); | ||
expect($engine->getResponse())->toBe($html); | ||
expect(fn () => OpdsResponse::make($engine, 500))->toThrow(Exception::class); | ||
expect(fn () => OpdsResponse::make($engine, 500))->toThrow('OPDS Response: invalid content'); | ||
}); | ||
|
||
it('can use response', function () { | ||
$opds = Opds::make() | ||
->get(); | ||
$response = $opds->getResponse(); | ||
|
||
expect($response->getStatus())->toBe(200); | ||
expect($response->isJson())->toBeFalse(); | ||
expect($response->isXml())->toBeTrue(); | ||
expect($response->getContent())->toBeString(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
use Kiwilan\Opds\Engine\OpdsXmlEngine; | ||
use Kiwilan\Opds\Opds; | ||
use Kiwilan\Opds\OpdsOutputEnum; | ||
use Kiwilan\Opds\OpdsResponse; | ||
use Kiwilan\Opds\OpdsVersionEnum; | ||
use Kiwilan\XmlReader\XmlReader; | ||
|
||
it('is string', function () { | ||
$opds = Opds::make() | ||
->get(); | ||
|
||
$response = $opds->getResponse(); | ||
expect($response->getContent())->toBeString(); | ||
}); | ||
|
||
it('is valid xml', function () { | ||
$opds = Opds::make() | ||
->get(); | ||
|
||
$response = $opds->getResponse(); | ||
expect(isValidXml($response->getContent()))->toBeTrue(); | ||
}); | ||
|
||
it('can be parsed', function () { | ||
$opds = Opds::make() | ||
->get(); | ||
|
||
$response = $opds->getResponse(); | ||
$xml = XmlReader::make($response->getContent())->toArray(); | ||
expect($xml)->toBeArray(); | ||
}); | ||
|
||
it('can use opds properties', function () { | ||
$opds = Opds::make() | ||
->title('feed'); | ||
|
||
expect($opds->getTitle())->toBe('feed'); | ||
expect($opds->getUrl())->toBe('http://localhost/'); | ||
expect($opds->getVersion())->toBe(OpdsVersionEnum::v1Dot2); | ||
expect($opds->getFeeds())->toBeArray(); | ||
expect($opds->getEngine())->toBeInstanceOf(OpdsXmlEngine::class); | ||
expect($opds->getOutput())->toBe(OpdsOutputEnum::xml); | ||
expect($opds->getResponse())->toBeInstanceOf(OpdsResponse::class); | ||
expect($opds->getUrlParts())->toBeArray(); | ||
|
||
}); | ||
|
||
it('can use output', function () { | ||
$opds = Opds::make() | ||
->title('feed'); | ||
|
||
expect($opds->getOutput())->toBe(OpdsOutputEnum::xml); | ||
}); | ||
|
||
it('can use response', function () { | ||
$opds = Opds::make() | ||
->title('feed'); | ||
|
||
expect($opds->getResponse())->toBeInstanceOf(OpdsResponse::class); | ||
}); | ||
|
||
it('will throw exception with unspported version', function () { | ||
$opds = Opds::make() | ||
->title('feed'); | ||
|
||
expect(fn () => $opds->url('http://localhost:8000/opds?version=1.0'))->toThrow(Exception::class); | ||
expect(fn () => $opds->url('http://localhost:8000/opds?version=1.0'))->toThrow('OPDS version 1.0 is not supported.'); | ||
}); |
Oops, something went wrong.