|
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\Extension\Twig; |
|
|
13 |
|
|
|
14 |
use Assetic\Factory\AssetFactory; |
|
|
15 |
use Assetic\Extension\Twig\AsseticExtension; |
|
|
16 |
use Assetic\Extension\Twig\TwigFormulaLoader; |
|
|
17 |
|
|
|
18 |
class TwigFormulaLoaderTest extends \PHPUnit_Framework_TestCase |
|
|
19 |
{ |
|
|
20 |
private $am; |
|
|
21 |
private $fm; |
|
|
22 |
private $twig; |
|
|
23 |
|
|
|
24 |
protected function setUp() |
|
|
25 |
{ |
|
|
26 |
if (!class_exists('Twig_Environment')) { |
|
|
27 |
$this->markTestSkipped('Twig is not installed.'); |
|
|
28 |
} |
|
|
29 |
|
|
|
30 |
$this->am = $this->getMock('Assetic\\AssetManager'); |
|
|
31 |
$this->fm = $this->getMock('Assetic\\FilterManager'); |
|
|
32 |
|
|
|
33 |
$factory = new AssetFactory(__DIR__.'/templates'); |
|
|
34 |
$factory->setAssetManager($this->am); |
|
|
35 |
$factory->setFilterManager($this->fm); |
|
|
36 |
|
|
|
37 |
$twig = new \Twig_Environment(); |
|
|
38 |
$twig->addExtension(new AsseticExtension($factory, array( |
|
|
39 |
'some_func' => array( |
|
|
40 |
'filter' => 'some_filter', |
|
|
41 |
'options' => array('output' => 'css/*.css'), |
|
|
42 |
), |
|
|
43 |
))); |
|
|
44 |
|
|
|
45 |
$this->loader = new TwigFormulaLoader($twig); |
|
|
46 |
} |
|
|
47 |
|
|
|
48 |
public function testMixture() |
|
|
49 |
{ |
|
|
50 |
$asset = $this->getMock('Assetic\\Asset\\AssetInterface'); |
|
|
51 |
|
|
|
52 |
$expected = array( |
|
|
53 |
'mixture' => array( |
|
|
54 |
array('foo', 'foo/*', '@foo'), |
|
|
55 |
array(), |
|
|
56 |
array( |
|
|
57 |
'output' => 'packed/mixture', |
|
|
58 |
'name' => 'mixture', |
|
|
59 |
'debug' => false, |
|
|
60 |
'combine' => null, |
|
|
61 |
), |
|
|
62 |
), |
|
|
63 |
); |
|
|
64 |
|
|
|
65 |
$resource = $this->getMock('Assetic\\Factory\\Resource\\ResourceInterface'); |
|
|
66 |
$resource->expects($this->once()) |
|
|
67 |
->method('getContent') |
|
|
68 |
->will($this->returnValue(file_get_contents(__DIR__.'/templates/mixture.twig'))); |
|
|
69 |
$this->am->expects($this->any()) |
|
|
70 |
->method('get') |
|
|
71 |
->with('foo') |
|
|
72 |
->will($this->returnValue($asset)); |
|
|
73 |
|
|
|
74 |
$formulae = $this->loader->load($resource); |
|
|
75 |
$this->assertEquals($expected, $formulae); |
|
|
76 |
} |
|
|
77 |
|
|
|
78 |
public function testFunction() |
|
|
79 |
{ |
|
|
80 |
$expected = array( |
|
|
81 |
'my_asset' => array( |
|
|
82 |
array('path/to/asset'), |
|
|
83 |
array('some_filter'), |
|
|
84 |
array('output' => 'css/*.css', 'name' => 'my_asset'), |
|
|
85 |
), |
|
|
86 |
); |
|
|
87 |
|
|
|
88 |
$resource = $this->getMock('Assetic\\Factory\\Resource\\ResourceInterface'); |
|
|
89 |
$resource->expects($this->once()) |
|
|
90 |
->method('getContent') |
|
|
91 |
->will($this->returnValue(file_get_contents(__DIR__.'/templates/function.twig'))); |
|
|
92 |
|
|
|
93 |
$formulae = $this->loader->load($resource); |
|
|
94 |
$this->assertEquals($expected, $formulae); |
|
|
95 |
} |
|
|
96 |
} |