1
|
|
|
<?php |
2
|
|
|
namespace HtImgModuleTest\Imagine\Loader; |
3
|
|
|
|
4
|
|
|
use HtImgModule\Imagine\Loader\LoaderManager; |
5
|
|
|
|
6
|
|
|
class LoaderManagerTest extends \PHPUnit_Framework_TestCase |
7
|
|
|
{ |
8
|
|
|
public function testGetExceptionWhenImageLoaderCannotLoadImage() |
9
|
|
|
{ |
10
|
|
|
$imageLoaders = $this->createMock('Zend\ServiceManager\ServiceLocatorInterface'); |
11
|
|
|
$filterManager = $this->createMock('HtImgModule\Imagine\Filter\FilterManagerInterface'); |
12
|
|
|
$imageLoader = $this->createMock('HtImgModule\Imagine\Loader\LoaderInterface'); |
13
|
|
|
$mimeTypeGuesser = $this->getMockBuilder('HtImgModule\Binary\MimeTypeGuesser') |
14
|
|
|
->disableOriginalConstructor() |
15
|
|
|
->getMock(); |
16
|
|
|
$loadManager = new LoaderManager($imageLoaders, $filterManager, $imageLoader, $mimeTypeGuesser); |
17
|
|
|
|
18
|
|
|
$relativePath = 'relative/path/of/some/image'; |
19
|
|
|
$imageLoader->expects($this->once()) |
20
|
|
|
->method('load') |
21
|
|
|
->with($relativePath) |
22
|
|
|
->will($this->returnValue(FALSE)); |
23
|
|
|
|
24
|
|
|
$this->setExpectedException('HtImgModule\Exception\ImageNotFoundException'); |
|
|
|
|
25
|
|
|
$loadManager->loadBinary($relativePath, 'asdf'); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function getData() |
29
|
|
|
{ |
30
|
|
|
return [ |
31
|
|
|
['awesome_image_loader', ['loader_options' => ['a' => []]]], |
32
|
|
|
['awesome_image_loader_2', []], |
33
|
|
|
]; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @dataProvider getData |
38
|
|
|
*/ |
39
|
|
|
public function testLoadBinary($imageLoaderName, $filterOptions) |
40
|
|
|
{ |
41
|
|
|
$imageLoaders = $this->createMock('Zend\ServiceManager\ServiceLocatorInterface'); |
42
|
|
|
$filterManager = $this->createMock('HtImgModule\Imagine\Filter\FilterManagerInterface'); |
43
|
|
|
$imageLoader = $this->createMock('HtImgModule\Imagine\Loader\LoaderInterface'); |
44
|
|
|
$mimeTypeGuesser = $this->getMockBuilder('HtImgModule\Binary\MimeTypeGuesser') |
45
|
|
|
->disableOriginalConstructor() |
46
|
|
|
->getMock(); |
47
|
|
|
$loadManager = new LoaderManager($imageLoaders, $filterManager, $imageLoader, $mimeTypeGuesser); |
48
|
|
|
|
49
|
|
|
$relativePath = 'relative/path/of/some/image'; |
50
|
|
|
$filter = 'bar_filter'; |
51
|
|
|
$binaryContent = 'asdf55asd4f53as4df54asdf564asdf'; |
52
|
|
|
$mimeType = 'image/png'; |
53
|
|
|
$filterOptions['image_loader'] = $imageLoaderName; |
54
|
|
|
|
55
|
|
|
$filterManager->expects($this->once()) |
56
|
|
|
->method('getFilterOptions') |
57
|
|
|
->with($filter) |
58
|
|
|
->will($this->returnValue($filterOptions)); |
59
|
|
|
|
60
|
|
|
$imageLoaders->expects($this->once()) |
61
|
|
|
->method('get') |
62
|
|
|
->with($imageLoaderName) |
63
|
|
|
->will($this->returnValue($imageLoader)); |
64
|
|
|
|
65
|
|
|
$imageLoader->expects($this->once()) |
66
|
|
|
->method('load') |
67
|
|
|
->with($relativePath) |
68
|
|
|
->will($this->returnValue($binaryContent)); |
69
|
|
|
|
70
|
|
|
$mimeTypeGuesser->expects($this->once()) |
71
|
|
|
->method('guess') |
72
|
|
|
->with($binaryContent) |
73
|
|
|
->will($this->returnValue($mimeType)); |
74
|
|
|
|
75
|
|
|
$binary = $loadManager->loadBinary($relativePath, $filter); |
76
|
|
|
|
77
|
|
|
$this->assertInstanceOf('HtImgModule\Binary\Binary', $binary); |
78
|
|
|
$this->assertEquals($mimeType, $binary->getMimeType()); |
79
|
|
|
$this->assertEquals($loadManager->getExtensionGuesser()->guess($mimeType), $binary->getFormat()); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.