| 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\Asset; |
| 13 |
|
| 14 |
use Assetic\Asset\FileAsset; |
| 15 |
|
| 16 |
class FileAssetTest extends \PHPUnit_Framework_TestCase |
| 17 |
{ |
| 18 |
public function testInterface() |
| 19 |
{ |
| 20 |
$asset = new FileAsset(__FILE__); |
| 21 |
$this->assertInstanceOf('Assetic\\Asset\\AssetInterface', $asset, 'Asset implements AssetInterface'); |
| 22 |
} |
| 23 |
|
| 24 |
public function testLazyLoading() |
| 25 |
{ |
| 26 |
$asset = new FileAsset(__FILE__); |
| 27 |
$this->assertEmpty($asset->getContent(), 'The asset content is empty before load'); |
| 28 |
|
| 29 |
$asset->load(); |
| 30 |
$this->assertNotEmpty($asset->getContent(), 'The asset content is not empty after load'); |
| 31 |
} |
| 32 |
|
| 33 |
public function testGetLastModifiedType() |
| 34 |
{ |
| 35 |
$asset = new FileAsset(__FILE__); |
| 36 |
$this->assertInternalType('integer', $asset->getLastModified(), '->getLastModified() returns an integer'); |
| 37 |
} |
| 38 |
|
| 39 |
public function testGetLastModifiedTypeFileNotFound() |
| 40 |
{ |
| 41 |
$asset = new FileAsset(__DIR__."/foo/bar/baz.css"); |
| 42 |
|
| 43 |
$this->setExpectedException("RuntimeException", "The source file"); |
| 44 |
$asset->getLastModified(); |
| 45 |
} |
| 46 |
|
| 47 |
public function testGetLastModifiedValue() |
| 48 |
{ |
| 49 |
$asset = new FileAsset(__FILE__); |
| 50 |
$this->assertLessThan(time(), $asset->getLastModified(), '->getLastModified() returns the mtime'); |
| 51 |
} |
| 52 |
|
| 53 |
public function testDefaultBaseAndPath() |
| 54 |
{ |
| 55 |
$asset = new FileAsset(__FILE__); |
| 56 |
$this->assertEquals(__DIR__, $asset->getSourceRoot(), '->__construct() defaults base to the asset directory'); |
| 57 |
$this->assertEquals(basename(__FILE__), $asset->getSourcePath(), '->__construct() defaults path to the asset basename'); |
| 58 |
$this->assertEquals(__DIR__, $asset->getSourceDirectory(), '->__construct() derives the asset directory'); |
| 59 |
} |
| 60 |
|
| 61 |
public function testPathGuessing() |
| 62 |
{ |
| 63 |
$asset = new FileAsset(__FILE__, array(), __DIR__); |
| 64 |
$this->assertEquals(basename(__FILE__), $asset->getSourcePath(), '->__construct() guesses the asset path'); |
| 65 |
$this->assertEquals(__DIR__, $asset->getSourceDirectory(), '->__construct() derives the asset directory'); |
| 66 |
} |
| 67 |
|
| 68 |
public function testInvalidBase() |
| 69 |
{ |
| 70 |
$this->setExpectedException('InvalidArgumentException'); |
| 71 |
|
| 72 |
$asset = new FileAsset(__FILE__, array(), __DIR__.'/foo'); |
| 73 |
} |
| 74 |
} |
| 75 |
|