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
|
|
|
|
* @author Timothy J. Warren <tim@timshomepage.net>
|
2021-01-13 01:52:03 -05:00
|
|
|
* @copyright 2015 - 2021 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;
|
|
|
|
|
|
|
|
class PictureHelperTest extends AnimeClientTestCase {
|
|
|
|
/**
|
|
|
|
* @dataProvider dataPictureCase
|
2021-02-23 12:00:22 -05:00
|
|
|
* @param array $params
|
2018-11-02 12:58:19 -04:00
|
|
|
*/
|
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
|
|
|
* @param string $ext
|
|
|
|
* @param bool $isSimple
|
|
|
|
* @param string $fallbackExt
|
2018-11-02 12:58:19 -04:00
|
|
|
*/
|
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
|
|
|
|
|
|
|
$this->assertEquals($isSimple, $actuallySimple);
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
$actual = $helper("foo.svg", 'svg');
|
|
|
|
|
2021-02-23 12:00:22 -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' => [
|
|
|
|
'images/anime/15424.webp'
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'bmp with gif fallback' => [
|
|
|
|
'params' => [
|
|
|
|
'images/avatar/25.bmp',
|
|
|
|
'gif',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'webp placeholder image' => [
|
|
|
|
'params' => [
|
|
|
|
'images/placeholder.webp',
|
|
|
|
]
|
|
|
|
],
|
|
|
|
'png placeholder image' => [
|
|
|
|
'params' => [
|
|
|
|
'images/placeholder.png',
|
|
|
|
]
|
|
|
|
],
|
|
|
|
'jpeg2000' => [
|
|
|
|
'params' => [
|
|
|
|
'images/foo.jpf',
|
|
|
|
]
|
|
|
|
],
|
|
|
|
'svg with png fallback and lots of attributes' => [
|
|
|
|
'params' => [
|
|
|
|
'images/example.svg',
|
|
|
|
'png',
|
|
|
|
[ 'width' => 200, 'height' => 300 ],
|
|
|
|
[ 'alt' => 'Example text' ]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
'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'],
|
|
|
|
]
|
|
|
|
]
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
'fallback' => 'jpf'
|
|
|
|
],
|
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,
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|