|
@@ -0,0 +1,121 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+class AssetTest extends PHPUnit_Framework_TestCase {
|
|
|
+
|
|
|
+ public function testContainerMethodReturnsContainer()
|
|
|
+ {
|
|
|
+ $asset = Laravel\IoC::resolve('laravel.asset');
|
|
|
+
|
|
|
+ $this->assertInstanceOf('Laravel\\Asset_Container', $asset->container());
|
|
|
+ $this->assertInstanceOf('Laravel\\Asset_Container', $asset->container('footer'));
|
|
|
+
|
|
|
+ $this->assertEquals($asset->container()->name, 'default');
|
|
|
+ $this->assertEquals($asset->container('footer')->name, 'footer');
|
|
|
+ }
|
|
|
+
|
|
|
+ public function testAssetManagerMagicallyCallsDefaultContainer()
|
|
|
+ {
|
|
|
+ $asset = Laravel\IoC::resolve('laravel.asset');
|
|
|
+
|
|
|
+ $mock = $this->getMockBuilder('Laravel\\Asset_Container')->disableOriginalConstructor()->getMock();
|
|
|
+
|
|
|
+ $mock->expects($this->any())->method('styles')->will($this->returnValue('styles'));
|
|
|
+
|
|
|
+ $asset->containers['default'] = $mock;
|
|
|
+
|
|
|
+ $this->assertEquals($asset->styles(), 'styles');
|
|
|
+ }
|
|
|
+
|
|
|
+ public function testAddMethodAddsAssetBasedOnExtension()
|
|
|
+ {
|
|
|
+ $container = $this->getContainer();
|
|
|
+
|
|
|
+ $container->add('jquery', 'js/jquery.js');
|
|
|
+ $container->add('jquery-css', 'css/jquery.css');
|
|
|
+
|
|
|
+ $this->assertEquals($container->assets['script']['jquery']['source'], 'js/jquery.js');
|
|
|
+ $this->assertEquals($container->assets['style']['jquery-css']['source'], 'css/jquery.css');
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @dataProvider assetProvider
|
|
|
+ */
|
|
|
+ public function testStyleMethodRegistersStylesheetAsset($type, $source, $attributes, $testAttributes)
|
|
|
+ {
|
|
|
+ $container = $this->getContainer();
|
|
|
+
|
|
|
+ $dependencies = array('jquery');
|
|
|
+
|
|
|
+ $container->$type('reset', $source, $dependencies, $attributes);
|
|
|
+
|
|
|
+ $this->assertEquals($container->assets[$type]['reset']['source'], $source);
|
|
|
+ $this->assertEquals($container->assets[$type]['reset']['dependencies'], $dependencies);
|
|
|
+ $this->assertEquals($container->assets[$type]['reset']['attributes'], $testAttributes);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function assetProvider()
|
|
|
+ {
|
|
|
+ $attributes = array('test' => 'test');
|
|
|
+
|
|
|
+ return array(
|
|
|
+ array('style', 'css/reset.css', $attributes, array_merge($attributes, array('media' => 'all'))),
|
|
|
+ array('script', 'js/jquery.js', $attributes, $attributes),
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ public function testStylesCanBeRetrieved()
|
|
|
+ {
|
|
|
+ $container = new Laravel\Asset_Container('default', new HTMLAssetStub);
|
|
|
+
|
|
|
+ $container->style('reset', 'css/reset.css');
|
|
|
+ $container->style('jquery', 'css/jquery.css');
|
|
|
+
|
|
|
+ $this->assertEquals($container->get_style('reset'), 'css/reset.css media:all');
|
|
|
+ $this->assertEquals($container->styles(), 'css/reset.css media:allcss/jquery.css media:all');
|
|
|
+ }
|
|
|
+
|
|
|
+ public function testScriptsCanBeRetrieved()
|
|
|
+ {
|
|
|
+ $container = new Laravel\Asset_Container('default', new HTMLAssetStub);
|
|
|
+
|
|
|
+ $container->script('jquery-ui', 'js/jquery-ui.js');
|
|
|
+ $container->script('jquery', 'js/jquery.js', array(), array('test' => 'value'));
|
|
|
+
|
|
|
+ $this->assertEquals($container->get_script('jquery-ui'), 'js/jquery-ui.js ');
|
|
|
+ $this->assertEquals($container->scripts(), 'js/jquery-ui.js js/jquery.js test:value');
|
|
|
+ }
|
|
|
+
|
|
|
+ private function getContainer()
|
|
|
+ {
|
|
|
+ return new Laravel\Asset_Container('default', Laravel\IoC::resolve('laravel.html'));
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+class HTMLAssetStub extends Laravel\HTML {
|
|
|
+
|
|
|
+ public function __construct() {}
|
|
|
+
|
|
|
+ public function style($source, $attributes)
|
|
|
+ {
|
|
|
+ return $source.' '.$this->getAttributes($attributes);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function script($source, $attributes)
|
|
|
+ {
|
|
|
+ return $source.' '.$this->getAttributes($attributes);
|
|
|
+ }
|
|
|
+
|
|
|
+ private function getAttributes($attributes)
|
|
|
+ {
|
|
|
+ $html = '';
|
|
|
+
|
|
|
+ foreach ($attributes as $key => $value)
|
|
|
+ {
|
|
|
+ $html .= $key.':'.$value;
|
|
|
+ }
|
|
|
+
|
|
|
+ return $html;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|