maj grav
This commit is contained in:
@@ -32,201 +32,298 @@ class AssetsTest extends \Codeception\TestCase\Test
|
||||
$this->assets->add('test.css');
|
||||
|
||||
$css = $this->assets->css();
|
||||
$this->assertSame('<link href="/test.css" type="text/css" rel="stylesheet" />' . PHP_EOL, $css);
|
||||
$this->assertSame('<link href="/test.css" type="text/css" rel="stylesheet">' . PHP_EOL, $css);
|
||||
|
||||
$array = $this->assets->getCss();
|
||||
$this->assertSame([
|
||||
'asset' => '/test.css',
|
||||
'remote' => false,
|
||||
'priority' => 10,
|
||||
'order' => 0,
|
||||
'pipeline' => true,
|
||||
'loading' => '',
|
||||
'group' => 'head',
|
||||
'modified' => false,
|
||||
'query' => ''
|
||||
], reset($array));
|
||||
|
||||
/** @var Assets\BaseAsset $item */
|
||||
$item = reset($array);
|
||||
$actual = json_encode($item);
|
||||
$expected = '
|
||||
{
|
||||
"type":"css",
|
||||
"elements":{
|
||||
"asset":"\/test.css",
|
||||
"asset_type":"css",
|
||||
"order":0,
|
||||
"group":"head",
|
||||
"position":"pipeline",
|
||||
"priority":10,
|
||||
"attributes":{
|
||||
"type":"text\/css",
|
||||
"rel":"stylesheet"
|
||||
},
|
||||
"modified":false,
|
||||
"query":""
|
||||
}
|
||||
}';
|
||||
$this->assertJsonStringEqualsJsonString($expected, $actual);
|
||||
|
||||
$this->assets->add('test.js');
|
||||
$js = $this->assets->js();
|
||||
$this->assertSame('<script src="/test.js" ></script>' . PHP_EOL, $js);
|
||||
$this->assertSame('<script src="/test.js"></script>' . PHP_EOL, $js);
|
||||
|
||||
$array = $this->assets->getCss();
|
||||
$this->assertSame([
|
||||
'asset' => '/test.css',
|
||||
'remote' => false,
|
||||
'priority' => 10,
|
||||
'order' => 0,
|
||||
'pipeline' => true,
|
||||
'loading' => '',
|
||||
'group' => 'head',
|
||||
'modified' => false,
|
||||
'query' => ''
|
||||
], reset($array));
|
||||
$array = $this->assets->getJs();
|
||||
|
||||
/** @var Assets\BaseAsset $item */
|
||||
$item = reset($array);
|
||||
$actual = json_encode($item);
|
||||
$expected = '
|
||||
{
|
||||
"type":"js",
|
||||
"elements":{
|
||||
"asset":"\/test.js",
|
||||
"asset_type":"js",
|
||||
"order":0,
|
||||
"group":"head",
|
||||
"position":"pipeline",
|
||||
"priority":10,
|
||||
"attributes":[
|
||||
|
||||
],
|
||||
"modified":false,
|
||||
"query":""
|
||||
}
|
||||
}';
|
||||
$this->assertJsonStringEqualsJsonString($expected, $actual);
|
||||
|
||||
//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);
|
||||
$this->assertSame('<link href="/test.css" type="text/css" rel="stylesheet">' . PHP_EOL, $css);
|
||||
|
||||
$array = $this->assets->getCss();
|
||||
$this->assertSame([
|
||||
'asset' => '/test.css',
|
||||
'remote' => false,
|
||||
'priority' => 10,
|
||||
'order' => 0,
|
||||
'pipeline' => true,
|
||||
'loading' => '',
|
||||
'group' => 'head',
|
||||
'modified' => false,
|
||||
'query' => ''
|
||||
], reset($array));
|
||||
/** @var Assets\BaseAsset $item */
|
||||
$item = reset($array);
|
||||
$actual = json_encode($item);
|
||||
$expected = '
|
||||
{
|
||||
"type":"css",
|
||||
"elements":{
|
||||
"asset":"\/test.css",
|
||||
"asset_type":"css",
|
||||
"order":0,
|
||||
"group":"head",
|
||||
"position":"pipeline",
|
||||
"priority":10,
|
||||
"attributes":{
|
||||
"type":"text\/css",
|
||||
"rel":"stylesheet"
|
||||
},
|
||||
"modified":false,
|
||||
"query":""
|
||||
}
|
||||
}';
|
||||
$this->assertJsonStringEqualsJsonString($expected, $actual);
|
||||
|
||||
//test addCss(). Testing with remote URL
|
||||
$this->assets->reset();
|
||||
$this->assets->addCSS('http://www.somesite.com/test.css');
|
||||
$css = $this->assets->css();
|
||||
$this->assertSame('<link href="http://www.somesite.com/test.css" type="text/css" rel="stylesheet" />' . PHP_EOL, $css);
|
||||
$this->assertSame('<link href="http://www.somesite.com/test.css" type="text/css" rel="stylesheet">' . PHP_EOL, $css);
|
||||
|
||||
$array = $this->assets->getCss();
|
||||
$this->assertSame([
|
||||
'asset' => 'http://www.somesite.com/test.css',
|
||||
'remote' => true,
|
||||
'priority' => 10,
|
||||
'order' => 0,
|
||||
'pipeline' => true,
|
||||
'loading' => '',
|
||||
'group' => 'head',
|
||||
'modified' => false,
|
||||
'query' => ''
|
||||
], reset($array));
|
||||
/** @var Assets\BaseAsset $item */
|
||||
$item = reset($array);
|
||||
$actual = json_encode($item);
|
||||
$expected = '
|
||||
{
|
||||
"type":"css",
|
||||
"elements":{
|
||||
"asset":"http:\/\/www.somesite.com\/test.css",
|
||||
"asset_type":"css",
|
||||
"order":0,
|
||||
"group":"head",
|
||||
"position":"pipeline",
|
||||
"priority":10,
|
||||
"attributes":{
|
||||
"type":"text\/css",
|
||||
"rel":"stylesheet"
|
||||
},
|
||||
"query":""
|
||||
}
|
||||
}';
|
||||
$this->assertJsonStringEqualsJsonString($expected, $actual);
|
||||
|
||||
//test addCss() adding asset to a separate group, and with an alternate rel attribute
|
||||
$this->assets->reset();
|
||||
$this->assets->addCSS('test.css', ['group' => 'alternate']);
|
||||
$css = $this->assets->css('alternate', ['rel' => 'alternate']);
|
||||
$this->assertSame('<link href="/test.css" type="text/css" rel="alternate" />' . PHP_EOL, $css);
|
||||
$this->assets->addCSS('test.css', ['group' => 'alternate', 'rel' => 'alternate']);
|
||||
$css = $this->assets->css('alternate');
|
||||
$this->assertSame('<link href="/test.css" type="text/css" rel="alternate">' . PHP_EOL, $css);
|
||||
|
||||
//test addJs()
|
||||
$this->assets->reset();
|
||||
$this->assets->addJs('test.js');
|
||||
$js = $this->assets->js();
|
||||
$this->assertSame('<script src="/test.js" ></script>' . PHP_EOL, $js);
|
||||
$this->assertSame('<script src="/test.js"></script>' . PHP_EOL, $js);
|
||||
|
||||
$array = $this->assets->getJs();
|
||||
$this->assertSame([
|
||||
'asset' => '/test.js',
|
||||
'remote' => false,
|
||||
'priority' => 10,
|
||||
'order' => 0,
|
||||
'pipeline' => true,
|
||||
'loading' => '',
|
||||
'group' => 'head',
|
||||
'modified' => false,
|
||||
'query' => ''
|
||||
], reset($array));
|
||||
/** @var Assets\BaseAsset $item */
|
||||
$item = reset($array);
|
||||
$actual = json_encode($item);
|
||||
$expected = '
|
||||
{
|
||||
"type":"js",
|
||||
"elements":{
|
||||
"asset":"\/test.js",
|
||||
"asset_type":"js",
|
||||
"order":0,
|
||||
"group":"head",
|
||||
"position":"pipeline",
|
||||
"priority":10,
|
||||
"attributes":[],
|
||||
"modified":false,
|
||||
"query":""
|
||||
}
|
||||
}';
|
||||
$this->assertJsonStringEqualsJsonString($expected, $actual);
|
||||
|
||||
//Test CSS Groups
|
||||
$this->assets->reset();
|
||||
$this->assets->addCSS('test.css', null, true, 'footer');
|
||||
$this->assets->addCSS('test.css', ['group' => '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);
|
||||
$this->assertSame('<link href="/test.css" type="text/css" rel="stylesheet">' . PHP_EOL, $css);
|
||||
|
||||
$array = $this->assets->getCss();
|
||||
$this->assertSame([
|
||||
'asset' => '/test.css',
|
||||
'remote' => false,
|
||||
'priority' => 10,
|
||||
'order' => 0,
|
||||
'pipeline' => true,
|
||||
'loading' => '',
|
||||
'group' => 'footer',
|
||||
'modified' => false,
|
||||
'query' => ''
|
||||
], reset($array));
|
||||
/** @var Assets\BaseAsset $item */
|
||||
$item = reset($array);
|
||||
$actual = json_encode($item);
|
||||
$expected = '
|
||||
{
|
||||
"type": "css",
|
||||
"elements": {
|
||||
"asset": "/test.css",
|
||||
"asset_type": "css",
|
||||
"order": 0,
|
||||
"group": "footer",
|
||||
"position": "pipeline",
|
||||
"priority": 10,
|
||||
"attributes": {
|
||||
"type": "text/css",
|
||||
"rel": "stylesheet"
|
||||
},
|
||||
"modified": false,
|
||||
"query": ""
|
||||
}
|
||||
}
|
||||
';
|
||||
$this->assertJsonStringEqualsJsonString($expected, $actual);
|
||||
|
||||
//Test JS Groups
|
||||
$this->assets->reset();
|
||||
$this->assets->addJs('test.js', null, true, null, 'footer');
|
||||
$this->assets->addJs('test.js', ['group' => 'footer']);
|
||||
$js = $this->assets->js();
|
||||
$this->assertEmpty($js);
|
||||
$js = $this->assets->js('footer');
|
||||
$this->assertSame('<script src="/test.js" ></script>' . PHP_EOL, $js);
|
||||
$this->assertSame('<script src="/test.js"></script>' . PHP_EOL, $js);
|
||||
|
||||
$array = $this->assets->getJs();
|
||||
$this->assertSame([
|
||||
'asset' => '/test.js',
|
||||
'remote' => false,
|
||||
'priority' => 10,
|
||||
'order' => 0,
|
||||
'pipeline' => true,
|
||||
'loading' => '',
|
||||
'group' => 'footer',
|
||||
'modified' => false,
|
||||
'query' => ''
|
||||
], reset($array));
|
||||
/** @var Assets\BaseAsset $item */
|
||||
$item = reset($array);
|
||||
$actual = json_encode($item);
|
||||
$expected = '
|
||||
{
|
||||
"type": "js",
|
||||
"elements": {
|
||||
"asset": "/test.js",
|
||||
"asset_type": "js",
|
||||
"order": 0,
|
||||
"group": "footer",
|
||||
"position": "pipeline",
|
||||
"priority": 10,
|
||||
"attributes": [],
|
||||
"modified": false,
|
||||
"query": ""
|
||||
}
|
||||
}';
|
||||
$this->assertJsonStringEqualsJsonString($expected, $actual);
|
||||
|
||||
//Test async / defer
|
||||
$this->assets->reset();
|
||||
$this->assets->addJs('test.js', null, true, 'async', null);
|
||||
$this->assets->addJs('test.js', ['loading' => 'async']);
|
||||
$js = $this->assets->js();
|
||||
$this->assertSame('<script src="/test.js" async></script>' . PHP_EOL, $js);
|
||||
|
||||
$array = $this->assets->getJs();
|
||||
$this->assertSame([
|
||||
'asset' => '/test.js',
|
||||
'remote' => false,
|
||||
'priority' => 10,
|
||||
'order' => 0,
|
||||
'pipeline' => true,
|
||||
'loading' => 'async',
|
||||
'group' => 'head',
|
||||
'modified' => false,
|
||||
'query' => ''
|
||||
], reset($array));
|
||||
/** @var Assets\BaseAsset $item */
|
||||
$item = reset($array);
|
||||
$actual = json_encode($item);
|
||||
$expected = '
|
||||
{
|
||||
"type": "js",
|
||||
"elements": {
|
||||
"asset": "/test.js",
|
||||
"asset_type": "js",
|
||||
"order": 0,
|
||||
"group": "head",
|
||||
"position": "pipeline",
|
||||
"priority": 10,
|
||||
"attributes": {
|
||||
"loading": "async"
|
||||
},
|
||||
"modified": false,
|
||||
"query": ""
|
||||
}
|
||||
}';
|
||||
$this->assertJsonStringEqualsJsonString($expected, $actual);
|
||||
|
||||
$this->assets->reset();
|
||||
$this->assets->addJs('test.js', null, true, 'defer', null);
|
||||
$this->assets->addJs('test.js', ['loading' => 'defer']);
|
||||
$js = $this->assets->js();
|
||||
$this->assertSame('<script src="/test.js" defer></script>' . PHP_EOL, $js);
|
||||
|
||||
$array = $this->assets->getJs();
|
||||
$this->assertSame([
|
||||
'asset' => '/test.js',
|
||||
'remote' => false,
|
||||
'priority' => 10,
|
||||
'order' => 0,
|
||||
'pipeline' => true,
|
||||
'loading' => 'defer',
|
||||
'group' => 'head',
|
||||
'modified' => false,
|
||||
'query' => ''
|
||||
], reset($array));
|
||||
/** @var Assets\BaseAsset $item */
|
||||
$item = reset($array);
|
||||
$actual = json_encode($item);
|
||||
$expected = '
|
||||
{
|
||||
"type": "js",
|
||||
"elements": {
|
||||
"asset": "/test.js",
|
||||
"asset_type": "js",
|
||||
"order": 0,
|
||||
"group": "head",
|
||||
"position": "pipeline",
|
||||
"priority": 10,
|
||||
"attributes": {
|
||||
"loading": "defer"
|
||||
},
|
||||
"modified": false,
|
||||
"query": ""
|
||||
}
|
||||
}';
|
||||
$this->assertJsonStringEqualsJsonString($expected, $actual);
|
||||
|
||||
//Test inline
|
||||
$this->assets->reset();
|
||||
$this->assets->addJs('/system/assets/jquery/jquery-2.x.min.js', null, true, 'inline', null);
|
||||
$js = $this->assets->js();
|
||||
$this->assertContains('jQuery Foundation', $js);
|
||||
$this->assets->setJsPipeline(true);
|
||||
$this->assets->addJs('/system/assets/jquery/jquery-3.x.min.js');
|
||||
$js = $this->assets->js('head', ['loading' => 'inline']);
|
||||
$this->assertContains('"jquery",[],function()', $js);
|
||||
|
||||
$this->assets->reset();
|
||||
$this->assets->addCss('/system/assets/debugger.css', null, true, null, 'inline');
|
||||
$css = $this->assets->css();
|
||||
$this->assets->setCssPipeline(true);
|
||||
$this->assets->addCss('/system/assets/debugger.css');
|
||||
$css = $this->assets->css('head', ['loading' => 'inline']);
|
||||
$this->assertContains('div.phpdebugbar', $css);
|
||||
|
||||
$this->assets->reset();
|
||||
$this->assets->addCss('https://fonts.googleapis.com/css?family=Roboto', null, true, null, 'inline');
|
||||
$css = $this->assets->css();
|
||||
$this->assertContains('font-family: \'Roboto\';', $css);
|
||||
$this->assets->setCssPipeline(true);
|
||||
$this->assets->addCss('https://fonts.googleapis.com/css?family=Roboto');
|
||||
$css = $this->assets->css('head', ['loading' => 'inline']);
|
||||
$this->assertContains('font-family:\'Roboto\';', $css);
|
||||
|
||||
//Test adding media queries
|
||||
$this->assets->reset();
|
||||
$this->assets->add('test.css', ['media' => 'only screen and (min-width: 640px)']);
|
||||
$css = $this->assets->css();
|
||||
$this->assertSame('<link href="/test.css" type="text/css" rel="stylesheet" media="only screen and (min-width: 640px)" />' . PHP_EOL, $css);
|
||||
$this->assertSame('<link href="/test.css" type="text/css" rel="stylesheet" media="only screen and (min-width: 640px)">' . PHP_EOL, $css);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function testAddingAssetPropertiesWithArray()
|
||||
@@ -275,6 +372,81 @@ class AssetsTest extends \Codeception\TestCase\Test
|
||||
'<script src="/test.js" async></script>' . PHP_EOL, $js);
|
||||
}
|
||||
|
||||
public function testAddingLegacyFormat()
|
||||
{
|
||||
// regular CSS add
|
||||
//test addCss(). Test adding asset to a separate group
|
||||
$this->assets->reset();
|
||||
$this->assets->addCSS('test.css', 15, true, 'bottom', 'async');
|
||||
$css = $this->assets->css('bottom');
|
||||
$this->assertSame('<link href="/test.css" type="text/css" rel="stylesheet" async>' . PHP_EOL, $css);
|
||||
|
||||
$array = $this->assets->getCss();
|
||||
/** @var Assets\BaseAsset $item */
|
||||
$item = reset($array);
|
||||
$actual = json_encode($item);
|
||||
$expected = '
|
||||
{
|
||||
"type":"css",
|
||||
"elements":{
|
||||
"asset":"\/test.css",
|
||||
"asset_type":"css",
|
||||
"order":0,
|
||||
"group":"bottom",
|
||||
"position":"pipeline",
|
||||
"priority":15,
|
||||
"attributes":{
|
||||
"type":"text\/css",
|
||||
"rel":"stylesheet",
|
||||
"loading":"async"
|
||||
},
|
||||
"modified":false,
|
||||
"query":""
|
||||
}
|
||||
}';
|
||||
$this->assertJsonStringEqualsJsonString($expected, $actual);
|
||||
|
||||
$this->assets->reset();
|
||||
$this->assets->addJs('test.js', 15, false, 'defer', 'bottom');
|
||||
$js = $this->assets->js('bottom');
|
||||
$this->assertSame('<script src="/test.js" defer></script>' . PHP_EOL, $js);
|
||||
|
||||
$array = $this->assets->getJs();
|
||||
/** @var Assets\BaseAsset $item */
|
||||
$item = reset($array);
|
||||
$actual = json_encode($item);
|
||||
$expected = '
|
||||
{
|
||||
"type": "js",
|
||||
"elements": {
|
||||
"asset": "/test.js",
|
||||
"asset_type": "js",
|
||||
"order": 0,
|
||||
"group": "bottom",
|
||||
"position": "after",
|
||||
"priority": 15,
|
||||
"attributes": {
|
||||
"loading": "defer"
|
||||
},
|
||||
"modified": false,
|
||||
"query": ""
|
||||
}
|
||||
}';
|
||||
$this->assertJsonStringEqualsJsonString($expected, $actual);
|
||||
|
||||
|
||||
$this->assets->reset();
|
||||
$this->assets->addInlineCss('body { color: black }', 15, 'bottom');
|
||||
$css = $this->assets->css('bottom');
|
||||
$this->assertSame('<style>' . PHP_EOL . 'body { color: black }' . PHP_EOL . '</style>' . PHP_EOL, $css);
|
||||
|
||||
$this->assets->reset();
|
||||
$this->assets->addInlineJs('alert("test")', 15, 'bottom', ['id' => 'foo']);
|
||||
$js = $this->assets->js('bottom');
|
||||
$this->assertSame('<script id="foo">' . PHP_EOL . 'alert("test")' . PHP_EOL . '</script>' . PHP_EOL, $js);
|
||||
|
||||
}
|
||||
|
||||
public function testAddingCSSAssetPropertiesWithArrayFromCollection()
|
||||
{
|
||||
$this->assets->registerCollection('test', ['/system/assets/whoops.css']);
|
||||
@@ -284,25 +456,25 @@ class AssetsTest extends \Codeception\TestCase\Test
|
||||
$this->assets->addCss('test', ['priority' => 1]);
|
||||
$this->assets->addCss('test.css', ['priority' => 2]);
|
||||
$css = $this->assets->css();
|
||||
$this->assertSame('<link href="/test.css" type="text/css" rel="stylesheet" />' . PHP_EOL .
|
||||
'<link href="/system/assets/whoops.css" type="text/css" rel="stylesheet" />' . PHP_EOL, $css);
|
||||
$this->assertSame('<link href="/test.css" type="text/css" rel="stylesheet">' . PHP_EOL .
|
||||
'<link href="/system/assets/whoops.css" type="text/css" rel="stylesheet">' . PHP_EOL, $css);
|
||||
|
||||
//Test multiple groups
|
||||
$this->assets->reset();
|
||||
$this->assets->addCss('test', ['priority' => 1, 'group' => 'footer']);
|
||||
$this->assets->addCss('test.css', ['priority' => 2]);
|
||||
$css = $this->assets->css();
|
||||
$this->assertSame('<link href="/test.css" type="text/css" rel="stylesheet" />' . PHP_EOL, $css);
|
||||
$this->assertSame('<link href="/test.css" type="text/css" rel="stylesheet">' . PHP_EOL, $css);
|
||||
$css = $this->assets->css('footer');
|
||||
$this->assertSame('<link href="/system/assets/whoops.css" type="text/css" rel="stylesheet" />' . PHP_EOL, $css);
|
||||
$this->assertSame('<link href="/system/assets/whoops.css" type="text/css" rel="stylesheet">' . PHP_EOL, $css);
|
||||
|
||||
//Test adding array of assets
|
||||
//Test priority too
|
||||
$this->assets->reset();
|
||||
$this->assets->addCss(['test', 'test.css'], ['loading' => 'async']);
|
||||
$css = $this->assets->css();
|
||||
$this->assertSame('<link href="/system/assets/whoops.css" type="text/css" rel="stylesheet" />' . PHP_EOL .
|
||||
'<link href="/test.css" type="text/css" rel="stylesheet" />' . PHP_EOL, $css);
|
||||
$this->assertSame('<link href="/system/assets/whoops.css" type="text/css" rel="stylesheet" async>' . PHP_EOL .
|
||||
'<link href="/test.css" type="text/css" rel="stylesheet" async>' . PHP_EOL, $css);
|
||||
}
|
||||
|
||||
public function testPriorityOfAssets()
|
||||
@@ -312,8 +484,8 @@ class AssetsTest extends \Codeception\TestCase\Test
|
||||
$this->assets->add('test-after.css');
|
||||
|
||||
$css = $this->assets->css();
|
||||
$this->assertSame('<link href="/test.css" type="text/css" rel="stylesheet" />' . PHP_EOL .
|
||||
'<link href="/test-after.css" type="text/css" rel="stylesheet" />' . PHP_EOL, $css);
|
||||
$this->assertSame('<link href="/test.css" type="text/css" rel="stylesheet">' . PHP_EOL .
|
||||
'<link href="/test-after.css" type="text/css" rel="stylesheet">' . PHP_EOL, $css);
|
||||
|
||||
//----------------
|
||||
$this->assets->reset();
|
||||
@@ -321,8 +493,8 @@ class AssetsTest extends \Codeception\TestCase\Test
|
||||
$this->assets->add('test.css', 2);
|
||||
|
||||
$css = $this->assets->css();
|
||||
$this->assertSame('<link href="/test.css" type="text/css" rel="stylesheet" />' . PHP_EOL .
|
||||
'<link href="/test-after.css" type="text/css" rel="stylesheet" />' . PHP_EOL, $css);
|
||||
$this->assertSame('<link href="/test.css" type="text/css" rel="stylesheet">' . PHP_EOL .
|
||||
'<link href="/test-after.css" type="text/css" rel="stylesheet">' . PHP_EOL, $css);
|
||||
|
||||
//----------------
|
||||
$this->assets->reset();
|
||||
@@ -331,9 +503,9 @@ class AssetsTest extends \Codeception\TestCase\Test
|
||||
$this->assets->add('test-before.css', 3);
|
||||
|
||||
$css = $this->assets->css();
|
||||
$this->assertSame('<link href="/test-before.css" type="text/css" rel="stylesheet" />' . PHP_EOL .
|
||||
'<link href="/test.css" type="text/css" rel="stylesheet" />' . PHP_EOL .
|
||||
'<link href="/test-after.css" type="text/css" rel="stylesheet" />' . PHP_EOL, $css);
|
||||
$this->assertSame('<link href="/test-before.css" type="text/css" rel="stylesheet">' . PHP_EOL .
|
||||
'<link href="/test.css" type="text/css" rel="stylesheet">' . PHP_EOL .
|
||||
'<link href="/test-after.css" type="text/css" rel="stylesheet">' . PHP_EOL, $css);
|
||||
}
|
||||
|
||||
public function testPipeline()
|
||||
@@ -344,37 +516,53 @@ class AssetsTest extends \Codeception\TestCase\Test
|
||||
$this->assets->add('test.css', null, true);
|
||||
$this->assets->setCssPipeline(true);
|
||||
$css = $this->assets->css();
|
||||
$this->assertSame('', $css);
|
||||
$this->assertRegExp('#<link href=\"\/assets\/(.*).css\" type=\"text\/css\" rel=\"stylesheet\">#', $css);
|
||||
|
||||
//Add a core Grav CSS file, which is found. Pipeline will now return a file
|
||||
$this->assets->add('/system/assets/debugger.css', null, true);
|
||||
$css = $this->assets->css();
|
||||
$this->assertContains('<link href=', $css);
|
||||
$this->assertContains('type="text/css" rel="stylesheet" />', $css);
|
||||
$this->assertRegExp('#<link href=\"\/assets\/(.*).css\" type=\"text\/css\" rel=\"stylesheet\">#', $css);
|
||||
}
|
||||
|
||||
public function testPipelineWithTimestamp()
|
||||
{
|
||||
$this->assets->reset();
|
||||
$this->assets->setTimestamp('foo');
|
||||
$this->assets->setCssPipeline(true);
|
||||
|
||||
//Add a core Grav CSS file, which is found. Pipeline will now return a file
|
||||
$this->assets->add('/system/assets/debugger.css', null, true);
|
||||
$css = $this->assets->css();
|
||||
$this->assertContains('<link href=', $css);
|
||||
$this->assertContains('type="text/css" rel="stylesheet" />', $css);
|
||||
$this->assertContains($this->assets->getTimestamp(), $css);
|
||||
$this->assertRegExp('#<link href=\"\/assets\/(.*).css\?foo\" type=\"text\/css\" rel=\"stylesheet\">#', $css);
|
||||
}
|
||||
|
||||
public function testInline()
|
||||
{
|
||||
$this->assets->reset();
|
||||
|
||||
//File not existing. Pipeline searches for that file without reaching it. Output is empty.
|
||||
$this->assets->add('test.css', ['loading' => 'inline']);
|
||||
$css = $this->assets->css();
|
||||
$this->assertSame("<style>\n\n</style>\n", $css);
|
||||
|
||||
$this->assets->reset();
|
||||
//Add a core Grav CSS file, which is found. Pipeline will now return its content.
|
||||
$this->assets->addCss('https://fonts.googleapis.com/css?family=Roboto', ['loading' => 'inline']);
|
||||
$this->assets->addCss('/system/assets/debugger.css', ['loading' => 'inline']);
|
||||
$css = $this->assets->css();
|
||||
$this->assertContains('font-family: \'Roboto\';', $css);
|
||||
$this->assertContains('div.phpdebugbar-header', $css);
|
||||
}
|
||||
|
||||
public function testInlinePipeline()
|
||||
{
|
||||
$this->assets->reset();
|
||||
$this->assets->setCssPipeline(true);
|
||||
|
||||
//File not existing. Pipeline searches for that file without reaching it. Output is empty.
|
||||
$this->assets->add('test.css', null, true);
|
||||
$this->assets->setCssPipeline(true);
|
||||
$this->assets->add('test.css');
|
||||
$css = $this->assets->css('head', ['loading' => 'inline']);
|
||||
$this->assertSame('', $css);
|
||||
$this->assertSame("<style>\n\n</style>\n", $css);
|
||||
|
||||
//Add a core Grav CSS file, which is found. Pipeline will now return its content.
|
||||
$this->assets->addCss('https://fonts.googleapis.com/css?family=Roboto', null, true);
|
||||
@@ -407,56 +595,56 @@ class AssetsTest extends \Codeception\TestCase\Test
|
||||
$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);
|
||||
$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);
|
||||
$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?foo" type="text/css" rel="stylesheet" />' . PHP_EOL, $css);
|
||||
$this->assertSame('<link href="http://somesite.com/test.css?foo" 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&foo" type="text/css" rel="stylesheet" />' . PHP_EOL, $css);
|
||||
$this->assertSame('<link href="http://somesite.com/test.css?bar&foo" 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" ></script>' . PHP_EOL, $css);
|
||||
$this->assertSame('<script src="/test.js?foo"></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" ></script>' . PHP_EOL, $css);
|
||||
$this->assertSame('<script src="/test.js?bar&foo"></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?foo" ></script>' . PHP_EOL, $css);
|
||||
$this->assertSame('<script src="http://somesite.com/test.js?foo"></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&foo" ></script>' . PHP_EOL, $css);
|
||||
$this->assertSame('<script src="http://somesite.com/test.js?bar&foo"></script>' . PHP_EOL, $css);
|
||||
}
|
||||
|
||||
public function testAddInlineCss()
|
||||
@@ -464,7 +652,7 @@ class AssetsTest extends \Codeception\TestCase\Test
|
||||
$this->assets->reset();
|
||||
$this->assets->addInlineCss('body { color: black }');
|
||||
$css = $this->assets->css();
|
||||
$this->assertSame(PHP_EOL . '<style>' . PHP_EOL . 'body { color: black }' . PHP_EOL . PHP_EOL . '</style>' . PHP_EOL, $css);
|
||||
$this->assertSame('<style>' . PHP_EOL . 'body { color: black }' . PHP_EOL . '</style>' . PHP_EOL, $css);
|
||||
}
|
||||
|
||||
public function testAddInlineJs()
|
||||
@@ -472,7 +660,7 @@ class AssetsTest extends \Codeception\TestCase\Test
|
||||
$this->assets->reset();
|
||||
$this->assets->addInlineJs('alert("test")');
|
||||
$js = $this->assets->js();
|
||||
$this->assertSame(PHP_EOL . '<script>' . PHP_EOL . 'alert("test")' . PHP_EOL . PHP_EOL . '</script>' . PHP_EOL, $js);
|
||||
$this->assertSame('<script>' . PHP_EOL . 'alert("test")' . PHP_EOL . '</script>' . PHP_EOL, $js);
|
||||
}
|
||||
|
||||
public function testGetCollections()
|
||||
@@ -499,49 +687,41 @@ class AssetsTest extends \Codeception\TestCase\Test
|
||||
{
|
||||
$this->assets->addInlineJs('alert("test")');
|
||||
$this->assets->reset();
|
||||
$this->assertCount(0, (array) $this->assets->js());
|
||||
$this->assertCount(0, (array) $this->assets->getJs());
|
||||
|
||||
$this->assets->addAsyncJs('jquery');
|
||||
$this->assets->reset();
|
||||
|
||||
$this->assertCount(0, (array) $this->assets->js());
|
||||
$this->assertCount(0, (array) $this->assets->getJs());
|
||||
|
||||
$this->assets->addInlineCss('body { color: black }');
|
||||
$this->assets->reset();
|
||||
|
||||
$this->assertCount(0, (array) $this->assets->css());
|
||||
$this->assertCount(0, (array) $this->assets->getCss());
|
||||
|
||||
$this->assets->add('/system/assets/debugger.css', null, true);
|
||||
$this->assets->reset();
|
||||
|
||||
$this->assertCount(0, (array) $this->assets->css());
|
||||
$this->assertCount(0, (array) $this->assets->getCss());
|
||||
}
|
||||
|
||||
public function testResetJs()
|
||||
{
|
||||
$this->assets->addInlineJs('alert("test")');
|
||||
$this->assets->resetJs();
|
||||
$this->assertCount(0, (array) $this->assets->js());
|
||||
$this->assertCount(0, (array) $this->assets->getJs());
|
||||
|
||||
$this->assets->addAsyncJs('jquery');
|
||||
$this->assets->resetJs();
|
||||
|
||||
$this->assertCount(0, (array) $this->assets->js());
|
||||
$this->assertCount(0, (array) $this->assets->getJs());
|
||||
}
|
||||
|
||||
public function testResetCss()
|
||||
{
|
||||
$this->assertCount(0, (array) $this->assets->js());
|
||||
|
||||
$this->assets->addInlineCss('body { color: black }');
|
||||
$this->assets->resetCss();
|
||||
|
||||
$this->assertCount(0, (array) $this->assets->css());
|
||||
$this->assertCount(0, (array) $this->assets->getCss());
|
||||
|
||||
$this->assets->add('/system/assets/debugger.css', null, true);
|
||||
$this->assets->resetCss();
|
||||
|
||||
$this->assertCount(0, (array) $this->assets->css());
|
||||
$this->assertCount(0, (array) $this->assets->getCss());
|
||||
}
|
||||
|
||||
public function testAddDirCss()
|
||||
|
||||
Reference in New Issue
Block a user