2016-08-18 16:37:50 +02:00
|
|
|
<?php
|
2017-10-12 10:13:20 +02:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2016-08-18 16:37:50 +02:00
|
|
|
namespace ShlinkioTest\Shlink\Common\Image;
|
|
|
|
|
|
|
|
use mikehaertl\wkhtmlto\Image;
|
2017-03-24 20:34:18 +01:00
|
|
|
use PHPUnit\Framework\TestCase;
|
2018-10-28 08:24:06 +01:00
|
|
|
use ReflectionObject;
|
2016-08-18 16:37:50 +02:00
|
|
|
use Shlinkio\Shlink\Common\Image\ImageFactory;
|
|
|
|
use Zend\ServiceManager\ServiceManager;
|
|
|
|
|
|
|
|
class ImageFactoryTest extends TestCase
|
|
|
|
{
|
2018-11-20 19:30:27 +01:00
|
|
|
/** @var ImageFactory */
|
2018-11-20 19:37:22 +01:00
|
|
|
private $factory;
|
2016-08-18 16:37:50 +02:00
|
|
|
|
2019-02-16 10:53:45 +01:00
|
|
|
public function setUp(): void
|
2016-08-18 16:37:50 +02:00
|
|
|
{
|
|
|
|
$this->factory = new ImageFactory();
|
|
|
|
}
|
|
|
|
|
2019-02-17 20:28:34 +01:00
|
|
|
/** @test */
|
2016-08-18 16:37:50 +02:00
|
|
|
public function noPageIsSetWhenOptionsAreNotProvided()
|
|
|
|
{
|
|
|
|
/** @var Image $image */
|
|
|
|
$image = $this->factory->__invoke(new ServiceManager(['services' => [
|
2019-01-28 10:52:05 +01:00
|
|
|
'config' => ['wkhtmltopdf' => []],
|
2016-08-18 16:37:50 +02:00
|
|
|
]]), '');
|
|
|
|
$this->assertInstanceOf(Image::class, $image);
|
|
|
|
|
2018-10-28 08:24:06 +01:00
|
|
|
$ref = new ReflectionObject($image);
|
2016-08-18 16:37:50 +02:00
|
|
|
$page = $ref->getProperty('_page');
|
|
|
|
$page->setAccessible(true);
|
|
|
|
$this->assertNull($page->getValue($image));
|
|
|
|
}
|
|
|
|
|
2019-02-17 20:28:34 +01:00
|
|
|
/** @test */
|
2016-08-18 16:37:50 +02:00
|
|
|
public function aPageIsSetWhenOptionsIncludeTheUrl()
|
|
|
|
{
|
|
|
|
$expectedPage = 'foo/bar.html';
|
|
|
|
|
|
|
|
/** @var Image $image */
|
|
|
|
$image = $this->factory->__invoke(new ServiceManager(['services' => [
|
2019-01-28 10:52:05 +01:00
|
|
|
'config' => ['wkhtmltopdf' => []],
|
2016-08-18 16:37:50 +02:00
|
|
|
]]), '', ['url' => $expectedPage]);
|
|
|
|
$this->assertInstanceOf(Image::class, $image);
|
|
|
|
|
2018-10-28 08:24:06 +01:00
|
|
|
$ref = new ReflectionObject($image);
|
2016-08-18 16:37:50 +02:00
|
|
|
$page = $ref->getProperty('_page');
|
|
|
|
$page->setAccessible(true);
|
|
|
|
$this->assertEquals($expectedPage, $page->getValue($image));
|
|
|
|
}
|
|
|
|
}
|