Beispiel #1
0
 public function testAddingAssets()
 {
     //test add()
     $this->assets->add('test.css');
     $css = $this->assets->css();
     $this->assertSame('<link href="/test.css" type="text/css" rel="stylesheet" />' . PHP_EOL, $css);
     $array = $this->assets->getCss();
     $this->assertSame(['asset' => '/test.css', 'priority' => 10, 'order' => 0, 'pipeline' => true, 'group' => 'head'], reset($array));
     $this->assets->add('test.js');
     $js = $this->assets->js();
     $this->assertSame('<script src="/test.js" type="text/javascript" ></script>' . PHP_EOL, $js);
     $array = $this->assets->getCss();
     $this->assertSame(['asset' => '/test.css', 'priority' => 10, 'order' => 0, 'pipeline' => true, 'group' => 'head'], reset($array));
     //test addCss(). Test adding asset to a separate group
     $this->assets->reset();
     $this->assets->addCSS('test.css');
     $css = $this->assets->css();
     $this->assertSame('<link href="/test.css" type="text/css" rel="stylesheet" />' . PHP_EOL, $css);
     $array = $this->assets->getCss();
     $this->assertSame(['asset' => '/test.css', 'priority' => 10, 'order' => 0, 'pipeline' => true, 'group' => 'head'], reset($array));
     //test addJs()
     $this->assets->reset();
     $this->assets->addJs('test.js');
     $js = $this->assets->js();
     $this->assertSame('<script src="/test.js" type="text/javascript" ></script>' . PHP_EOL, $js);
     $array = $this->assets->getJs();
     $this->assertSame(['asset' => '/test.js', 'priority' => 10, 'order' => 0, 'pipeline' => true, 'loading' => '', 'group' => 'head'], reset($array));
     //Test CSS Groups
     $this->assets->reset();
     $this->assets->addCSS('test.css', null, true, 'footer');
     $css = $this->assets->css();
     $this->assertEmpty($css);
     $css = $this->assets->css('footer');
     $this->assertSame('<link href="/test.css" type="text/css" rel="stylesheet" />' . PHP_EOL, $css);
     $array = $this->assets->getCss();
     $this->assertSame(['asset' => '/test.css', 'priority' => 10, 'order' => 0, 'pipeline' => true, 'group' => 'footer'], reset($array));
     //Test JS Groups
     $this->assets->reset();
     $this->assets->addJs('test.js', null, true, null, 'footer');
     $js = $this->assets->js();
     $this->assertEmpty($js);
     $js = $this->assets->js('footer');
     $this->assertSame('<script src="/test.js" type="text/javascript" ></script>' . PHP_EOL, $js);
     $array = $this->assets->getJs();
     $this->assertSame(['asset' => '/test.js', 'priority' => 10, 'order' => 0, 'pipeline' => true, 'loading' => '', 'group' => 'footer'], reset($array));
     //Test async / defer
     $this->assets->reset();
     $this->assets->addJs('test.js', null, true, 'async', null);
     $js = $this->assets->js();
     $this->assertSame('<script src="/test.js" type="text/javascript" async></script>' . PHP_EOL, $js);
     $array = $this->assets->getJs();
     $this->assertSame(['asset' => '/test.js', 'priority' => 10, 'order' => 0, 'pipeline' => true, 'loading' => 'async', 'group' => 'head'], reset($array));
     $this->assets->reset();
     $this->assets->addJs('test.js', null, true, 'defer', null);
     $js = $this->assets->js();
     $this->assertSame('<script src="/test.js" type="text/javascript" defer></script>' . PHP_EOL, $js);
     $array = $this->assets->getJs();
     $this->assertSame(['asset' => '/test.js', 'priority' => 10, 'order' => 0, 'pipeline' => true, 'loading' => 'defer', 'group' => 'head'], reset($array));
 }
Beispiel #2
0
 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);
 }