| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262 | <?phpclass AssetTest extends PHPUnit_Framework_TestCase {	/**	 * Initialize the test environment.	 */	public function setUp()	{		Config::$items = array();		Config::$cache = array();		Asset::$containers = array();	}	/**	 * Test the Asset::container method.	 *	 * @group laravel	 */	public function testContainersCanBeCreated()	{		$container = Asset::container('foo');		$this->assertTrue($container === Asset::container('foo'));		$this->assertInstanceOf('\\Laravel\\Asset_Container', $container);	}	/**	 * Test the Asset::container method for default container creation.	 *	 * @group laravel	 */	public function testDefaultContainerCreatedByDefault()	{		$this->assertEquals('default', Asset::container()->name);	}	/**	 * Test the Asset::__callStatic method.	 *	 * @group laravel	 */	public function testContainerMethodsCanBeDynamicallyCalled()	{		Asset::style('common', 'common.css');		$this->assertEquals('common.css', Asset::container()->assets['style']['common']['source']);	}	/**	 * Test the Asset_Container constructor.	 *	 * @group laravel	 */	public function testNameIsSetOnAssetContainerConstruction()	{		$container = $this->getContainer();		$this->assertEquals('foo', $container->name);	}	/**	 * Test the Asset_Container::add method.	 *	 * @group laravel	 */	public function testAddMethodProperlySniffsAssetType()	{		$container = $this->getContainer();		$container->add('jquery', 'jquery.js');		$container->add('common', 'common.css');		$this->assertEquals('jquery.js', $container->assets['script']['jquery']['source']);		$this->assertEquals('common.css', $container->assets['style']['common']['source']);	}	/**	 * Test the Asset_Container::style method.	 *	 * @group laravel	 */	public function testStyleMethodProperlyRegistersAnAsset()	{		$container = $this->getContainer();		$container->style('common', 'common.css');		$this->assertEquals('common.css', $container->assets['style']['common']['source']);	}	/**	 * Test the Asset_Container::style method sets media attribute.	 *	 * @group laravel	 */	public function testStyleMethodProperlySetsMediaAttributeIfNotSet()	{		$container = $this->getContainer();		$container->style('common', 'common.css');		$this->assertEquals('all', $container->assets['style']['common']['attributes']['media']);	}	/**	 * Test the Asset_Container::style method sets media attribute.	 *	 * @group laravel	 */	public function testStyleMethodProperlyIgnoresMediaAttributeIfSet()	{		$container = $this->getContainer();		$container->style('common', 'common.css', array(), array('media' => 'print'));		$this->assertEquals('print', $container->assets['style']['common']['attributes']['media']);	}	/**	 * Test the Asset_Container::script method.	 *	 * @group laravel	 */	public function testScriptMethodProperlyRegistersAnAsset()	{		$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::set('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::set('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);	}}
 |