|
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\Factory; |
|
|
13 |
|
|
|
14 |
use Assetic\Factory\LazyAssetManager; |
|
|
15 |
|
|
|
16 |
class LazyAssetManagerTest extends \PHPUnit_Framework_TestCase |
|
|
17 |
{ |
|
|
18 |
private $factory; |
|
|
19 |
|
|
|
20 |
protected function setUp() |
|
|
21 |
{ |
|
|
22 |
$this->factory = $this->getMockBuilder('Assetic\\Factory\\AssetFactory') |
|
|
23 |
->disableOriginalConstructor() |
|
|
24 |
->getMock(); |
|
|
25 |
|
|
|
26 |
$this->am = new LazyAssetManager($this->factory); |
|
|
27 |
} |
|
|
28 |
|
|
|
29 |
public function testGetFromLoader() |
|
|
30 |
{ |
|
|
31 |
$resource = $this->getMock('Assetic\\Factory\\Resource\\ResourceInterface'); |
|
|
32 |
$loader = $this->getMock('Assetic\\Factory\\Loader\\FormulaLoaderInterface'); |
|
|
33 |
$asset = $this->getMock('Assetic\\Asset\\AssetInterface'); |
|
|
34 |
|
|
|
35 |
$formula = array( |
|
|
36 |
array('js/core.js', 'js/more.js'), |
|
|
37 |
array('?yui_js'), |
|
|
38 |
array('output' => 'js/all.js') |
|
|
39 |
); |
|
|
40 |
|
|
|
41 |
$loader->expects($this->once()) |
|
|
42 |
->method('load') |
|
|
43 |
->with($resource) |
|
|
44 |
->will($this->returnValue(array('foo' => $formula))); |
|
|
45 |
$this->factory->expects($this->once()) |
|
|
46 |
->method('createAsset') |
|
|
47 |
->with($formula[0], $formula[1], $formula[2] + array('name' => 'foo')) |
|
|
48 |
->will($this->returnValue($asset)); |
|
|
49 |
|
|
|
50 |
$this->am->setLoader('foo', $loader); |
|
|
51 |
$this->am->addResource($resource, 'foo'); |
|
|
52 |
|
|
|
53 |
$this->assertSame($asset, $this->am->get('foo'), '->get() returns an asset from the loader'); |
|
|
54 |
|
|
|
55 |
// test the "once" expectations |
|
|
56 |
$this->am->get('foo'); |
|
|
57 |
} |
|
|
58 |
|
|
|
59 |
public function testGetResources() |
|
|
60 |
{ |
|
|
61 |
$resources = array( |
|
|
62 |
$this->getMock('Assetic\\Factory\\Resource\\ResourceInterface'), |
|
|
63 |
$this->getMock('Assetic\\Factory\\Resource\\ResourceInterface'), |
|
|
64 |
); |
|
|
65 |
|
|
|
66 |
$this->am->addResource($resources[0], 'foo'); |
|
|
67 |
$this->am->addResource($resources[1], 'bar'); |
|
|
68 |
|
|
|
69 |
$ret = $this->am->getResources(); |
|
|
70 |
|
|
|
71 |
foreach ($resources as $resource) { |
|
|
72 |
$this->assertTrue(in_array($resource, $ret, true)); |
|
|
73 |
} |
|
|
74 |
} |
|
|
75 |
|
|
|
76 |
public function testGetResourcesEmpty() |
|
|
77 |
{ |
|
|
78 |
$this->am->getResources(); |
|
|
79 |
} |
|
|
80 |
|
|
|
81 |
public function testSetFormula() |
|
|
82 |
{ |
|
|
83 |
$this->am->setFormula('foo', array()); |
|
|
84 |
$this->am->load(); |
|
|
85 |
$this->assertTrue($this->am->hasFormula('foo'), '->load() does not remove manually added formulae'); |
|
|
86 |
} |
|
|
87 |
|
|
|
88 |
public function testIsDebug() |
|
|
89 |
{ |
|
|
90 |
$this->factory->expects($this->once()) |
|
|
91 |
->method('isDebug') |
|
|
92 |
->will($this->returnValue(false)); |
|
|
93 |
|
|
|
94 |
$this->assertSame(false, $this->am->isDebug(), '->isDebug() proxies the factory'); |
|
|
95 |
} |
|
|
96 |
} |