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