|
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\AssetReference; |
|
|
15 |
|
|
|
16 |
class AssetReferenceTest extends \PHPUnit_Framework_TestCase |
|
|
17 |
{ |
|
|
18 |
private $am; |
|
|
19 |
private $ref; |
|
|
20 |
|
|
|
21 |
protected function setUp() |
|
|
22 |
{ |
|
|
23 |
$this->am = $this->getMock('Assetic\\AssetManager'); |
|
|
24 |
$this->ref = new AssetReference($this->am, 'foo'); |
|
|
25 |
} |
|
|
26 |
|
|
|
27 |
/** |
|
|
28 |
* @dataProvider getMethodAndRetVal |
|
|
29 |
*/ |
|
|
30 |
public function testMethods($method, $returnValue) |
|
|
31 |
{ |
|
|
32 |
$asset = $this->getMock('Assetic\\Asset\\AssetInterface'); |
|
|
33 |
|
|
|
34 |
$this->am->expects($this->once()) |
|
|
35 |
->method('get') |
|
|
36 |
->with('foo') |
|
|
37 |
->will($this->returnValue($asset)); |
|
|
38 |
$asset->expects($this->once()) |
|
|
39 |
->method($method) |
|
|
40 |
->will($this->returnValue($returnValue)); |
|
|
41 |
|
|
|
42 |
$this->assertEquals($returnValue, $this->ref->$method(), '->'.$method.'() returns the asset value'); |
|
|
43 |
} |
|
|
44 |
|
|
|
45 |
public function getMethodAndRetVal() |
|
|
46 |
{ |
|
|
47 |
return array( |
|
|
48 |
array('getContent', 'asdf'), |
|
|
49 |
array('getSourceRoot', 'asdf'), |
|
|
50 |
array('getSourcePath', 'asdf'), |
|
|
51 |
array('getTargetPath', 'asdf'), |
|
|
52 |
array('getLastModified', 123), |
|
|
53 |
); |
|
|
54 |
} |
|
|
55 |
|
|
|
56 |
public function testLazyFilters() |
|
|
57 |
{ |
|
|
58 |
$this->am->expects($this->never())->method('get'); |
|
|
59 |
$this->ref->ensureFilter($this->getMock('Assetic\\Filter\\FilterInterface')); |
|
|
60 |
} |
|
|
61 |
|
|
|
62 |
public function testFilterFlush() |
|
|
63 |
{ |
|
|
64 |
$asset = $this->getMock('Assetic\\Asset\\AssetInterface'); |
|
|
65 |
|
|
|
66 |
$this->am->expects($this->exactly(2)) |
|
|
67 |
->method('get') |
|
|
68 |
->with('foo') |
|
|
69 |
->will($this->returnValue($asset)); |
|
|
70 |
$asset->expects($this->once())->method('ensureFilter'); |
|
|
71 |
$asset->expects($this->once()) |
|
|
72 |
->method('getFilters') |
|
|
73 |
->will($this->returnValue(array())); |
|
|
74 |
|
|
|
75 |
$this->ref->ensureFilter($this->getMock('Assetic\\Filter\\FilterInterface')); |
|
|
76 |
|
|
|
77 |
$this->assertInternalType('array', $this->ref->getFilters(), '->getFilters() flushes and returns filters'); |
|
|
78 |
} |
|
|
79 |
|
|
|
80 |
public function testSetContent() |
|
|
81 |
{ |
|
|
82 |
$asset = $this->getMock('Assetic\\Asset\\AssetInterface'); |
|
|
83 |
|
|
|
84 |
$this->am->expects($this->once()) |
|
|
85 |
->method('get') |
|
|
86 |
->with('foo') |
|
|
87 |
->will($this->returnValue($asset)); |
|
|
88 |
$asset->expects($this->once()) |
|
|
89 |
->method('setContent') |
|
|
90 |
->with('asdf'); |
|
|
91 |
|
|
|
92 |
$this->ref->setContent('asdf'); |
|
|
93 |
} |
|
|
94 |
|
|
|
95 |
public function testLoad() |
|
|
96 |
{ |
|
|
97 |
$filter = $this->getMock('Assetic\\Filter\\FilterInterface'); |
|
|
98 |
$asset = $this->getMock('Assetic\\Asset\\AssetInterface'); |
|
|
99 |
|
|
|
100 |
$this->am->expects($this->exactly(2)) |
|
|
101 |
->method('get') |
|
|
102 |
->with('foo') |
|
|
103 |
->will($this->returnValue($asset)); |
|
|
104 |
$asset->expects($this->once()) |
|
|
105 |
->method('load') |
|
|
106 |
->with($filter); |
|
|
107 |
|
|
|
108 |
$this->ref->load($filter); |
|
|
109 |
} |
|
|
110 |
|
|
|
111 |
public function testDump() |
|
|
112 |
{ |
|
|
113 |
$filter = $this->getMock('Assetic\\Filter\\FilterInterface'); |
|
|
114 |
$asset = $this->getMock('Assetic\\Asset\\AssetInterface'); |
|
|
115 |
|
|
|
116 |
$this->am->expects($this->exactly(2)) |
|
|
117 |
->method('get') |
|
|
118 |
->with('foo') |
|
|
119 |
->will($this->returnValue($asset)); |
|
|
120 |
$asset->expects($this->once()) |
|
|
121 |
->method('dump') |
|
|
122 |
->with($filter); |
|
|
123 |
|
|
|
124 |
$this->ref->dump($filter); |
|
|
125 |
} |
|
|
126 |
} |