HummingBirdAnimeClient/tests/AnimeClient/UtilTest.php

107 lines
2.1 KiB
PHP
Raw 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
*
2021-02-04 11:57:01 -05:00
* PHP version 8
*
2022-03-04 15:50:35 -05:00
* @copyright 2015 - 2022 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
2022-03-04 15:50:35 -05:00
* @link https://git.timshome.page/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
/**
* @param mixed $uri
*/
#[\PHPUnit\Framework\Attributes\DataProvider('dataIsViewPage')]
public function testIsViewPage($uri, mixed $expected)
{
$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
/**
* @param mixed $uri
* @param mixed $expected
*/
#[\PHPUnit\Framework\Attributes\DataProvider('dataIsViewPage')]
public function testIsFormPage($uri, $expected)
{
$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
}