diff --git a/tests/unit/Grav/Common/AssetsTest.php b/tests/unit/Grav/Common/AssetsTest.php
index 747c8ed51..aea7be291 100644
--- a/tests/unit/Grav/Common/AssetsTest.php
+++ b/tests/unit/Grav/Common/AssetsTest.php
@@ -473,6 +473,59 @@ class AssetsTest extends \Codeception\TestCase\Test
'' . 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 = [
+ '',
+ '',
+ '',
+ ];
+
+ 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 = [
+ '',
+ '',
+ '',
+ ];
+
+ 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 = [
+ '',
+ ];
+
+
+ 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")');