FileAssetTest.php 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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\FileAsset;
  12. class FileAssetTest extends \PHPUnit_Framework_TestCase
  13. {
  14. public function testInterface()
  15. {
  16. $asset = new FileAsset(__FILE__);
  17. $this->assertInstanceOf('Assetic\\Asset\\AssetInterface', $asset, 'Asset implements AssetInterface');
  18. }
  19. public function testLazyLoading()
  20. {
  21. $asset = new FileAsset(__FILE__);
  22. $this->assertEmpty($asset->getContent(), 'The asset content is empty before load');
  23. $asset->load();
  24. $this->assertNotEmpty($asset->getContent(), 'The asset content is not empty after load');
  25. }
  26. public function testGetLastModifiedType()
  27. {
  28. $asset = new FileAsset(__FILE__);
  29. $this->assertInternalType('integer', $asset->getLastModified(), '->getLastModified() returns an integer');
  30. }
  31. public function testGetLastModifiedValue()
  32. {
  33. $asset = new FileAsset(__FILE__);
  34. $this->assertLessThan(time(), $asset->getLastModified(), '->getLastModified() returns the mtime');
  35. }
  36. public function testDefaultBaseAndPath()
  37. {
  38. $asset = new FileAsset(__FILE__);
  39. $this->assertEquals(__DIR__, $asset->getSourceRoot(), '->__construct() defaults base to the asset directory');
  40. $this->assertEquals(basename(__FILE__), $asset->getSourcePath(), '->__construct() defaults path to the asset basename');
  41. }
  42. public function testPathGuessing()
  43. {
  44. $asset = new FileAsset(__FILE__, array(), __DIR__);
  45. $this->assertEquals(basename(__FILE__), $asset->getSourcePath(), '->__construct() guesses the asset path');
  46. }
  47. public function testInvalidBase()
  48. {
  49. $this->setExpectedException('InvalidArgumentException');
  50. $asset = new FileAsset(__FILE__, array(), __DIR__.'/foo');
  51. }
  52. }