diff --git a/core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php b/core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php index 3eaf553..54eed4f 100644 --- a/core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php +++ b/core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php @@ -130,9 +130,10 @@ public function buildByExtension($extension) { // and only once prior to rendering out an HTML page. if ($type == 'css' && !empty($library[$type])) { foreach ($library[$type] as $category => $files) { - $category_weight = 'CSS_' . strtoupper($category); - assert('defined($category_weight)', 'Invalid CSS category: ' . $category . '. See https://www.drupal.org/node/2274843.'); foreach ($files as $source => $options) { + assert('is_array($options)', 'CSS must be nested under a category. See https://www.drupal.org/node/2274843.'); + $category_weight = 'CSS_' . strtoupper($category); + assert('defined($category_weight)', 'Invalid CSS category: ' . $category . '. See https://www.drupal.org/node/2274843.'); if (!isset($options['weight'])) { $options['weight'] = 0; } diff --git a/core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryParserTest.php b/core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryParserTest.php index c977d39..e18b0ae 100644 --- a/core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryParserTest.php +++ b/core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryParserTest.php @@ -534,10 +534,10 @@ public function testLibraryWithLicenses() { } /** - * Verify an assertion fails if CSS declarations aren't properly nested. + * Verify an assertion fails if CSS declarations have non-existent categories. * * @expectedException \AssertionError - * @expectedExceptionMessage Invalid CSS category: css/styles.css. See https://www.drupal.org/node/2274843. + * @expectedExceptionMessage Invalid CSS category: bad_category. See https://www.drupal.org/node/2274843. */ public function testCssCategoryAssert() { $this->moduleHandler->expects($this->atLeastOnce()) @@ -554,6 +554,27 @@ public function testCssCategoryAssert() { $this->libraryDiscoveryParser->buildByExtension('css_bad_category'); } + /** + * Verify an assertion fails if CSS declarations aren't properly nested. + * + * @expectedException \AssertionError + * @expectedExceptionMessage CSS must be nested under a category. See https://www.drupal.org/node/2274843. + */ + public function testCssNestingAssert() { + $this->moduleHandler->expects($this->atLeastOnce()) + ->method('moduleExists') + ->with('css_bad_nesting') + ->will($this->returnValue(TRUE)); + + $path = __DIR__ . '/library_test_files'; + $path = substr($path, strlen($this->root) + 1); + $this->libraryDiscoveryParser->setPaths('module', 'css_bad_nesting', $path); + + // This will fail since the CSS declaration isn't properly nested under + // a category. + $this->libraryDiscoveryParser->buildByExtension('css_bad_nesting'); + } + } /** diff --git a/core/tests/Drupal/Tests/Core/Asset/library_test_files/css_bad_category.libraries.yml b/core/tests/Drupal/Tests/Core/Asset/library_test_files/css_bad_category.libraries.yml index 5a76a30..803efc3 100644 --- a/core/tests/Drupal/Tests/Core/Asset/library_test_files/css_bad_category.libraries.yml +++ b/core/tests/Drupal/Tests/Core/Asset/library_test_files/css_bad_category.libraries.yml @@ -1,4 +1,5 @@ bad_category: css: - # No nesting here will break. - css/styles.css: { minified: true } + # Non-existent category. + bad_category: + css/styles.css: { minified: true } diff --git a/core/tests/Drupal/Tests/Core/Asset/library_test_files/css_bad_nesting.libraries.yml b/core/tests/Drupal/Tests/Core/Asset/library_test_files/css_bad_nesting.libraries.yml new file mode 100644 index 0000000..44c9c0e --- /dev/null +++ b/core/tests/Drupal/Tests/Core/Asset/library_test_files/css_bad_nesting.libraries.yml @@ -0,0 +1,4 @@ +bad_nesting: + css: + # No nesting here will break. + css/styles.css: { minified: true }