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