ORIENT/tests/unit/system/traits/AssetMakerTest.php

60 lines
1.9 KiB
PHP

<?php
class AssetMakerStub
{
use System\Traits\AssetMaker;
use System\Traits\ViewMaker; // Needed for guessViewPath(), which is used to set default assetPath
}
class AssetMakerTest extends TestCase
{
private $stub;
public function setUp()
{
$this->createApplication();
$this->stub = new AssetMakerStub();
}
//
// Helpers
//
protected static function callProtectedMethod($object, $name, $params = [])
{
$className = get_class($object);
$class = new ReflectionClass($className);
$method = $class->getMethod($name);
$method->setAccessible(true);
return $method->invokeArgs($object, $params);
}
//
// Tests
//
public function testGetLocalPath()
{
$basePath = base_path();
// Default assetPath
$assetPath = $this->stub->guessViewPath('/assets', true);
$resolvedPath = $this->callProtectedMethod($this->stub, 'getLocalPath', [$assetPath]);
$this->assertEquals(realpath($basePath.$assetPath), realpath($resolvedPath));
// Paths with symbols
$resolvedPath = $this->callProtectedMethod($this->stub, 'getLocalPath', ['~/themes/demo/']);
$this->assertEquals(realpath($basePath.'/themes/demo/'), realpath($resolvedPath));
$resolvedPath = $this->callProtectedMethod($this->stub, 'getLocalPath', ['~/plugins/demo/']);
$this->assertEquals(realpath($basePath.'/plugins/demo/'), realpath($resolvedPath));
$resolvedPath = $this->callProtectedMethod($this->stub, 'getLocalPath', ['$/demo/']);
$this->assertEquals(realpath($basePath.'/plugins/demo/'), realpath($resolvedPath));
// Absolute Path
$resolvedPath = $this->callProtectedMethod($this->stub, 'getLocalPath', [$basePath.'/some/wild/absolute/path/']);
$this->assertEquals(realpath($basePath.'/some/wild/absolute/path/'), realpath($resolvedPath));
}
}