PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 3.2.5
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v3.2.5
4.7.0 4.6.1 4.6.0 4.5.5 4.5.4 4.5.3 4.5.2 3.2.20 3.2.21 3.2.22 3.2.3 3.2.5 3.2.6 3.2.7 3.2.9 3.3.0 3.3.1 3.3.2 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.7.0 3.7.1 All 111 releases
wp-optimize / vendor / kriswallsmith / assetic / tests / Assetic / Test / Asset / AssetCacheTest.php

AssetCacheTest.php in WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance 3.2.5, at vendor/kriswallsmith/assetic/tests/Assetic/Test/Asset/AssetCacheTest.php

184 lines 5.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*
4 * This file is part of the Assetic package, an OpenSky project.
5 *
6 * (c) 2010-2014 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 /** @var AssetCache */
21 private $asset;
22
23 protected function setUp()
24 {
25 $this->inner = $this->getMockBuilder('Assetic\\Asset\\AssetInterface')->getMock();
26 $this->cache = $this->getMockBuilder('Assetic\\Cache\\CacheInterface')->getMock();
27
28 $this->asset = new AssetCache($this->inner, $this->cache);
29 }
30
31 protected function tearDown()
32 {
33 $this->inner = null;
34 $this->cache = null;
35 $this->asset = null;
36 }
37
38 public function testLoadFromCache()
39 {
40 $content = 'asdf';
41 $filter = $this->getMockBuilder('Assetic\\Filter\\FilterInterface')->getMock();
42
43 $this->inner->expects($this->once())
44 ->method('getFilters')
45 ->will($this->returnValue(array($filter)));
46 $this->cache->expects($this->once())
47 ->method('has')
48 ->with($this->isType('string'))
49 ->will($this->returnValue(true));
50 $this->cache->expects($this->once())
51 ->method('get')
52 ->with($this->isType('string'))
53 ->will($this->returnValue($content));
54 $this->inner->expects($this->once())
55 ->method('setContent')
56 ->with($content);
57
58 $this->asset->load($filter);
59 }
60
61 public function testLoadToCache()
62 {
63 $content = 'asdf';
64
65 $this->inner->expects($this->once())
66 ->method('getFilters')
67 ->will($this->returnValue(array()));
68 $this->cache->expects($this->once())
69 ->method('has')
70 ->with($this->isType('string'))
71 ->will($this->returnValue(false));
72 $this->inner->expects($this->once())->method('load');
73 $this->inner->expects($this->once())
74 ->method('getContent')
75 ->will($this->returnValue($content));
76 $this->cache->expects($this->once())
77 ->method('set')
78 ->with($this->isType('string'), $content);
79
80 $this->asset->load();
81 }
82
83 public function testDumpFromCache()
84 {
85 $content = 'asdf';
86
87 $this->inner->expects($this->once())
88 ->method('getFilters')
89 ->will($this->returnValue(array()));
90 $this->cache->expects($this->once())
91 ->method('has')
92 ->with($this->isType('string'))
93 ->will($this->returnValue(true));
94 $this->cache->expects($this->once())
95 ->method('get')
96 ->with($this->isType('string'))
97 ->will($this->returnValue($content));
98
99 $this->assertEquals($content, $this->asset->dump(), '->dump() returns the cached value');
100 }
101
102 public function testDumpToCache()
103 {
104 $content = 'asdf';
105
106 $this->inner->expects($this->once())
107 ->method('getFilters')
108 ->will($this->returnValue(array()));
109 $this->cache->expects($this->once())
110 ->method('has')
111 ->with($this->isType('string'))
112 ->will($this->returnValue(false));
113 $this->inner->expects($this->once())
114 ->method('dump')
115 ->will($this->returnValue($content));
116 $this->cache->expects($this->once())
117 ->method('set')
118 ->with($this->isType('string'), $content);
119
120 $this->assertEquals($content, $this->asset->dump(), '->dump() returns the dumped value');
121 }
122
123 public function testEnsureFilter()
124 {
125 $filter = $this->getMockBuilder('Assetic\\Filter\\FilterInterface')->getMock();
126 $this->inner->expects($this->once())->method('ensureFilter');
127 $this->asset->ensureFilter($filter);
128 }
129
130 public function testGetFilters()
131 {
132 $this->inner->expects($this->once())
133 ->method('getFilters')
134 ->will($this->returnValue(array()));
135
136 $this->assertInternalType('array', $this->asset->getFilters(), '->getFilters() returns the inner asset filters');
137 }
138
139 public function testGetContent()
140 {
141 $this->inner->expects($this->once())
142 ->method('getContent')
143 ->will($this->returnValue('asdf'));
144
145 $this->assertEquals('asdf', $this->asset->getContent(), '->getContent() returns the inner asset content');
146 }
147
148 public function testSetContent()
149 {
150 $this->inner->expects($this->once())
151 ->method('setContent')
152 ->with('asdf');
153
154 $this->asset->setContent('asdf');
155 }
156
157 public function testGetSourceRoot()
158 {
159 $this->inner->expects($this->once())
160 ->method('getSourceRoot')
161 ->will($this->returnValue('asdf'));
162
163 $this->assertEquals('asdf', $this->asset->getSourceRoot(), '->getSourceRoot() returns the inner asset source root');
164 }
165
166 public function testGetSourcePath()
167 {
168 $this->inner->expects($this->once())
169 ->method('getSourcePath')
170 ->will($this->returnValue('asdf'));
171
172 $this->assertEquals('asdf', $this->asset->getSourcePath(), '->getSourcePath() returns the inner asset source path');
173 }
174
175 public function testGetLastModified()
176 {
177 $this->inner->expects($this->once())
178 ->method('getLastModified')
179 ->will($this->returnValue(123));
180
181 $this->assertEquals(123, $this->asset->getLastModified(), '->getLastModified() returns the inner asset last modified');
182 }
183 }
184