From b049c2af0d2c6b5aa3e6e7ba130996d2251c98eb Mon Sep 17 00:00:00 2001 From: Ujjwal Ojha Date: Fri, 22 Aug 2014 20:21:27 +0545 Subject: [PATCH] Support for loader options --- src/Imagine/Loader/LoaderManager.php | 5 ++++- .../Imagine/Loader/LoaderManagerTest.php | 17 ++++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/Imagine/Loader/LoaderManager.php b/src/Imagine/Loader/LoaderManager.php index 7d90d5b..e19dd68 100644 --- a/src/Imagine/Loader/LoaderManager.php +++ b/src/Imagine/Loader/LoaderManager.php @@ -70,7 +70,10 @@ public function loadBinary($relativePath, $filter) $imageLoader = $this->defaultImageLoader; } if (!is_object($imageLoader)) { - $imageLoader = $this->imageLoaders->get($imageLoader); + $imageLoader = $this->imageLoaders->get( + $imageLoader, + isset($filterOptions['loader_options']) ? $filterOptions['loader_options'] : [] + ); } $binary = $imageLoader->load($relativePath); diff --git a/tests/HtImgModuleTest/Imagine/Loader/LoaderManagerTest.php b/tests/HtImgModuleTest/Imagine/Loader/LoaderManagerTest.php index fd3f13b..eeca375 100644 --- a/tests/HtImgModuleTest/Imagine/Loader/LoaderManagerTest.php +++ b/tests/HtImgModuleTest/Imagine/Loader/LoaderManagerTest.php @@ -25,7 +25,18 @@ public function testGetExceptionWhenImageLoaderCannotLoadImage() $loadManager->loadBinary($relativePath, 'asdf'); } - public function testLoadBinary() + public function getData() + { + return [ + ['awesome_image_loader', ['loader_options' => ['a' => []]]], + ['awesome_image_loader_2', []], + ]; + } + + /** + * @dataProvider getData + */ + public function testLoadBinary($imageLoaderName, $filterOptions) { $imageLoaders = $this->getMock('Zend\ServiceManager\ServiceLocatorInterface'); $filterManager = $this->getMock('HtImgModule\Imagine\Filter\FilterManagerInterface'); @@ -37,14 +48,14 @@ public function testLoadBinary() $relativePath = 'relative/path/of/some/image'; $filter = 'bar_filter'; - $imageLoaderName = 'some_image_loader'; $binaryContent = 'asdf55asd4f53as4df54asdf564asdf'; $mimeType = 'image/png'; + $filterOptions['image_loader'] = $imageLoaderName; $filterManager->expects($this->once()) ->method('getFilterOptions') ->with($filter) - ->will($this->returnValue(['image_loader' => $imageLoaderName])); + ->will($this->returnValue($filterOptions)); $imageLoaders->expects($this->once()) ->method('get')