1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Liip\ImagineBundle\Tests; |
4
|
|
|
|
5
|
|
|
use Liip\ImagineBundle\Imagine\Cache\Resolver\ResolverInterface; |
6
|
|
|
use Liip\ImagineBundle\Imagine\Filter\FilterConfiguration; |
7
|
|
|
use Symfony\Component\Filesystem\Filesystem; |
8
|
|
|
use Symfony\Component\Routing\RouterInterface; |
9
|
|
|
|
10
|
|
|
abstract class AbstractTest extends \PHPUnit_Framework_TestCase |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var Filesystem |
14
|
|
|
*/ |
15
|
|
|
protected $filesystem; |
16
|
|
|
|
17
|
|
|
protected $fixturesDir; |
18
|
|
|
protected $tempDir; |
19
|
|
|
|
20
|
|
|
protected function setUp() |
21
|
|
|
{ |
22
|
|
|
$this->fixturesDir = __DIR__.'/Fixtures'; |
23
|
|
|
|
24
|
|
|
$this->tempDir = str_replace('/', DIRECTORY_SEPARATOR, sys_get_temp_dir().'/liip_imagine_test'); |
25
|
|
|
|
26
|
|
|
$this->filesystem = new Filesystem(); |
27
|
|
|
|
28
|
|
|
if ($this->filesystem->exists($this->tempDir)) { |
29
|
|
|
$this->filesystem->remove($this->tempDir); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
$this->filesystem->mkdir($this->tempDir); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function invalidPathProvider() |
36
|
|
|
{ |
37
|
|
|
return array( |
38
|
|
|
array($this->fixturesDir.'/assets/../../foobar.png'), |
39
|
|
|
array($this->fixturesDir.'/assets/some_folder/../foobar.png'), |
40
|
|
|
array('../../outside/foobar.jpg'), |
41
|
|
|
); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
protected function createFilterConfiguration() |
45
|
|
|
{ |
46
|
|
|
$config = new FilterConfiguration(); |
47
|
|
|
$config->set('thumbnail', array( |
48
|
|
|
'size' => array(180, 180), |
49
|
|
|
'mode' => 'outbound', |
50
|
|
|
)); |
51
|
|
|
|
52
|
|
|
return $config; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
protected function getMockCacheManager() |
56
|
|
|
{ |
57
|
|
|
return $this->getMock('Liip\ImagineBundle\Imagine\Cache\CacheManager', array(), array(), '', false); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject|FilterConfiguration |
62
|
|
|
*/ |
63
|
|
|
protected function createFilterConfigurationMock() |
64
|
|
|
{ |
65
|
|
|
return $this->getMock('Liip\ImagineBundle\Imagine\Filter\FilterConfiguration'); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject|RouterInterface |
70
|
|
|
*/ |
71
|
|
|
protected function createRouterMock() |
72
|
|
|
{ |
73
|
|
|
return $this->getMock('Symfony\Component\Routing\RouterInterface'); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject|ResolverInterface |
78
|
|
|
*/ |
79
|
|
|
protected function createResolverMock() |
80
|
|
|
{ |
81
|
|
|
return $this->getMock('Liip\ImagineBundle\Imagine\Cache\Resolver\ResolverInterface'); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
protected function createEventDispatcherMock() |
85
|
|
|
{ |
86
|
|
|
return $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface'); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
protected function getMockImage() |
90
|
|
|
{ |
91
|
|
|
return $this->getMock('Imagine\Image\ImageInterface'); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
protected function getMockMetaData() |
95
|
|
|
{ |
96
|
|
|
return $this->getMock('Imagine\Image\Metadata\MetadataBag'); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
protected function createImagineMock() |
100
|
|
|
{ |
101
|
|
|
return $this->getMock('Imagine\Image\ImagineInterface'); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
protected function tearDown() |
105
|
|
|
{ |
106
|
|
|
if (!$this->filesystem) { |
107
|
|
|
return; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
if ($this->filesystem->exists($this->tempDir)) { |
111
|
|
|
$this->filesystem->remove($this->tempDir); |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
|