LazyAssetManagerTest.php 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. /*
  3. * This file is part of the Assetic package, an OpenSky project.
  4. *
  5. * (c) 2010-2011 OpenSky Project Inc
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Assetic\Test\Factory;
  11. use Assetic\Factory\LazyAssetManager;
  12. class LazyAssetManagerTest extends \PHPUnit_Framework_TestCase
  13. {
  14. private $factory;
  15. protected function setUp()
  16. {
  17. $this->factory = $this->getMockBuilder('Assetic\\Factory\\AssetFactory')
  18. ->disableOriginalConstructor()
  19. ->getMock();
  20. $this->am = new LazyAssetManager($this->factory);
  21. }
  22. public function testGetFromLoader()
  23. {
  24. $resource = $this->getMock('Assetic\\Factory\\Resource\\ResourceInterface');
  25. $loader = $this->getMock('Assetic\\Factory\\Loader\\FormulaLoaderInterface');
  26. $asset = $this->getMock('Assetic\\Asset\\AssetInterface');
  27. $formula = array(
  28. array('js/core.js', 'js/more.js'),
  29. array('?yui_js'),
  30. array('output' => 'js/all.js')
  31. );
  32. $loader->expects($this->once())
  33. ->method('load')
  34. ->with($resource)
  35. ->will($this->returnValue(array('foo' => $formula)));
  36. $this->factory->expects($this->once())
  37. ->method('createAsset')
  38. ->with($formula[0], $formula[1], $formula[2] + array('name' => 'foo'))
  39. ->will($this->returnValue($asset));
  40. $this->am->setLoader('foo', $loader);
  41. $this->am->addResource($resource, 'foo');
  42. $this->assertSame($asset, $this->am->get('foo'), '->get() returns an asset from the loader');
  43. // test the "once" expectations
  44. $this->am->get('foo');
  45. }
  46. public function testGetResources()
  47. {
  48. $resources = array(
  49. $this->getMock('Assetic\\Factory\\Resource\\ResourceInterface'),
  50. $this->getMock('Assetic\\Factory\\Resource\\ResourceInterface'),
  51. );
  52. $this->am->addResource($resources[0], 'foo');
  53. $this->am->addResource($resources[1], 'bar');
  54. $ret = $this->am->getResources();
  55. foreach ($resources as $resource) {
  56. $this->assertTrue(in_array($resource, $ret, true));
  57. }
  58. }
  59. public function testGetResourcesEmpty()
  60. {
  61. $this->am->getResources();
  62. }
  63. public function testSetFormula()
  64. {
  65. $this->am->setFormula('foo', array());
  66. $this->am->load();
  67. $this->assertTrue($this->am->hasFormula('foo'), '->load() does not remove manually added formulae');
  68. }
  69. public function testIsDebug()
  70. {
  71. $this->factory->expects($this->once())
  72. ->method('isDebug')
  73. ->will($this->returnValue(false));
  74. $this->assertSame(false, $this->am->isDebug(), '->isDebug() proxies the factory');
  75. }
  76. }