|
0
|
1 |
<?php |
|
|
2 |
|
|
|
3 |
/* |
|
|
4 |
* This file is part of the Assetic package, an OpenSky project. |
|
|
5 |
* |
|
|
6 |
* (c) 2010-2011 OpenSky Project Inc |
|
|
7 |
* |
|
|
8 |
* For the full copyright and license information, please view the LICENSE |
|
|
9 |
* file that was distributed with this source code. |
|
|
10 |
*/ |
|
|
11 |
|
|
|
12 |
namespace Assetic\Test\Asset; |
|
|
13 |
|
|
|
14 |
use Assetic\Asset\AssetCache; |
|
|
15 |
|
|
|
16 |
class AssetCacheTest extends \PHPUnit_Framework_TestCase |
|
|
17 |
{ |
|
|
18 |
private $inner; |
|
|
19 |
private $cache; |
|
|
20 |
private $asset; |
|
|
21 |
|
|
|
22 |
protected function setUp() |
|
|
23 |
{ |
|
|
24 |
$this->inner = $this->getMock('Assetic\\Asset\\AssetInterface'); |
|
|
25 |
$this->cache = $this->getMock('Assetic\\Cache\\CacheInterface'); |
|
|
26 |
|
|
|
27 |
$this->asset = new AssetCache($this->inner, $this->cache); |
|
|
28 |
} |
|
|
29 |
|
|
|
30 |
public function testLoadFromCache() |
|
|
31 |
{ |
|
|
32 |
$content = 'asdf'; |
|
|
33 |
$filter = $this->getMock('Assetic\\Filter\\FilterInterface'); |
|
|
34 |
|
|
|
35 |
$this->inner->expects($this->once()) |
|
|
36 |
->method('getFilters') |
|
|
37 |
->will($this->returnValue(array($filter))); |
|
|
38 |
$this->cache->expects($this->once()) |
|
|
39 |
->method('has') |
|
|
40 |
->with($this->isType('string')) |
|
|
41 |
->will($this->returnValue(true)); |
|
|
42 |
$this->cache->expects($this->once()) |
|
|
43 |
->method('get') |
|
|
44 |
->with($this->isType('string')) |
|
|
45 |
->will($this->returnValue($content)); |
|
|
46 |
$this->inner->expects($this->once()) |
|
|
47 |
->method('setContent') |
|
|
48 |
->with($content); |
|
|
49 |
|
|
|
50 |
$this->asset->load($filter); |
|
|
51 |
} |
|
|
52 |
|
|
|
53 |
public function testLoadToCache() |
|
|
54 |
{ |
|
|
55 |
$content = 'asdf'; |
|
|
56 |
|
|
|
57 |
$this->inner->expects($this->once()) |
|
|
58 |
->method('getFilters') |
|
|
59 |
->will($this->returnValue(array())); |
|
|
60 |
$this->cache->expects($this->once()) |
|
|
61 |
->method('has') |
|
|
62 |
->with($this->isType('string')) |
|
|
63 |
->will($this->returnValue(false)); |
|
|
64 |
$this->inner->expects($this->once())->method('load'); |
|
|
65 |
$this->inner->expects($this->once()) |
|
|
66 |
->method('getContent') |
|
|
67 |
->will($this->returnValue($content)); |
|
|
68 |
$this->cache->expects($this->once()) |
|
|
69 |
->method('set') |
|
|
70 |
->with($this->isType('string'), $content); |
|
|
71 |
|
|
|
72 |
$this->asset->load(); |
|
|
73 |
} |
|
|
74 |
|
|
|
75 |
public function testDumpFromCache() |
|
|
76 |
{ |
|
|
77 |
$content = 'asdf'; |
|
|
78 |
|
|
|
79 |
$this->inner->expects($this->once()) |
|
|
80 |
->method('getFilters') |
|
|
81 |
->will($this->returnValue(array())); |
|
|
82 |
$this->cache->expects($this->once()) |
|
|
83 |
->method('has') |
|
|
84 |
->with($this->isType('string')) |
|
|
85 |
->will($this->returnValue(true)); |
|
|
86 |
$this->cache->expects($this->once()) |
|
|
87 |
->method('get') |
|
|
88 |
->with($this->isType('string')) |
|
|
89 |
->will($this->returnValue($content)); |
|
|
90 |
|
|
|
91 |
$this->assertEquals($content, $this->asset->dump(), '->dump() returns the cached value'); |
|
|
92 |
} |
|
|
93 |
|
|
|
94 |
public function testDumpToCache() |
|
|
95 |
{ |
|
|
96 |
$content = 'asdf'; |
|
|
97 |
|
|
|
98 |
$this->inner->expects($this->once()) |
|
|
99 |
->method('getFilters') |
|
|
100 |
->will($this->returnValue(array())); |
|
|
101 |
$this->cache->expects($this->once()) |
|
|
102 |
->method('has') |
|
|
103 |
->with($this->isType('string')) |
|
|
104 |
->will($this->returnValue(false)); |
|
|
105 |
$this->inner->expects($this->once()) |
|
|
106 |
->method('dump') |
|
|
107 |
->will($this->returnValue($content)); |
|
|
108 |
$this->cache->expects($this->once()) |
|
|
109 |
->method('set') |
|
|
110 |
->with($this->isType('string'), $content); |
|
|
111 |
|
|
|
112 |
$this->assertEquals($content, $this->asset->dump(), '->dump() returns the dumped value'); |
|
|
113 |
} |
|
|
114 |
|
|
|
115 |
public function testEnsureFilter() |
|
|
116 |
{ |
|
|
117 |
$filter = $this->getMock('Assetic\\Filter\\FilterInterface'); |
|
|
118 |
$this->inner->expects($this->once())->method('ensureFilter'); |
|
|
119 |
$this->asset->ensureFilter($filter); |
|
|
120 |
} |
|
|
121 |
|
|
|
122 |
public function testGetFilters() |
|
|
123 |
{ |
|
|
124 |
$this->inner->expects($this->once()) |
|
|
125 |
->method('getFilters') |
|
|
126 |
->will($this->returnValue(array())); |
|
|
127 |
|
|
|
128 |
$this->assertInternalType('array', $this->asset->getFilters(), '->getFilters() returns the inner asset filters'); |
|
|
129 |
} |
|
|
130 |
|
|
|
131 |
public function testGetContent() |
|
|
132 |
{ |
|
|
133 |
$this->inner->expects($this->once()) |
|
|
134 |
->method('getContent') |
|
|
135 |
->will($this->returnValue('asdf')); |
|
|
136 |
|
|
|
137 |
$this->assertEquals('asdf', $this->asset->getContent(), '->getContent() returns the inner asset content'); |
|
|
138 |
} |
|
|
139 |
|
|
|
140 |
public function testSetContent() |
|
|
141 |
{ |
|
|
142 |
$this->inner->expects($this->once()) |
|
|
143 |
->method('setContent') |
|
|
144 |
->with('asdf'); |
|
|
145 |
|
|
|
146 |
$this->asset->setContent('asdf'); |
|
|
147 |
} |
|
|
148 |
|
|
|
149 |
public function testGetSourceRoot() |
|
|
150 |
{ |
|
|
151 |
$this->inner->expects($this->once()) |
|
|
152 |
->method('getSourceRoot') |
|
|
153 |
->will($this->returnValue('asdf')); |
|
|
154 |
|
|
|
155 |
$this->assertEquals('asdf', $this->asset->getSourceRoot(), '->getSourceRoot() returns the inner asset source root'); |
|
|
156 |
} |
|
|
157 |
|
|
|
158 |
public function testGetSourcePath() |
|
|
159 |
{ |
|
|
160 |
$this->inner->expects($this->once()) |
|
|
161 |
->method('getSourcePath') |
|
|
162 |
->will($this->returnValue('asdf')); |
|
|
163 |
|
|
|
164 |
$this->assertEquals('asdf', $this->asset->getSourcePath(), '->getSourcePath() returns the inner asset source path'); |
|
|
165 |
} |
|
|
166 |
|
|
|
167 |
public function testGetLastModified() |
|
|
168 |
{ |
|
|
169 |
$this->inner->expects($this->once()) |
|
|
170 |
->method('getLastModified') |
|
|
171 |
->will($this->returnValue(123)); |
|
|
172 |
|
|
|
173 |
$this->assertEquals(123, $this->asset->getLastModified(), '->getLastModified() returns the inner asset last modified'); |
|
|
174 |
} |
|
|
175 |
} |