HummingBirdAnimeClient/tests/AnimeClient/UtilTest.php

100 lines
2.1 KiB
PHP
Raw Permalink Normal View History

<?php declare(strict_types=1);
/**
* Hummingbird Anime List Client
*
2018-08-22 13:48:27 -04:00
* An API client for Kitsu to manage anime and manga watch lists
*
2023-07-13 11:08:05 -04:00
* PHP version 8.1
*
2023-07-13 11:08:05 -04:00
* @copyright 2015 - 2023 Timothy J. Warren <tim@timshome.page>
* @license http://www.opensource.org/licenses/mit-license.html MIT License
2020-12-10 17:06:50 -05:00
* @version 5.2
2023-07-13 11:08:05 -04:00
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/
2016-08-29 17:09:56 -04:00
namespace Aviat\AnimeClient\Tests;
use Aviat\AnimeClient\Util;
2022-03-04 12:19:47 -05:00
/**
* @internal
*/
final class UtilTest extends AnimeClientTestCase
{
2017-02-22 15:08:29 -05:00
protected $util;
2016-08-29 17:09:56 -04:00
2022-03-04 12:19:47 -05:00
protected function setUp(): void
{
2016-08-29 17:09:56 -04:00
parent::setUp();
$this->util = new Util($this->container);
}
public function testIsSelected()
{
// Failure to match
2022-03-04 12:19:47 -05:00
$this->assertSame('', Util::isSelected('foo', 'bar'));
2016-08-29 17:09:56 -04:00
// Matches
2022-03-04 12:19:47 -05:00
$this->assertSame('selected', Util::isSelected('foo', 'foo'));
2016-08-29 17:09:56 -04:00
}
public function testIsNotSelected()
{
// Failure to match
2022-03-04 12:19:47 -05:00
$this->assertSame('selected', Util::isNotSelected('foo', 'bar'));
2016-08-29 17:09:56 -04:00
// Matches
2022-03-04 12:19:47 -05:00
$this->assertSame('', Util::isNotSelected('foo', 'foo'));
2016-08-29 17:09:56 -04:00
}
2023-05-09 12:46:52 -04:00
public static function dataIsViewPage()
2016-08-29 17:09:56 -04:00
{
return [
[
'uri' => '/anime/update',
2022-03-04 12:19:47 -05:00
'expected' => FALSE,
2016-08-29 17:09:56 -04:00
],
[
'uri' => '/anime/watching',
2022-03-04 12:19:47 -05:00
'expected' => TRUE,
2016-08-29 17:09:56 -04:00
],
[
'uri' => '/manga/reading',
2022-03-04 12:19:47 -05:00
'expected' => TRUE,
2016-08-29 17:09:56 -04:00
],
[
'uri' => '/manga/update',
2022-03-04 12:19:47 -05:00
'expected' => FALSE,
],
2016-08-29 17:09:56 -04:00
];
}
2023-05-09 12:46:52 -04:00
#[\PHPUnit\Framework\Attributes\DataProvider('dataIsViewPage')]
2023-05-19 10:56:23 -04:00
public function testIsViewPage(mixed $uri, mixed $expected)
2023-05-09 12:46:52 -04:00
{
$this->setSuperGlobals([
'_SERVER' => [
'REQUEST_URI' => $uri,
],
]);
$this->assertSame($expected, $this->util->isViewPage());
}
2016-08-29 17:09:56 -04:00
2023-05-09 12:46:52 -04:00
#[\PHPUnit\Framework\Attributes\DataProvider('dataIsViewPage')]
2023-05-19 10:56:23 -04:00
public function testIsFormPage(mixed $uri, mixed $expected)
2023-05-09 12:46:52 -04:00
{
$this->setSuperGlobals([
'_SERVER' => [
'REQUEST_URI' => $uri,
],
]);
$this->assertSame( ! $expected, $this->util->isFormPage());
}
2020-12-10 15:59:37 -05:00
public function testAriaCurrent(): void
{
2022-03-04 12:19:47 -05:00
$this->assertSame('true', Util::ariaCurrent(TRUE));
$this->assertSame('false', Util::ariaCurrent(FALSE));
2020-12-10 15:59:37 -05:00
}
2016-08-29 17:09:56 -04:00
}