2018-11-02 12:58:19 -04:00
|
|
|
<?php declare(strict_types=1);
|
|
|
|
/**
|
|
|
|
* Hummingbird Anime List Client
|
|
|
|
*
|
|
|
|
* An API client for Kitsu to manage anime and manga watch lists
|
|
|
|
*
|
2021-02-04 11:57:01 -05:00
|
|
|
* PHP version 8
|
2018-11-02 12:58:19 -04:00
|
|
|
*
|
|
|
|
* @package HummingbirdAnimeClient
|
2022-03-04 12:32:17 -05:00
|
|
|
* @author Timothy J. Warren <tim@timshome.page>
|
|
|
|
* @copyright 2015 - 2022 Timothy J. Warren
|
2018-11-02 12:58:19 -04:00
|
|
|
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
2020-12-10 17:06:50 -05:00
|
|
|
* @version 5.2
|
2018-11-02 12:58:19 -04:00
|
|
|
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Aviat\AnimeClient\Tests\Helper;
|
|
|
|
|
|
|
|
use Aviat\AnimeClient\Helper\Picture as PictureHelper;
|
|
|
|
use Aviat\AnimeClient\Tests\AnimeClientTestCase;
|
|
|
|
|
2022-03-04 12:19:47 -05:00
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
*/
|
|
|
|
final class PictureHelperTest extends AnimeClientTestCase
|
|
|
|
{
|
2018-11-02 12:58:19 -04:00
|
|
|
/**
|
|
|
|
* @dataProvider dataPictureCase
|
|
|
|
*/
|
2021-02-23 12:00:22 -05:00
|
|
|
public function testPictureHelper(array $params): void
|
2018-11-02 12:58:19 -04:00
|
|
|
{
|
|
|
|
$helper = new PictureHelper();
|
|
|
|
$helper->setContainer($this->container);
|
|
|
|
|
|
|
|
$actual = $helper(...$params);
|
|
|
|
|
2021-02-23 12:00:22 -05:00
|
|
|
$this->assertMatchesSnapshot($actual);
|
2018-11-02 12:58:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider dataSimpleImageCase
|
|
|
|
*/
|
2021-02-23 12:00:22 -05:00
|
|
|
public function testSimpleImage(string $ext, bool $isSimple, string $fallbackExt = 'jpg'): void
|
2018-11-02 12:58:19 -04:00
|
|
|
{
|
|
|
|
$helper = new PictureHelper();
|
|
|
|
$helper->setContainer($this->container);
|
|
|
|
|
|
|
|
$url = "https://example.com/image.{$ext}";
|
2021-02-23 12:00:22 -05:00
|
|
|
$actual = $helper($url, $fallbackExt);
|
2018-11-02 12:58:19 -04:00
|
|
|
|
2021-02-23 12:00:22 -05:00
|
|
|
$actuallySimple = ! str_contains($actual, '<picture');
|
2018-11-02 12:58:19 -04:00
|
|
|
|
2022-03-04 12:19:47 -05:00
|
|
|
$this->assertSame($isSimple, $actuallySimple);
|
2018-11-02 12:58:19 -04:00
|
|
|
}
|
|
|
|
|
2021-02-23 12:00:22 -05:00
|
|
|
public function testSimpleImageByFallback(): void
|
2018-11-02 12:58:19 -04:00
|
|
|
{
|
|
|
|
$helper = new PictureHelper();
|
|
|
|
$helper->setContainer($this->container);
|
|
|
|
|
2022-03-04 12:19:47 -05:00
|
|
|
$actual = $helper('foo.svg', 'svg');
|
2018-11-02 12:58:19 -04:00
|
|
|
|
2022-03-04 12:19:47 -05:00
|
|
|
$this->assertTrue( ! str_contains($actual, '<picture'));
|
2018-11-02 12:58:19 -04:00
|
|
|
}
|
|
|
|
|
2021-02-23 12:00:22 -05:00
|
|
|
public function dataPictureCase(): array
|
2018-11-02 12:58:19 -04:00
|
|
|
{
|
|
|
|
return [
|
2021-02-23 12:00:22 -05:00
|
|
|
'Full AVIF URL' => [
|
|
|
|
'params' => [
|
|
|
|
'https://www.example.com/image.avif',
|
|
|
|
],
|
|
|
|
],
|
2018-11-02 12:58:19 -04:00
|
|
|
'Full webp URL' => [
|
|
|
|
'params' => [
|
|
|
|
'https://www.example.com/image.webp',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'Partial webp URL' => [
|
|
|
|
'params' => [
|
2022-03-04 12:19:47 -05:00
|
|
|
'images/anime/15424.webp',
|
2018-11-02 12:58:19 -04:00
|
|
|
],
|
|
|
|
],
|
|
|
|
'bmp with gif fallback' => [
|
|
|
|
'params' => [
|
|
|
|
'images/avatar/25.bmp',
|
|
|
|
'gif',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'webp placeholder image' => [
|
|
|
|
'params' => [
|
|
|
|
'images/placeholder.webp',
|
2022-03-04 12:19:47 -05:00
|
|
|
],
|
2018-11-02 12:58:19 -04:00
|
|
|
],
|
|
|
|
'png placeholder image' => [
|
|
|
|
'params' => [
|
|
|
|
'images/placeholder.png',
|
2022-03-04 12:19:47 -05:00
|
|
|
],
|
2018-11-02 12:58:19 -04:00
|
|
|
],
|
|
|
|
'jpeg2000' => [
|
|
|
|
'params' => [
|
|
|
|
'images/foo.jpf',
|
2022-03-04 12:19:47 -05:00
|
|
|
],
|
2018-11-02 12:58:19 -04:00
|
|
|
],
|
|
|
|
'svg with png fallback and lots of attributes' => [
|
|
|
|
'params' => [
|
|
|
|
'images/example.svg',
|
|
|
|
'png',
|
2022-03-04 12:19:47 -05:00
|
|
|
['width' => 200, 'height' => 300],
|
|
|
|
['alt' => 'Example text'],
|
|
|
|
],
|
2018-11-02 12:58:19 -04:00
|
|
|
],
|
|
|
|
'simple image with attributes' => [
|
|
|
|
'params' => [
|
|
|
|
'images/foo.jpg',
|
|
|
|
'jpg',
|
2021-02-23 12:00:22 -05:00
|
|
|
[],
|
2018-11-02 12:58:19 -04:00
|
|
|
['width' => 200, 'height' => 200, 'alt' => 'should exist'],
|
2022-03-04 12:19:47 -05:00
|
|
|
],
|
|
|
|
],
|
2018-11-02 12:58:19 -04:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2021-02-23 12:00:22 -05:00
|
|
|
public function dataSimpleImageCase(): array
|
2018-11-02 12:58:19 -04:00
|
|
|
{
|
|
|
|
return [
|
2021-02-23 12:00:22 -05:00
|
|
|
'avif' => [
|
|
|
|
'ext' => 'avif',
|
|
|
|
'isSimple' => FALSE,
|
2022-03-04 12:19:47 -05:00
|
|
|
'fallback' => 'jpf',
|
2021-02-23 12:00:22 -05:00
|
|
|
],
|
2018-11-02 12:58:19 -04:00
|
|
|
'apng' => [
|
|
|
|
'ext' => 'apng',
|
|
|
|
'isSimple' => FALSE,
|
|
|
|
],
|
|
|
|
'gif' => [
|
|
|
|
'ext' => 'gif',
|
|
|
|
'isSimple' => TRUE,
|
|
|
|
],
|
|
|
|
'jpg' => [
|
|
|
|
'ext' => 'jpg',
|
|
|
|
'isSimple' => TRUE,
|
|
|
|
],
|
|
|
|
'jpeg' => [
|
|
|
|
'ext' => 'jpeg',
|
|
|
|
'isSimple' => TRUE,
|
|
|
|
],
|
|
|
|
'png' => [
|
|
|
|
'ext' => 'png',
|
|
|
|
'isSimple' => TRUE,
|
|
|
|
],
|
|
|
|
'webp' => [
|
|
|
|
'ext' => 'webp',
|
|
|
|
'isSimple' => FALSE,
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
2022-03-04 12:19:47 -05:00
|
|
|
}
|