AssetCacheTest.php 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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\AssetCache;
  12. class AssetCacheTest extends \PHPUnit_Framework_TestCase
  13. {
  14. private $inner;
  15. private $cache;
  16. private $asset;
  17. protected function setUp()
  18. {
  19. $this->inner = $this->getMock('Assetic\\Asset\\AssetInterface');
  20. $this->cache = $this->getMock('Assetic\\Cache\\CacheInterface');
  21. $this->asset = new AssetCache($this->inner, $this->cache);
  22. }
  23. public function testLoadFromCache()
  24. {
  25. $content = 'asdf';
  26. $filter = $this->getMock('Assetic\\Filter\\FilterInterface');
  27. $this->inner->expects($this->once())
  28. ->method('getFilters')
  29. ->will($this->returnValue(array($filter)));
  30. $this->cache->expects($this->once())
  31. ->method('has')
  32. ->with($this->isType('string'))
  33. ->will($this->returnValue(true));
  34. $this->cache->expects($this->once())
  35. ->method('get')
  36. ->with($this->isType('string'))
  37. ->will($this->returnValue($content));
  38. $this->inner->expects($this->once())
  39. ->method('setContent')
  40. ->with($content);
  41. $this->asset->load($filter);
  42. }
  43. public function testLoadToCache()
  44. {
  45. $content = 'asdf';
  46. $this->inner->expects($this->once())
  47. ->method('getFilters')
  48. ->will($this->returnValue(array()));
  49. $this->cache->expects($this->once())
  50. ->method('has')
  51. ->with($this->isType('string'))
  52. ->will($this->returnValue(false));
  53. $this->inner->expects($this->once())->method('load');
  54. $this->inner->expects($this->once())
  55. ->method('getContent')
  56. ->will($this->returnValue($content));
  57. $this->cache->expects($this->once())
  58. ->method('set')
  59. ->with($this->isType('string'), $content);
  60. $this->asset->load();
  61. }
  62. public function testDumpFromCache()
  63. {
  64. $content = 'asdf';
  65. $this->inner->expects($this->once())
  66. ->method('getFilters')
  67. ->will($this->returnValue(array()));
  68. $this->cache->expects($this->once())
  69. ->method('has')
  70. ->with($this->isType('string'))
  71. ->will($this->returnValue(true));
  72. $this->cache->expects($this->once())
  73. ->method('get')
  74. ->with($this->isType('string'))
  75. ->will($this->returnValue($content));
  76. $this->assertEquals($content, $this->asset->dump(), '->dump() returns the cached value');
  77. }
  78. public function testDumpToCache()
  79. {
  80. $content = 'asdf';
  81. $this->inner->expects($this->once())
  82. ->method('getFilters')
  83. ->will($this->returnValue(array()));
  84. $this->cache->expects($this->once())
  85. ->method('has')
  86. ->with($this->isType('string'))
  87. ->will($this->returnValue(false));
  88. $this->inner->expects($this->once())
  89. ->method('dump')
  90. ->will($this->returnValue($content));
  91. $this->cache->expects($this->once())
  92. ->method('set')
  93. ->with($this->isType('string'), $content);
  94. $this->assertEquals($content, $this->asset->dump(), '->dump() returns the dumped value');
  95. }
  96. public function testEnsureFilter()
  97. {
  98. $filter = $this->getMock('Assetic\\Filter\\FilterInterface');
  99. $this->inner->expects($this->once())->method('ensureFilter');
  100. $this->asset->ensureFilter($filter);
  101. }
  102. public function testGetFilters()
  103. {
  104. $this->inner->expects($this->once())
  105. ->method('getFilters')
  106. ->will($this->returnValue(array()));
  107. $this->assertInternalType('array', $this->asset->getFilters(), '->getFilters() returns the inner asset filters');
  108. }
  109. public function testGetContent()
  110. {
  111. $this->inner->expects($this->once())
  112. ->method('getContent')
  113. ->will($this->returnValue('asdf'));
  114. $this->assertEquals('asdf', $this->asset->getContent(), '->getContent() returns the inner asset content');
  115. }
  116. public function testSetContent()
  117. {
  118. $this->inner->expects($this->once())
  119. ->method('setContent')
  120. ->with('asdf');
  121. $this->asset->setContent('asdf');
  122. }
  123. public function testGetSourceRoot()
  124. {
  125. $this->inner->expects($this->once())
  126. ->method('getSourceRoot')
  127. ->will($this->returnValue('asdf'));
  128. $this->assertEquals('asdf', $this->asset->getSourceRoot(), '->getSourceRoot() returns the inner asset source root');
  129. }
  130. public function testGetSourcePath()
  131. {
  132. $this->inner->expects($this->once())
  133. ->method('getSourcePath')
  134. ->will($this->returnValue('asdf'));
  135. $this->assertEquals('asdf', $this->asset->getSourcePath(), '->getSourcePath() returns the inner asset source path');
  136. }
  137. public function testGetLastModified()
  138. {
  139. $this->inner->expects($this->once())
  140. ->method('getLastModified')
  141. ->will($this->returnValue(123));
  142. $this->assertEquals(123, $this->asset->getLastModified(), '->getLastModified() returns the inner asset last modified');
  143. }
  144. }