AssetReferenceTest.php 3.6KB

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