HummingBirdAnimeClient/tests/AnimeClient/KitsuTest.php

133 lines
3.0 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
*
2022-03-04 15:50:35 -05:00
* @copyright 2015 - 2022 Timothy J. Warren <tim@timshome.page>
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
2022-03-04 15:50:35 -05:00
* @link https://git.timshome.page/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
}
2023-05-09 12:46:52 -04:00
public static function getPublishingStatus(): array
2020-12-11 15:37:55 -05:00
{
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
];
}
2023-05-09 12:46:52 -04:00
#[\PHPUnit\Framework\Attributes\DataProvider('getPublishingStatus')]
public function testGetPublishingStatus(string $kitsuStatus, string $expected): void
2020-12-11 15:37:55 -05:00
{
$actual = Kitsu::getPublishingStatus($kitsuStatus);
$this->assertSame($expected, $actual);
2020-12-11 15:37:55 -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
}