public function testAddingJSAssetPropertiesWithArrayFromCollection() { //Test adding properties with array $this->assets->reset(); $this->assets->addJs('jquery', ['loading' => 'async']); $js = $this->assets->js(); $this->assertSame('<script src="/system/assets/jquery/jquery-2.x.min.js" type="text/javascript" async></script>' . PHP_EOL, $js); //Test priority too $this->assets->reset(); $this->assets->addJs('jquery', ['loading' => 'async', 'priority' => 1]); $this->assets->addJs('test.js', ['loading' => 'async', 'priority' => 2]); $js = $this->assets->js(); $this->assertSame('<script src="/test.js" type="text/javascript" async></script>' . PHP_EOL . '<script src="/system/assets/jquery/jquery-2.x.min.js" type="text/javascript" async></script>' . PHP_EOL, $js); //Test multiple groups $this->assets->reset(); $this->assets->addJs('jquery', ['loading' => 'async', 'priority' => 1, 'group' => 'footer']); $this->assets->addJs('test.js', ['loading' => 'async', 'priority' => 2]); $js = $this->assets->js(); $this->assertSame('<script src="/test.js" type="text/javascript" async></script>' . PHP_EOL, $js); $js = $this->assets->js('footer'); $this->assertSame('<script src="/system/assets/jquery/jquery-2.x.min.js" type="text/javascript" async></script>' . PHP_EOL, $js); //Test adding array of assets //Test priority too $this->assets->reset(); $this->assets->addJs(['jquery', 'test.js'], ['loading' => 'async']); $js = $this->assets->js(); $this->assertSame('<script src="/system/assets/jquery/jquery-2.x.min.js" type="text/javascript" async></script>' . PHP_EOL . '<script src="/test.js" type="text/javascript" async></script>' . PHP_EOL, $js); }
public function testTimestamps() { // local CSS nothing extra $this->assets->reset(); $this->assets->setTimestamp('foo'); $this->assets->addCSS('test.css'); $css = $this->assets->css(); $this->assertSame('<link href="/test.css?foo" type="text/css" rel="stylesheet" />' . PHP_EOL, $css); // local CSS already with param $this->assets->reset(); $this->assets->setTimestamp('foo'); $this->assets->addCSS('test.css?bar'); $css = $this->assets->css(); $this->assertSame('<link href="/test.css?bar&foo" type="text/css" rel="stylesheet" />' . PHP_EOL, $css); // external CSS already $this->assets->reset(); $this->assets->setTimestamp('foo'); $this->assets->addCSS('http://somesite.com/test.css'); $css = $this->assets->css(); $this->assertSame('<link href="http://somesite.com/test.css" type="text/css" rel="stylesheet" />' . PHP_EOL, $css); // external CSS already with param $this->assets->reset(); $this->assets->setTimestamp('foo'); $this->assets->addCSS('http://somesite.com/test.css?bar'); $css = $this->assets->css(); $this->assertSame('<link href="http://somesite.com/test.css?bar" type="text/css" rel="stylesheet" />' . PHP_EOL, $css); // local JS nothing extra $this->assets->reset(); $this->assets->setTimestamp('foo'); $this->assets->addJs('test.js'); $css = $this->assets->js(); $this->assertSame('<script src="/test.js?foo" type="text/javascript" ></script>' . PHP_EOL, $css); // local JS already with param $this->assets->reset(); $this->assets->setTimestamp('foo'); $this->assets->addJs('test.js?bar'); $css = $this->assets->js(); $this->assertSame('<script src="/test.js?bar&foo" type="text/javascript" ></script>' . PHP_EOL, $css); // external JS already $this->assets->reset(); $this->assets->setTimestamp('foo'); $this->assets->addJs('http://somesite.com/test.js'); $css = $this->assets->js(); $this->assertSame('<script src="http://somesite.com/test.js" type="text/javascript" ></script>' . PHP_EOL, $css); // external JS already with param $this->assets->reset(); $this->assets->setTimestamp('foo'); $this->assets->addJs('http://somesite.com/test.js?bar'); $css = $this->assets->js(); $this->assertSame('<script src="http://somesite.com/test.js?bar" type="text/javascript" ></script>' . PHP_EOL, $css); }