finished the asset tests.
This commit is contained in:
parent
9977ccb708
commit
19f8430ce2
|
@ -254,7 +254,7 @@ protected function asset($group, $name)
|
||||||
// ensure that we attach the correct path to the asset.
|
// ensure that we attach the correct path to the asset.
|
||||||
if (filter_var($asset['source'], FILTER_VALIDATE_URL) === false)
|
if (filter_var($asset['source'], FILTER_VALIDATE_URL) === false)
|
||||||
{
|
{
|
||||||
$asset['source'] = Bundle::assets($this->bundle).$asset['source'];
|
$asset['source'] = $this->path($asset['source']);
|
||||||
}
|
}
|
||||||
|
|
||||||
return HTML::$group($asset['source'], $asset['attributes']);
|
return HTML::$group($asset['source'], $asset['attributes']);
|
||||||
|
|
|
@ -18,7 +18,7 @@ class Config {
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected static $cache = array();
|
public static $cache = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if a configuration item or file exists.
|
* Determine if a configuration item or file exists.
|
||||||
|
|
|
@ -7,6 +7,8 @@ class AssetTest extends PHPUnit_Framework_TestCase {
|
||||||
*/
|
*/
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
|
Config::$items = array();
|
||||||
|
Config::$cache = array();
|
||||||
Asset::$containers = array();
|
Asset::$containers = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,7 +54,7 @@ public function testContainerMethodsCanBeDynamicallyCalled()
|
||||||
*/
|
*/
|
||||||
public function testNameIsSetOnAssetContainerConstruction()
|
public function testNameIsSetOnAssetContainerConstruction()
|
||||||
{
|
{
|
||||||
$container = new Laravel\Asset_Container('foo');
|
$container = $this->getContainer();
|
||||||
|
|
||||||
$this->assertEquals('foo', $container->name);
|
$this->assertEquals('foo', $container->name);
|
||||||
}
|
}
|
||||||
|
@ -64,7 +66,7 @@ public function testNameIsSetOnAssetContainerConstruction()
|
||||||
*/
|
*/
|
||||||
public function testAddMethodProperlySniffsAssetType()
|
public function testAddMethodProperlySniffsAssetType()
|
||||||
{
|
{
|
||||||
$container = new Laravel\Asset_Container('foo');
|
$container = $this->getContainer();
|
||||||
|
|
||||||
$container->add('jquery', 'jquery.js');
|
$container->add('jquery', 'jquery.js');
|
||||||
$container->add('common', 'common.css');
|
$container->add('common', 'common.css');
|
||||||
|
@ -80,7 +82,7 @@ public function testAddMethodProperlySniffsAssetType()
|
||||||
*/
|
*/
|
||||||
public function testStyleMethodProperlyRegistersAnAsset()
|
public function testStyleMethodProperlyRegistersAnAsset()
|
||||||
{
|
{
|
||||||
$container = new Laravel\Asset_Container('foo');
|
$container = $this->getContainer();
|
||||||
|
|
||||||
$container->style('common', 'common.css');
|
$container->style('common', 'common.css');
|
||||||
|
|
||||||
|
@ -94,7 +96,7 @@ public function testStyleMethodProperlyRegistersAnAsset()
|
||||||
*/
|
*/
|
||||||
public function testStyleMethodProperlySetsMediaAttributeIfNotSet()
|
public function testStyleMethodProperlySetsMediaAttributeIfNotSet()
|
||||||
{
|
{
|
||||||
$container = new Laravel\Asset_Container('foo');
|
$container = $this->getContainer();
|
||||||
|
|
||||||
$container->style('common', 'common.css');
|
$container->style('common', 'common.css');
|
||||||
|
|
||||||
|
@ -108,7 +110,7 @@ public function testStyleMethodProperlySetsMediaAttributeIfNotSet()
|
||||||
*/
|
*/
|
||||||
public function testStyleMethodProperlyIgnoresMediaAttributeIfSet()
|
public function testStyleMethodProperlyIgnoresMediaAttributeIfSet()
|
||||||
{
|
{
|
||||||
$container = new Laravel\Asset_Container('foo');
|
$container = $this->getContainer();
|
||||||
|
|
||||||
$container->style('common', 'common.css', array(), array('media' => 'print'));
|
$container->style('common', 'common.css', array(), array('media' => 'print'));
|
||||||
|
|
||||||
|
@ -122,11 +124,139 @@ public function testStyleMethodProperlyIgnoresMediaAttributeIfSet()
|
||||||
*/
|
*/
|
||||||
public function testScriptMethodProperlyRegistersAnAsset()
|
public function testScriptMethodProperlyRegistersAnAsset()
|
||||||
{
|
{
|
||||||
$container = new Laravel\Asset_Container('foo');
|
$container = $this->getContainer();
|
||||||
|
|
||||||
$container->script('jquery', 'jquery.js');
|
$container->script('jquery', 'jquery.js');
|
||||||
|
|
||||||
$this->assertEquals('jquery.js', $container->assets['script']['jquery']['source']);
|
$this->assertEquals('jquery.js', $container->assets['script']['jquery']['source']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test the Asset_Container::add method properly sets dependencies.
|
||||||
|
*
|
||||||
|
* @group laravel
|
||||||
|
*/
|
||||||
|
public function testAddMethodProperlySetsDependencies()
|
||||||
|
{
|
||||||
|
$container = $this->getContainer();
|
||||||
|
|
||||||
|
$container->add('common', 'common.css', 'jquery');
|
||||||
|
$container->add('jquery', 'jquery.js', array('jquery-ui'));
|
||||||
|
|
||||||
|
$this->assertEquals(array('jquery'), $container->assets['style']['common']['dependencies']);
|
||||||
|
$this->assertEquals(array('jquery-ui'), $container->assets['script']['jquery']['dependencies']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test the Asset_Container::add method properly sets attributes.
|
||||||
|
*
|
||||||
|
* @group laravel
|
||||||
|
*/
|
||||||
|
public function testAddMethodProperlySetsAttributes()
|
||||||
|
{
|
||||||
|
$container = $this->getContainer();
|
||||||
|
|
||||||
|
$container->add('common', 'common.css', array(), array('media' => 'print'));
|
||||||
|
$container->add('jquery', 'jquery.js', array(), array('defer'));
|
||||||
|
|
||||||
|
$this->assertEquals(array('media' => 'print'), $container->assets['style']['common']['attributes']);
|
||||||
|
$this->assertEquals(array('defer'), $container->assets['script']['jquery']['attributes']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test the Asset_Container::bundle method.
|
||||||
|
*
|
||||||
|
* @group laravel
|
||||||
|
*/
|
||||||
|
public function testBundleMethodCorrectlySetsTheAssetBundle()
|
||||||
|
{
|
||||||
|
$container = $this->getContainer();
|
||||||
|
|
||||||
|
$container->bundle('eloquent');
|
||||||
|
|
||||||
|
$this->assertEquals('eloquent', $container->bundle);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test the Asset_Container::path method.
|
||||||
|
*
|
||||||
|
* @group laravel
|
||||||
|
*/
|
||||||
|
public function testPathMethodReturnsCorrectPathForABundleAsset()
|
||||||
|
{
|
||||||
|
Config::$cache['application.url'] = 'http://localhost';
|
||||||
|
|
||||||
|
$container = $this->getContainer();
|
||||||
|
|
||||||
|
$container->bundle('eloquent');
|
||||||
|
|
||||||
|
$this->assertEquals('http://localhost/bundles/eloquent/foo.jpg', $container->path('foo.jpg'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test the Asset_Container::path method.
|
||||||
|
*
|
||||||
|
* @group laravel
|
||||||
|
*/
|
||||||
|
public function testPathMethodReturnsCorrectPathForAnApplicationAsset()
|
||||||
|
{
|
||||||
|
Config::$cache['application.url'] = 'http://localhost';
|
||||||
|
|
||||||
|
$container = $this->getContainer();
|
||||||
|
|
||||||
|
$this->assertEquals('http://localhost/foo.jpg', $container->path('foo.jpg'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test the Asset_Container::scripts method.
|
||||||
|
*
|
||||||
|
* @group laravel
|
||||||
|
*/
|
||||||
|
public function testScriptsCanBeRetrieved()
|
||||||
|
{
|
||||||
|
$container = $this->getContainer();
|
||||||
|
|
||||||
|
$container->script('dojo', 'dojo.js', array('jquery-ui'));
|
||||||
|
$container->script('jquery', 'jquery.js', array('jquery-ui', 'dojo'));
|
||||||
|
$container->script('jquery-ui', 'jquery-ui.js');
|
||||||
|
|
||||||
|
$scripts = $container->scripts();
|
||||||
|
|
||||||
|
$this->assertTrue(strpos($scripts, 'jquery.js') > 0);
|
||||||
|
$this->assertTrue(strpos($scripts, 'jquery.js') > strpos($scripts, 'jquery-ui.js'));
|
||||||
|
$this->assertTrue(strpos($scripts, 'dojo.js') > strpos($scripts, 'jquery-ui.js'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test the Asset_Container::styles method.
|
||||||
|
*
|
||||||
|
* @group laravel
|
||||||
|
*/
|
||||||
|
public function testStylesCanBeRetrieved()
|
||||||
|
{
|
||||||
|
$container = $this->getContainer();
|
||||||
|
|
||||||
|
$container->style('dojo', 'dojo.css', array('jquery-ui'), array('media' => 'print'));
|
||||||
|
$container->style('jquery', 'jquery.css', array('jquery-ui', 'dojo'));
|
||||||
|
$container->style('jquery-ui', 'jquery-ui.css');
|
||||||
|
|
||||||
|
$styles = $container->styles();
|
||||||
|
|
||||||
|
$this->assertTrue(strpos($styles, 'jquery.css') > 0);
|
||||||
|
$this->assertTrue(strpos($styles, 'media="print"') > 0);
|
||||||
|
$this->assertTrue(strpos($styles, 'jquery.css') > strpos($styles, 'jquery-ui.css'));
|
||||||
|
$this->assertTrue(strpos($styles, 'dojo.css') > strpos($styles, 'jquery-ui.css'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get an asset container instance.
|
||||||
|
*
|
||||||
|
* @param string $name
|
||||||
|
* @return Asset_Container
|
||||||
|
*/
|
||||||
|
private function getContainer($name = 'foo')
|
||||||
|
{
|
||||||
|
return new Laravel\Asset_Container($name);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue