From 34174b2fbe85888e050d5fbb2f7e25959ad74bf8 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Thu, 18 Aug 2016 16:37:50 +0200 Subject: [PATCH] Added tests for Image classes --- module/Common/src/Image/ImageFactory.php | 2 +- .../test/Image/ImageBuilderFactoryTest.php | 29 ++++++++++ module/Common/test/Image/ImageFactoryTest.php | 56 +++++++++++++++++++ 3 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 module/Common/test/Image/ImageBuilderFactoryTest.php create mode 100644 module/Common/test/Image/ImageFactoryTest.php diff --git a/module/Common/src/Image/ImageFactory.php b/module/Common/src/Image/ImageFactory.php index d7e74bd7..2bdea7be 100644 --- a/module/Common/src/Image/ImageFactory.php +++ b/module/Common/src/Image/ImageFactory.php @@ -27,7 +27,7 @@ class ImageFactory implements FactoryInterface $config = $container->get('config')['phpwkhtmltopdf']; $image = new Image(isset($config['images']) ? $config['images'] : null); - if (isset($options['url'])) { + if (isset($options) && isset($options['url'])) { $image->setPage($options['url']); } diff --git a/module/Common/test/Image/ImageBuilderFactoryTest.php b/module/Common/test/Image/ImageBuilderFactoryTest.php new file mode 100644 index 00000000..8e07b4a3 --- /dev/null +++ b/module/Common/test/Image/ImageBuilderFactoryTest.php @@ -0,0 +1,29 @@ +factory = new ImageBuilderFactory(); + } + + /** + * @test + */ + public function serviceIsCreated() + { + $instance = $this->factory->__invoke(new ServiceManager(), ''); + $this->assertInstanceOf(ImageBuilder::class, $instance); + } +} diff --git a/module/Common/test/Image/ImageFactoryTest.php b/module/Common/test/Image/ImageFactoryTest.php new file mode 100644 index 00000000..c4a3bd6a --- /dev/null +++ b/module/Common/test/Image/ImageFactoryTest.php @@ -0,0 +1,56 @@ +factory = new ImageFactory(); + } + + /** + * @test + */ + public function noPageIsSetWhenOptionsAreNotProvided() + { + /** @var Image $image */ + $image = $this->factory->__invoke(new ServiceManager(['services' => [ + 'config' => ['phpwkhtmltopdf' => []], + ]]), ''); + $this->assertInstanceOf(Image::class, $image); + + $ref = new \ReflectionObject($image); + $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); + + $ref = new \ReflectionObject($image); + $page = $ref->getProperty('_page'); + $page->setAccessible(true); + $this->assertEquals($expectedPage, $page->getValue($image)); + } +}