2017-01-27 15:41:52 -05:00
|
|
|
<?php declare(strict_types=1);
|
2017-02-07 13:27:41 -05:00
|
|
|
/**
|
2017-02-15 16:13:32 -05:00
|
|
|
* Hummingbird Anime List Client
|
2017-02-07 13:27:41 -05:00
|
|
|
*
|
2018-08-22 13:48:27 -04:00
|
|
|
* An API client for Kitsu to manage anime and manga watch lists
|
2017-02-07 13:27:41 -05:00
|
|
|
*
|
2021-02-04 11:57:01 -05:00
|
|
|
* PHP version 8
|
2017-02-07 13:27:41 -05:00
|
|
|
*
|
2017-02-15 16:13:32 -05:00
|
|
|
* @package HummingbirdAnimeClient
|
2017-02-07 13:27:41 -05:00
|
|
|
* @author Timothy J. Warren <tim@timshomepage.net>
|
2021-01-13 01:52:03 -05:00
|
|
|
* @copyright 2015 - 2021 Timothy J. Warren
|
2017-02-07 13:27:41 -05:00
|
|
|
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
2020-12-10 17:06:50 -05:00
|
|
|
* @version 5.2
|
2017-03-07 20:53:58 -05:00
|
|
|
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
|
2017-02-07 13:27:41 -05:00
|
|
|
*/
|
2017-01-27 15:41:52 -05:00
|
|
|
|
|
|
|
namespace Aviat\AnimeClient\Tests\API;
|
|
|
|
|
2020-12-11 15:37:55 -05:00
|
|
|
use Aviat\AnimeClient\API\Kitsu\Enum\MangaPublishingStatus;
|
2020-08-26 15:22:14 -04:00
|
|
|
use Aviat\AnimeClient\Kitsu;
|
2017-03-01 22:07:51 -05:00
|
|
|
use Aviat\AnimeClient\API\Kitsu\Enum\AnimeAiringStatus;
|
2017-01-27 15:41:52 -05:00
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
|
|
|
|
class KitsuTest extends TestCase {
|
2020-12-11 15:37:55 -05:00
|
|
|
public function testGetAiringStatus(): void
|
2017-01-27 15:41:52 -05:00
|
|
|
{
|
|
|
|
$actual = Kitsu::getAiringStatus('next week', 'next year');
|
|
|
|
$this->assertEquals(AnimeAiringStatus::NOT_YET_AIRED, $actual);
|
|
|
|
}
|
2017-03-01 22:07:51 -05:00
|
|
|
|
2020-12-11 15:37:55 -05:00
|
|
|
public function testParseStreamingLinksEmpty(): void
|
2017-01-27 15:41:52 -05:00
|
|
|
{
|
|
|
|
$this->assertEquals([], Kitsu::parseStreamingLinks([]));
|
|
|
|
}
|
2020-12-11 15:37:55 -05:00
|
|
|
|
|
|
|
public function testParseStreamingLinks(): void
|
|
|
|
{
|
|
|
|
$nodes = [[
|
|
|
|
'url' => 'www.hulu.com/chobits',
|
|
|
|
'dubs' => ['ja'],
|
|
|
|
'subs' => ['en']
|
|
|
|
]];
|
|
|
|
|
|
|
|
$expected = [[
|
|
|
|
'meta' => [
|
|
|
|
'name' => 'Hulu',
|
|
|
|
'link' => TRUE,
|
|
|
|
'image' => 'streaming-logos/hulu.svg',
|
|
|
|
],
|
|
|
|
'link' => 'www.hulu.com/chobits',
|
|
|
|
'dubs' => ['ja'],
|
|
|
|
'subs' => ['en'],
|
|
|
|
]];
|
|
|
|
|
|
|
|
$this->assertEquals($expected, Kitsu::parseStreamingLinks($nodes));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetAiringStatusEmptyArguments(): void
|
|
|
|
{
|
|
|
|
$this->assertEquals(AnimeAiringStatus::NOT_YET_AIRED, Kitsu::getAiringStatus());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetAiringStatusIsAiring(): void
|
|
|
|
{
|
|
|
|
$this->assertEquals(AnimeAiringStatus::AIRING, Kitsu::getAiringStatus('yesterday'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getPublishingStatus(): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'current' => [
|
|
|
|
'kitsuStatus' => 'CURRENT',
|
|
|
|
'expected' => MangaPublishingStatus::CURRENT,
|
|
|
|
],
|
|
|
|
'future' => [
|
|
|
|
'kitsuStatus' => 'foo',
|
|
|
|
'expected' => MangaPublishingStatus::NOT_YET_PUBLISHED,
|
|
|
|
]
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $kitsuStatus
|
|
|
|
* @param string $expected
|
|
|
|
* @dataProvider getPublishingStatus
|
|
|
|
*/
|
|
|
|
public function testGetPublishingStatus(string $kitsuStatus, string $expected): void
|
|
|
|
{
|
|
|
|
$actual = Kitsu::getPublishingStatus($kitsuStatus);
|
|
|
|
$this->assertEquals($expected, $actual);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getFriendlyTime(): array
|
|
|
|
{
|
|
|
|
$SECONDS_IN_DAY = Kitsu::SECONDS_IN_MINUTE * Kitsu::MINUTES_IN_DAY;
|
|
|
|
$SECONDS_IN_HOUR = Kitsu::SECONDS_IN_MINUTE * Kitsu::MINUTES_IN_HOUR;
|
|
|
|
$SECONDS_IN_YEAR = Kitsu::SECONDS_IN_MINUTE * Kitsu::MINUTES_IN_YEAR;
|
|
|
|
|
|
|
|
return [[
|
|
|
|
'seconds' => $SECONDS_IN_YEAR,
|
|
|
|
'expected' => '1 year',
|
|
|
|
], [
|
|
|
|
'seconds' => $SECONDS_IN_HOUR,
|
|
|
|
'expected' => '1 hour',
|
|
|
|
], [
|
|
|
|
'seconds' => (2 * $SECONDS_IN_YEAR) + 30,
|
|
|
|
'expected' => '2 years, 30 seconds'
|
|
|
|
], [
|
|
|
|
'seconds' => (5 * $SECONDS_IN_YEAR) + (3 * $SECONDS_IN_DAY) + (17 * Kitsu::SECONDS_IN_MINUTE),
|
|
|
|
'expected' => '5 years, 3 days, and 17 minutes'
|
|
|
|
]];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param int $seconds
|
|
|
|
* @param string $expected
|
|
|
|
* @dataProvider getFriendlyTime
|
|
|
|
*/
|
|
|
|
public function testGetFriendlyTime(int $seconds, string $expected): void
|
|
|
|
{
|
|
|
|
$actual = Kitsu::friendlyTime($seconds);
|
|
|
|
|
|
|
|
$this->assertEquals($expected, $actual);
|
|
|
|
}
|
2021-02-10 10:59:15 -05:00
|
|
|
|
|
|
|
public function testFilterLocalizedTitles()
|
|
|
|
{
|
|
|
|
$input = [
|
|
|
|
'canonical' => 'foo',
|
|
|
|
'localized' => [
|
|
|
|
'en' => 'Foo the Movie',
|
|
|
|
'fr' => '',
|
|
|
|
'jp' => NULL,
|
|
|
|
],
|
|
|
|
'alternatives' => [],
|
|
|
|
];
|
|
|
|
|
|
|
|
$actual = Kitsu::filterLocalizedTitles($input);
|
|
|
|
|
|
|
|
$this->assertEquals(['Foo the Movie'], $actual);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetFilteredTitles()
|
|
|
|
{
|
|
|
|
$input = [
|
|
|
|
'canonical' => 'foo',
|
|
|
|
'localized' => [
|
|
|
|
'en' => 'Foo the Movie'
|
|
|
|
],
|
|
|
|
'alternatives' => [],
|
|
|
|
];
|
|
|
|
|
|
|
|
$actual = Kitsu::getFilteredTitles($input);
|
|
|
|
|
|
|
|
$this->assertEquals(['Foo the Movie'], $actual);
|
|
|
|
}
|
2017-01-27 15:41:52 -05:00
|
|
|
}
|