HummingBirdAnimeClient/tests/AnimeClient/KitsuTest.php

168 lines
3.8 KiB
PHP
Raw Normal View History

<?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
2022-03-04 12:32:17 -05:00
* @author Timothy J. Warren <tim@timshome.page>
* @copyright 2015 - 2022 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
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
2017-02-07 13:27:41 -05:00
*/
namespace Aviat\AnimeClient\Tests\API;
2022-03-04 12:19:47 -05:00
use Aviat\AnimeClient\API\Kitsu\Enum\{AnimeAiringStatus, MangaPublishingStatus};
2020-08-26 15:22:14 -04:00
use Aviat\AnimeClient\Kitsu;
use PHPUnit\Framework\TestCase;
2022-03-04 12:19:47 -05:00
/**
* @internal
*/
final class KitsuTest extends TestCase
{
2020-12-11 15:37:55 -05:00
public function testGetAiringStatus(): void
{
$actual = Kitsu::getAiringStatus('next week', 'next year');
2022-03-04 12:19:47 -05:00
$this->assertSame(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
{
2022-03-04 12:19:47 -05:00
$this->assertSame([], Kitsu::parseStreamingLinks([]));
}
2020-12-11 15:37:55 -05:00
public function testParseStreamingLinks(): void
{
$nodes = [[
'url' => 'www.hulu.com/chobits',
'dubs' => ['ja'],
2022-03-04 12:19:47 -05:00
'subs' => ['en'],
2020-12-11 15:37:55 -05:00
]];
$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));
}
2021-02-23 12:00:22 -05:00
public function testParseStreamingLinksNoHost(): void
{
$nodes = [[
'url' => '/link-fragment',
'dubs' => [],
'subs' => [],
]];
2022-03-04 12:19:47 -05:00
$this->assertSame([], Kitsu::parseStreamingLinks($nodes));
2021-02-23 12:00:22 -05:00
}
2020-12-11 15:37:55 -05:00
public function testGetAiringStatusEmptyArguments(): void
{
2022-03-04 12:19:47 -05:00
$this->assertSame(AnimeAiringStatus::NOT_YET_AIRED, Kitsu::getAiringStatus());
2020-12-11 15:37:55 -05:00
}
public function testGetAiringStatusIsAiring(): void
{
2022-03-04 12:19:47 -05:00
$this->assertSame(AnimeAiringStatus::AIRING, Kitsu::getAiringStatus('yesterday'));
2020-12-11 15:37:55 -05:00
}
public function getPublishingStatus(): array
{
return [
'current' => [
'kitsuStatus' => 'CURRENT',
'expected' => MangaPublishingStatus::CURRENT,
],
'future' => [
'kitsuStatus' => 'foo',
'expected' => MangaPublishingStatus::NOT_YET_PUBLISHED,
2022-03-04 12:19:47 -05:00
],
2020-12-11 15:37:55 -05:00
];
}
/**
* @dataProvider getPublishingStatus
*/
public function testGetPublishingStatus(string $kitsuStatus, string $expected): void
{
$actual = Kitsu::getPublishingStatus($kitsuStatus);
2022-03-04 12:19:47 -05:00
$this->assertSame($expected, $actual);
2020-12-11 15:37:55 -05:00
}
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,
2022-03-04 12:19:47 -05:00
'expected' => '2 years, 30 seconds',
2020-12-11 15:37:55 -05:00
], [
'seconds' => (5 * $SECONDS_IN_YEAR) + (3 * $SECONDS_IN_DAY) + (17 * Kitsu::SECONDS_IN_MINUTE),
2022-03-04 12:19:47 -05:00
'expected' => '5 years, 3 days, and 17 minutes',
2020-12-11 15:37:55 -05:00
]];
}
/**
* @dataProvider getFriendlyTime
*/
public function testGetFriendlyTime(int $seconds, string $expected): void
{
$actual = Kitsu::friendlyTime($seconds);
2022-03-04 12:19:47 -05:00
$this->assertSame($expected, $actual);
2020-12-11 15:37:55 -05:00
}
2021-02-10 10:59:15 -05:00
2021-02-23 12:00:22 -05:00
public function testFilterLocalizedTitles(): void
2021-02-10 10:59:15 -05:00
{
$input = [
'canonical' => 'foo',
'localized' => [
'en' => 'Foo the Movie',
'fr' => '',
'jp' => NULL,
],
'alternatives' => [],
];
$actual = Kitsu::filterLocalizedTitles($input);
2022-03-04 12:19:47 -05:00
$this->assertSame(['Foo the Movie'], $actual);
2021-02-10 10:59:15 -05:00
}
2021-02-23 12:00:22 -05:00
public function testGetFilteredTitles(): void
2021-02-10 10:59:15 -05:00
{
$input = [
'canonical' => 'foo',
'localized' => [
2022-03-04 12:19:47 -05:00
'en' => 'Foo the Movie',
2021-02-10 10:59:15 -05:00
],
'alternatives' => [],
];
$actual = Kitsu::getFilteredTitles($input);
2022-03-04 12:19:47 -05:00
$this->assertSame(['Foo the Movie'], $actual);
2021-02-10 10:59:15 -05:00
}
2022-03-04 12:19:47 -05:00
}