diff --git a/core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryParserTest.php b/core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryParserTest.php index 422eb0b..9df801e 100644 --- a/core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryParserTest.php +++ b/core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryParserTest.php @@ -503,60 +503,49 @@ public function testLibraryWithLicenses() { } /** - * Verify an assertion fails if CSS declarations have non-existent categories. + * Verifies assertions catch invalid CSS declarations. + * + * @dataProvider providerTestCssAssert */ - public function testCssCategoryAssert() { - $this->moduleHandler->expects($this->atLeastOnce()) - ->method('moduleExists') - ->with('css_bad_category') - ->will($this->returnValue(TRUE)); - - $path = __DIR__ . '/library_test_files'; - $path = substr($path, strlen($this->root) + 1); - $this->libraryDiscoveryParser->setPaths('module', 'css_bad_category', $path); - - // This will fail since the CSS declaration isn't properly nested under - // a category. - $this->setExpectedException(\AssertionError::class, 'Invalid CSS category: bad_category. See https://www.drupal.org/node/2274843.'); - $this->libraryDiscoveryParser->buildByExtension('css_bad_category'); - } /** - * Verify an assertion fails if CSS declarations aren't properly nested. + * Verify an assertion fails if CSS declarations have non-existent categories. + * + * @param string $extension + * The css extension to build. + * @param string $exception_message + * The expected exception message. + * + * @dataProvider providerTestCssAssert */ - public function testCssNestingAssert() { + public function testCssAssert($extension, $exception_message) { $this->moduleHandler->expects($this->atLeastOnce()) ->method('moduleExists') - ->with('css_bad_nesting') + ->with($extension) ->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->libraryDiscoveryParser->setPaths('module', $extension, $path); - // This will fail since the CSS declaration isn't properly nested under - // a category. - $this->setExpectedException(\AssertionError::class, 'CSS must be nested under a category. See https://www.drupal.org/node/2274843.'); - $this->libraryDiscoveryParser->buildByExtension('css_bad_nesting'); + $this->setExpectedException(\AssertionError::class, $exception_message); + $this->libraryDiscoveryParser->buildByExtension($extension); } /** - * Verify an assertion fails if CSS declarations are a simple array of files. + * Data provider for testing bad CSS declarations. */ - public function testCssNestingArrayAssert() { - $this->moduleHandler->expects($this->atLeastOnce()) - ->method('moduleExists') - ->with('css_bad_nesting_array') - ->will($this->returnValue(TRUE)); + public function providerTestCssAssert() { + return [ + // Invalid category. + ['css_bad_category', 'Invalid CSS category: bad_category. See https://www.drupal.org/node/2274843.'] , - $path = __DIR__ . '/library_test_files'; - $path = substr($path, strlen($this->root) + 1); - $this->libraryDiscoveryParser->setPaths('module', 'css_bad_nesting_array', $path); + // Improper CSS nesting. + ['css_bad_nesting', 'CSS must be nested under a category. See https://www.drupal.org/node/2274843.'], - // This will fail since the CSS declaration isn't properly nested under - // a category. - $this->setExpectedException(\AssertionError::class, 'CSS files should be specified as key/value pairs, where the values are configuration options. See https://www.drupal.org/node/2274843.'); - $this->libraryDiscoveryParser->buildByExtension('css_bad_nesting_array'); + // Improper nesting with bad key value pairs. + ['css_bad_nesting_array', 'CSS files should be specified as key/value pairs, where the values are configuration options. See https://www.drupal.org/node/2274843.'], + ]; } } diff --git a/core/tests/Drupal/Tests/Core/Asset/library_test_files/css_bad_nesting_array.libraries.yml b/core/tests/Drupal/Tests/Core/Asset/library_test_files/css_bad_nesting_array.libraries.yml index db028d9..3c59bc7 100644 --- a/core/tests/Drupal/Tests/Core/Asset/library_test_files/css_bad_nesting_array.libraries.yml +++ b/core/tests/Drupal/Tests/Core/Asset/library_test_files/css_bad_nesting_array.libraries.yml @@ -1,4 +1,4 @@ bad_nesting_array: css: - # Specified as an array will break. + # Specified as an array will break. - css/styles.css diff --git a/core/tests/Drupal/Tests/Core/Asset/library_test_files/dependencies.libraries.yml b/core/tests/Drupal/Tests/Core/Asset/library_test_files/dependencies.libraries.yml index 068a9a3..169d2f4 100644 --- a/core/tests/Drupal/Tests/Core/Asset/library_test_files/dependencies.libraries.yml +++ b/core/tests/Drupal/Tests/Core/Asset/library_test_files/dependencies.libraries.yml @@ -1,7 +1,7 @@ example: css: theme: - css/example.js: {} + css/example.css: {} dependencies: - external/example_external - example_module/example