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 / AssetReferenceTest.php

AssetReferenceTest.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/AssetReferenceTest.php

163 lines 4.8 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\AssetReference;
15 use Assetic\Asset\StringAsset;
16
17 class AssetReferenceTest extends \PHPUnit_Framework_TestCase
18 {
19 private $am;
20 private $ref;
21
22 protected function setUp()
23 {
24 $this->am = $this->getMockBuilder('Assetic\\AssetManager')->getMock();
25 $this->ref = new AssetReference($this->am, 'foo');
26 }
27
28 protected function tearDown()
29 {
30 $this->am = null;
31 $this->ref = null;
32 }
33
34 /**
35 * @dataProvider getMethodAndRetVal
36 */
37 public function testMethods($method, $returnValue)
38 {
39 $asset = $this->getMockBuilder('Assetic\\Asset\\AssetInterface')->getMock();
40
41 $this->am->expects($this->once())
42 ->method('get')
43 ->with('foo')
44 ->will($this->returnValue($asset));
45 $asset->expects($this->once())
46 ->method($method)
47 ->will($this->returnValue($returnValue));
48
49 $this->assertEquals($returnValue, $this->ref->$method(), '->'.$method.'() returns the asset value');
50 }
51
52 public function getMethodAndRetVal()
53 {
54 return array(
55 array('getContent', 'asdf'),
56 array('getSourceRoot', 'asdf'),
57 array('getSourcePath', 'asdf'),
58 array('getTargetPath', 'asdf'),
59 array('getLastModified', 123),
60 );
61 }
62
63 public function testLazyFilters()
64 {
65 $this->am->expects($this->never())->method('get');
66 $this->ref->ensureFilter($this->getMockBuilder('Assetic\\Filter\\FilterInterface')->getMock());
67 }
68
69 public function testFilterFlush()
70 {
71 $asset = $this->getMockBuilder('Assetic\\Asset\\AssetInterface')->getMock();
72
73 $this->am->expects($this->exactly(2))
74 ->method('get')
75 ->with('foo')
76 ->will($this->returnValue($asset));
77 $asset->expects($this->once())->method('ensureFilter');
78 $asset->expects($this->once())
79 ->method('getFilters')
80 ->will($this->returnValue(array()));
81
82 $this->ref->ensureFilter($this->getMockBuilder('Assetic\\Filter\\FilterInterface')->getMock());
83
84 $this->assertInternalType('array', $this->ref->getFilters(), '->getFilters() flushes and returns filters');
85 }
86
87 public function testSetContent()
88 {
89 $asset = $this->getMockBuilder('Assetic\\Asset\\AssetInterface')->getMock();
90
91 $this->am->expects($this->once())
92 ->method('get')
93 ->with('foo')
94 ->will($this->returnValue($asset));
95 $asset->expects($this->once())
96 ->method('setContent')
97 ->with('asdf');
98
99 $this->ref->setContent('asdf');
100 }
101
102 public function testLoad()
103 {
104 $filter = $this->getMockBuilder('Assetic\\Filter\\FilterInterface')->getMock();
105 $asset = $this->getMockBuilder('Assetic\\Asset\\AssetInterface')->getMock();
106
107 $this->am->expects($this->exactly(2))
108 ->method('get')
109 ->with('foo')
110 ->will($this->returnValue($asset));
111 $asset->expects($this->once())
112 ->method('load')
113 ->with($filter);
114
115 $this->ref->load($filter);
116 }
117
118 public function testDump()
119 {
120 $filter = $this->getMockBuilder('Assetic\\Filter\\FilterInterface')->getMock();
121 $asset = $this->getMockBuilder('Assetic\\Asset\\AssetInterface')->getMock();
122
123 $this->am->expects($this->exactly(2))
124 ->method('get')
125 ->with('foo')
126 ->will($this->returnValue($asset));
127 $asset->expects($this->once())
128 ->method('dump')
129 ->with($filter);
130
131 $this->ref->dump($filter);
132 }
133
134 public function testClone()
135 {
136 $filter1 = $this->getMockBuilder('Assetic\\Filter\\FilterInterface')->getMock();
137 $filter2 = $this->getMockBuilder('Assetic\\Filter\\FilterInterface')->getMock();
138 $filter3 = $this->getMockBuilder('Assetic\\Filter\\FilterInterface')->getMock();
139
140 $asset = new StringAsset('');
141 $this->am->expects($this->any())
142 ->method('get')
143 ->with('foo')
144 ->will($this->returnValue($asset));
145
146 $this->ref->ensureFilter($filter1);
147 $this->ref->load();
148
149 $clone1 = clone $this->ref;
150 $clone1->ensureFilter($filter2);
151 $clone1->load();
152
153 $clone2 = clone $clone1;
154 $clone2->ensureFilter($filter3);
155 $clone2->load();
156
157 $this->assertCount(1, $asset->getFilters());
158 $this->assertCount(1, $this->ref->getFilters());
159 $this->assertCount(2, $clone1->getFilters());
160 $this->assertCount(3, $clone2->getFilters());
161 }
162 }
163