Commit 19f8430c authored by Taylor Otwell's avatar Taylor Otwell

finished the asset tests.

parent 9977ccb7
......@@ -254,7 +254,7 @@ class Asset_Container {
// ensure that we attach the correct path to the asset.
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']);
......
......@@ -18,7 +18,7 @@ class Config {
*
* @var array
*/
protected static $cache = array();
public static $cache = array();
/**
* Determine if a configuration item or file exists.
......
......@@ -7,6 +7,8 @@ class AssetTest extends PHPUnit_Framework_TestCase {
*/
public function setUp()
{
Config::$items = array();
Config::$cache = array();
Asset::$containers = array();
}
......@@ -52,7 +54,7 @@ class AssetTest extends PHPUnit_Framework_TestCase {
*/
public function testNameIsSetOnAssetContainerConstruction()
{
$container = new Laravel\Asset_Container('foo');
$container = $this->getContainer();
$this->assertEquals('foo', $container->name);
}
......@@ -64,7 +66,7 @@ class AssetTest extends PHPUnit_Framework_TestCase {
*/
public function testAddMethodProperlySniffsAssetType()
{
$container = new Laravel\Asset_Container('foo');
$container = $this->getContainer();
$container->add('jquery', 'jquery.js');
$container->add('common', 'common.css');
......@@ -80,7 +82,7 @@ class AssetTest extends PHPUnit_Framework_TestCase {
*/
public function testStyleMethodProperlyRegistersAnAsset()
{
$container = new Laravel\Asset_Container('foo');
$container = $this->getContainer();
$container->style('common', 'common.css');
......@@ -94,7 +96,7 @@ class AssetTest extends PHPUnit_Framework_TestCase {
*/
public function testStyleMethodProperlySetsMediaAttributeIfNotSet()
{
$container = new Laravel\Asset_Container('foo');
$container = $this->getContainer();
$container->style('common', 'common.css');
......@@ -108,7 +110,7 @@ class AssetTest extends PHPUnit_Framework_TestCase {
*/
public function testStyleMethodProperlyIgnoresMediaAttributeIfSet()
{
$container = new Laravel\Asset_Container('foo');
$container = $this->getContainer();
$container->style('common', 'common.css', array(), array('media' => 'print'));
......@@ -122,11 +124,139 @@ class AssetTest extends PHPUnit_Framework_TestCase {
*/
public function testScriptMethodProperlyRegistersAnAsset()
{
$container = new Laravel\Asset_Container('foo');
$container = $this->getContainer();
$container->script('jquery', 'jquery.js');
$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);
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment