mirror of
https://github.com/getgrav/grav.git
synced 2025-02-20 19:56:53 +01:00
Added tests for new params support in collections (#3358)
This commit is contained in:
parent
f1c623c14b
commit
acf8724402
|
|
@ -473,6 +473,59 @@ class AssetsTest extends \Codeception\TestCase\Test
|
|||
'<link href="/test.css" type="text/css" rel="stylesheet" async>' . PHP_EOL, $css);
|
||||
}
|
||||
|
||||
public function testAddingAssetPropertiesWithArrayFromCollectionAndParameters(): void
|
||||
{
|
||||
$this->assets->registerCollection('collection_multi_params', [
|
||||
'foo.js' => [ 'defer' => true ],
|
||||
'bar.js' => [ 'integrity' => 'sha512-abc123' ],
|
||||
'foobar.css' => [ 'defer' => null, 'loading' => null ]
|
||||
]);
|
||||
|
||||
// # Test adding properties with array
|
||||
$this->assets->addJs('collection_multi_params', ['loading' => 'async']);
|
||||
$js = $this->assets->js();
|
||||
|
||||
// expected output
|
||||
$expected = [
|
||||
'<script src="/foo.js" async defer="1"></script>',
|
||||
'<script src="/bar.js" async integrity="sha512-abc123"></script>',
|
||||
'<script src="/foobar.css"></script>',
|
||||
];
|
||||
|
||||
self::assertCount(count($expected), array_filter(explode("\n", $js)));
|
||||
self::assertSame(implode("\n", $expected) . PHP_EOL, $js);
|
||||
|
||||
// # Test priority as second argument + render JS should not have any css
|
||||
$this->assets->reset();
|
||||
$this->assets->add('low_priority.js', 1);
|
||||
$this->assets->add('collection_multi_params', 2);
|
||||
$js = $this->assets->js();
|
||||
|
||||
// expected output
|
||||
$expected = [
|
||||
'<script src="/foo.js" defer="1"></script>',
|
||||
'<script src="/bar.js" integrity="sha512-abc123"></script>',
|
||||
'<script src="/low_priority.js"></script>',
|
||||
];
|
||||
|
||||
self::assertCount(3, array_filter(explode("\n", $js)));
|
||||
self::assertSame(implode("\n", $expected) . PHP_EOL, $js);
|
||||
|
||||
// # Test rendering CSS, should not have any JS
|
||||
$this->assets->reset();
|
||||
$this->assets->add('collection_multi_params', [ 'class' => '__classname' ]);
|
||||
$css = $this->assets->css();
|
||||
|
||||
// expected output
|
||||
$expected = [
|
||||
'<link href="/foobar.css" type="text/css" rel="stylesheet" class="__classname">',
|
||||
];
|
||||
|
||||
|
||||
self::assertCount(1, array_filter(explode("\n", $css)));
|
||||
self::assertSame(implode("\n", $expected) . PHP_EOL, $css);
|
||||
}
|
||||
|
||||
public function testPriorityOfAssets(): void
|
||||
{
|
||||
$this->assets->reset();
|
||||
|
|
@ -679,6 +732,27 @@ class AssetsTest extends \Codeception\TestCase\Test
|
|||
self::assertContains('debugger', array_keys($this->assets->getCollections()));
|
||||
}
|
||||
|
||||
public function testRegisterCollectionWithParameters(): void
|
||||
{
|
||||
$this->assets->registerCollection('collection_multi_params', [
|
||||
'foo.js' => [ 'defer' => true ],
|
||||
'bar.js' => [ 'integrity' => 'sha512-abc123' ],
|
||||
'foobar.css' => [ 'defer' => null ],
|
||||
]);
|
||||
|
||||
self::assertTrue($this->assets->exists('collection_multi_params'));
|
||||
|
||||
$collection = $this->assets->getCollections()['collection_multi_params'];
|
||||
self::assertArrayHasKey('foo.js', $collection);
|
||||
self::assertArrayHasKey('bar.js', $collection);
|
||||
self::assertArrayHasKey('foobar.css', $collection);
|
||||
self::assertArrayHasKey('defer', $collection['foo.js']);
|
||||
self::assertArrayHasKey('defer', $collection['foobar.css']);
|
||||
|
||||
self::assertNull($collection['foobar.css']['defer']);
|
||||
self::assertTrue($collection['foo.js']['defer']);
|
||||
}
|
||||
|
||||
public function testReset(): void
|
||||
{
|
||||
$this->assets->addInlineJs('alert("test")');
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user