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 / Factory / LazyAssetManagerTest.php

LazyAssetManagerTest.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/Factory/LazyAssetManagerTest.php

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