1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace HtImgModuleTest\Imagine\Filter; |
4
|
|
|
|
5
|
|
|
use HtImgModule\Options\ModuleOptions; |
6
|
|
|
use HtImgModule\Imagine\Filter\FilterManager; |
7
|
|
|
use Zend\ServiceManager\ServiceManager; |
8
|
|
|
|
9
|
|
|
class FilterManagerTest extends \PHPUnit_Framework_TestCase |
10
|
|
|
{ |
11
|
|
|
protected $filterManager; |
12
|
|
|
|
13
|
|
|
public function SetUp() |
14
|
|
|
{ |
15
|
|
|
$this->filterManager = new FilterManager( |
16
|
|
|
new ModuleOptions, |
17
|
|
|
new ServiceManager |
18
|
|
|
); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
public function testFilterNotFoundException() |
22
|
|
|
{ |
23
|
|
|
$filterManager = new FilterManager( |
24
|
|
|
new ModuleOptions, |
25
|
|
|
new ServiceManager |
26
|
|
|
); |
27
|
|
|
$this->setExpectedException('HtImgModule\Exception\FilterNotFoundException'); |
|
|
|
|
28
|
|
|
$filterManager->getFilter('not_available'); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function testExceptionWithNoFilterType() |
32
|
|
|
{ |
33
|
|
|
$options = new ModuleOptions; |
34
|
|
|
$filterManager = new FilterManager( |
35
|
|
|
$options, |
36
|
|
|
new ServiceManager |
37
|
|
|
); |
38
|
|
|
$options->addFilter('hello', ['options' => 'hello']); |
39
|
|
|
$this->setExpectedException('HtImgModule\Exception\InvalidArgumentException'); |
|
|
|
|
40
|
|
|
$filterManager->getFilter('hello'); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function testExceptionWithNoFilterOptions() |
44
|
|
|
{ |
45
|
|
|
$options = new ModuleOptions; |
46
|
|
|
$filterManager = new FilterManager( |
47
|
|
|
$options, |
48
|
|
|
new ServiceManager |
49
|
|
|
); |
50
|
|
|
$options->addFilter('hello', ['type' => 'hello']); |
51
|
|
|
$this->setExpectedException('HtImgModule\Exception\InvalidArgumentException'); |
|
|
|
|
52
|
|
|
$filterManager->getFilter('hello'); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function testGetFilterOptions() |
56
|
|
|
{ |
57
|
|
|
$options = new ModuleOptions; |
58
|
|
|
$filterManager = new FilterManager( |
59
|
|
|
$options, |
60
|
|
|
new ServiceManager |
61
|
|
|
); |
62
|
|
|
$options->addFilter('filter_name', ['type' => 'hello', 'options' => ['key' => 'value']]); |
63
|
|
|
$filterOptions = $filterManager->getFilterOptions('filter_name'); |
64
|
|
|
$this->assertEquals(['key' => 'value'], $filterOptions); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function testGetFilter() |
68
|
|
|
{ |
69
|
|
|
$options = new ModuleOptions; |
70
|
|
|
$filterLoaders = new ServiceManager; |
71
|
|
|
$loader = $this->createMock('HtImgModule\Imagine\Filter\Loader\LoaderInterface'); |
72
|
|
|
$loader->expects($this->any()) |
73
|
|
|
->method('load') |
74
|
|
|
->will($this->returnValue('sample_loader')); |
75
|
|
|
$filterLoaders->setService('hello123', $loader); |
76
|
|
|
$filterManager = new FilterManager( |
77
|
|
|
$options, |
78
|
|
|
$filterLoaders |
79
|
|
|
); |
80
|
|
|
$options->addFilter('filter_name', ['type' => 'hello123', 'options' => ['key' => 'value']]); |
81
|
|
|
$this->assertEquals('sample_loader', $filterManager->getFilter('filter_name')); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function testAddFilter() |
85
|
|
|
{ |
86
|
|
|
$options = new ModuleOptions; |
87
|
|
|
$filterLoaders = new ServiceManager; |
88
|
|
|
$filterManager = new FilterManager( |
89
|
|
|
$options, |
90
|
|
|
$filterLoaders |
91
|
|
|
); |
92
|
|
|
$filterManager->addFilter('foo_filter', ['foo3' => 'bar3']); |
93
|
|
|
$this->assertEquals( ['foo3' => 'bar3'], $options->getFilters()['foo_filter']); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @covers HtImgModule\Imagine\Filter\FilterManager::applyFilter |
98
|
|
|
*/ |
99
|
|
|
public function testApplyFilter() |
100
|
|
|
{ |
101
|
|
|
$options = new ModuleOptions; |
102
|
|
|
$filterLoaders = new ServiceManager; |
103
|
|
|
$loader = $this->createMock('HtImgModule\Imagine\Filter\Loader\LoaderInterface'); |
104
|
|
|
$filter = $this->createMock('Imagine\Filter\FilterInterface'); |
105
|
|
|
$image = $this->createMock('Imagine\Image\ImageInterface'); |
106
|
|
|
$filteredImage = $this->createMock('Imagine\Image\ImageInterface'); |
107
|
|
|
$loader->expects($this->any()) |
108
|
|
|
->method('load') |
109
|
|
|
->will($this->returnValue($filter)); |
110
|
|
|
$filter->expects($this->once()) |
111
|
|
|
->method('apply') |
112
|
|
|
->will($this->returnValue($filteredImage)); |
113
|
|
|
$filterLoaders->setService('bar_filter', $loader); |
114
|
|
|
$filterManager = new FilterManager( |
115
|
|
|
$options, |
116
|
|
|
$filterLoaders |
117
|
|
|
); |
118
|
|
|
$options->addFilter('bar_filter', ['type' => 'bar_filter', 'options' => ['key' => 'value']]); |
119
|
|
|
$this->assertEquals($filteredImage, $filterManager->applyFilter($image, 'bar_filter')); |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|
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.