Problem/Motivation

As stated in #3050389: [META] Remove dependency to Classy from core themes, Classy will be moved to contrib before Drupal 9 and we have to remove dependencies on Classy from all core themes.

Part of this process includes creating theme-specific copies of all Classy libraries to core themes. This ensures Classy can be removed without impacting those themes.

Because this is the first of several issues for copying a Classy library to Umami, there are no tests for this yet.

Also because this is the first of several similar issues, this will also be used to collect feedback about the process and naming conventions, with the goal of making the additional issues as easy as possible to patch and review.

Proposed resolution

  • Make an Umami-specific copy of classy/dropbutton This includes:
    • The library should be called classy.dropbutton, using the classy. prefix to make it clear that it is copied from Classy, not custom to Umami
    • Umami should extend core/drupal.dropbuttonso the end result behaves identically to Classy's extending of the library.
    • The CSS file will be located in css/classy/components. As a rule, copied assets from Classy should go in a classy subdirectory of that asset type, but otherwise maintain the directory structure from classy (such as going in a components or theme directory)
  • Add a test class that confirms the copy is successful, and build it so it is easily capable of testing other libraries when they are copied to a theme that previously depended on the Classy library.
  • Manually test in Umami by comparing elements that use the dropbutton css before-patch and after-patch, and provide screenshots.

Remaining tasks

Currently all the steps above.

User interface changes

no

API changes

no

Data model changes

no

Release notes snippet

...

CommentFileSizeAuthor
#42 3096203-42.patch23.43 KBbnjmnm
#42 interdiff_40-42.txt3.13 KBbnjmnm
#40 3096203-40.patch23.42 KBbnjmnm
#40 interdiff_38-40.txt729 bytesbnjmnm
#38 3096203-38.patch23.56 KBbnjmnm
#38 interdiff_36-38.txt8.19 KBbnjmnm
#36 3096203-36.patch23.09 KBbnjmnm
#36 interdiff_20-36.txt16.98 KBbnjmnm
#20 3096203-20.patch20.61 KBbnjmnm
#20 interdiff_14-20.txt26.69 KBbnjmnm
#20 3096203-20-theme-is-extending-with-classy-library-FAIL.patch23.1 KBbnjmnm
#20 3096203-20-core-lib-override-has-classy-asset-FAIL.patch23.53 KBbnjmnm
#20 3096203-20-incorrectly-override-core-lib-with-classy-lib-FAIL.patch23.3 KBbnjmnm
#20 3096203-20-classy-extends-corelib-but-theme-does-not-FAIL.patch22.92 KBbnjmnm
#20 3096203-20-incomplete-asset-copy-FAIL.patch22.92 KBbnjmnm
#20 3096203-20-asset-properties-dont-match-FAIL.patch22.92 KBbnjmnm
#20 3096203-20-missing-copied-library-FAIL.patch22.92 KBbnjmnm
#20 3096203-20-missing-equivalent-file-FAIL.patch22.92 KBbnjmnm
#20 3096203-20-missing-library-override-FAIL.patch22.92 KBbnjmnm
#14 3096203-14.patch17.85 KBbnjmnm
#14 interdiff_12-14.txt7.23 KBbnjmnm
#12 3096203-12.patch15.44 KBbnjmnm
#12 interdiff_9-12.txt485 bytesbnjmnm
#9 3096203-9.patch15.43 KBbnjmnm
#9 interdiff_3-9.txt2.26 KBbnjmnm
#9 3096203-9-test-for-missing-override-FAIL.patch15.27 KBbnjmnm
#3 3096203-3.patch14.93 KBbnjmnm
#3 interdiff_2-3.txt20.29 KBbnjmnm
#2 dropbutton-after-open.png35.03 KBbnjmnm
#2 dropbutton-after-closed-withPath.png123.86 KBbnjmnm
#2 dropbutton-before-open.png6.52 KBbnjmnm
#2 dropbutton-before-closed-withPath.png82.89 KBbnjmnm
#2 3096203-2.patch9.53 KBbnjmnm
#2 3096203-2-no-replacement-library-FAIL.patch11.77 KBbnjmnm
#2 3096203-2-file-not-present-FAIL.patch11.8 KBbnjmnm
#2 3096203-2-missing-equivalent-file-FAIL.patch11.81 KBbnjmnm
#2 3096203-2-missing-library-extend-FAIL.patch11.78 KBbnjmnm

Comments

bnjmnm created an issue. See original summary.

bnjmnm’s picture

This patch creates an Umami equivalent of classy/dropbutton.
Screenshots of manual testing:
Before

After

This also adds a test that can be used for all additional issues for copying other Classy libraries to Umami. For each libraries' issue, the library will be removed from the $librariesToSkip array. Several intended-to-fail patches are attached to demonstrate the various copying errors that are checked for.

bnjmnm’s picture

Title: Remove Umami theme dependency on classy/dropbutton + add tests. » Create Classy library dependency tests that can be used for all themes, and verify by providing an Umami-specific classy/dropbutton
Issue summary: View changes
StatusFileSize
new20.29 KB
new14.93 KB

Refactored the test to work with all core themes. As issues are opened to copy additional libraries, those libraries are removed from the "skip" array for that theme.

Also added checks in the test to confirm that if a Classy library is overridden, all CSS/JS files are accounted for.

The last submitted patch, 2: 3096203-2-missing-equivalent-file-FAIL.patch, failed testing. View results

The last submitted patch, 2: 3096203-2-no-replacement-library-FAIL.patch, failed testing. View results

The last submitted patch, 2: 3096203-2-file-not-present-FAIL.patch, failed testing. View results

The last submitted patch, 2: 3096203-2-missing-library-extend-FAIL.patch, failed testing. View results

lauriii’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll
+++ b/core/profiles/demo_umami/themes/umami/umami.info.yml
@@ -16,6 +16,8 @@ libraries-override:
+  core/drupal.dropbutton:
+    - umami/classy.dropbutton

Should we also add a library override to unload the library from Classy? If we don't unload the Classy library, we would have two versions of the CSS loaded until we have removed dependency to Classy.

bnjmnm’s picture

Status: Needs work » Needs review
Issue tags: -Drupal 9 compatibility, -Needs reroll +Drupal 9
StatusFileSize
new15.27 KB
new2.26 KB
new15.43 KB

From #8

Should we also add a library override to unload the library from Classy? If we don't unload the Classy library, we would have two versions of the CSS loaded until we have removed dependency to Classy.

Good catch. That step has been added to the test coverage with a failing patch to prove it, along with a version that properly overrides the library.

The last submitted patch, 9: 3096203-9-test-for-missing-override-FAIL.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 9: 3096203-9.patch, failed testing. View results

bnjmnm’s picture

Status: Needs work » Needs review
StatusFileSize
new485 bytes
new15.44 KB

Addresses the test failures in #9 by setting the libraries-override to the Umami library instead of FALSE.

lauriii’s picture

Status: Needs review » Needs work
  1. +++ b/core/tests/Drupal/KernelTests/Core/Theme/ThemeNotUsingClassyLibraryTest.php
    @@ -0,0 +1,329 @@
    +      // If the library override has a css key, it's some classy CSS is still
    

    Nit: s/css/CSS

  2. +++ b/core/tests/Drupal/KernelTests/Core/Theme/ThemeNotUsingClassyLibraryTest.php
    @@ -0,0 +1,329 @@
    +      if (in_array($classy_library_name, $libraries_to_skip) || isset($library_overrides_created_by_this_theme["classy/$classy_library_name"])) {
    ...
    +        $this->assertNotEmpty($theme_css_files);
    +        $this->assertEmpty(array_diff($theme_css_files, $classy_css_files), "Missing the inclusion of one or more CSS files from classy/$classy_library_name.");
    ...
    +        $this->assertNotEmpty($theme_js_files);
    +        $this->assertEmpty(array_diff($theme_js_files, $classy_js_files), "Missing the inclusion of one or more JS files from classy/$classy_library_name.");
    

    These assertions are never run given that we skip this if the library has been overridden.

  3. +++ b/core/tests/Drupal/KernelTests/Core/Theme/ThemeNotUsingClassyLibraryTest.php
    @@ -0,0 +1,329 @@
    +      // Confirm there is a theme-specific version of the Classy library.
    +      $this->assertArrayHasKey("classy.$classy_library_name", $this_theme_libraries, "There is not a $theme equivalent for classy/$classy_library_name");
    

    This seems redundant given that we never run this assert if the library has been overridden 🤔

  4. +++ b/core/tests/Drupal/KernelTests/Core/Theme/ThemeNotUsingClassyLibraryTest.php
    @@ -0,0 +1,329 @@
    +      // that should be extended instead of overridden.
    ...
    +      $this->assertTrue(($extends_core_library || $overrides_core_library), "$library_extended is extended by Classy and should be extended or overridden by $theme");
    ...
    +        // Libraries-extend to skip in test.
    

    Should we add more specific assertions for this scenario?

bnjmnm’s picture

Status: Needs work » Needs review
StatusFileSize
new7.23 KB
new17.85 KB

This addresses all the points in #14. The feedback made it apparent that there was a better way to check for Classy libraries already fully-overridden by a theme. This means I was able to remove a few more libraries from the skip-lists as they are already entirely overridden in the Classy inheriting themes.

lauriii’s picture

Status: Needs review » Reviewed & tested by the community

I tested manually various use cases to ensure that the tests fail when libraries are not sufficiently overridden. I tried missing override on a library that was extended, as well as libraries with both CSS and JavaScript dependencies. Looks good to me! 🚀

xjm’s picture

Thanks for all the excellent test patches exposing the specific fails!

Reviewed so far by:

  • Copying core/themes/classy/css/components/dropbutton.css to core/profiles/demo_umami/themes/umami/css/classy/components/ with the patch applied to verify that the files are identical.
  • Checking the diffs between the exposed fail patches in #2 and the full patches -- the relevant bits are:
    • Missing library extension:
      +++ b/core/profiles/demo_umami/themes/umami/umami.info.yml
      @@ -15,8 +15,8 @@ libraries-override:
       libraries-extend:
         tour/tour-styling:
           - umami/demo-umami-tour
      -  core/drupal.dropbutton:
      -    - umami/classy.dropbutton
      +#  core/drupal.dropbutton:
      +#    - umami/classy.dropbutton
       

      Failure message

      1) Drupal\KernelTests\Core\Theme\UmamiClassyLibraryTest::testUmamiCopiesOfClassyLibraries
      Umami should override or extend classy/dropbutton.
      Failed asserting that an array has the key 'classy/dropbutton'.
      
    • Missing equivalent file:
           component:
      -      css/classy/components/dropbutton.css: { weight: -10 }
      +      css/classy/components/dropbutton-different.css: { weight: -10 }
      diff --git a/core/tests/Drupal/KernelTests/Core/Theme/UmamiClassyLibraryTest.php b/core/tests/Drupal/KernelTests/Core/Theme/UmamiClassyLibraryTest.php
      index b68e0414cf..9699a7116c 100644
      --- a/core/tests/Drupal/KernelTests/Core/Theme/UmamiClassyLibraryTest.php
      +++ b/core/tests/Drupal/KernelTests/Core/Theme/UmamiClassyLibraryTest.php
      @@ -175,7 +175,7 @@ public function testUmamiCopiesOfClassyLibraries() {
               continue;
             }
       
      -      $this->assertArrayHasKey("classy/$classy_library_name", $umami_library_overrides, "Umami should override or extend classy/$classy_library_name.");
      +      $this->assertArrayHasKey("classy/$classy_library_name", $umami_library_overrides, "Umami should override classy/$classy_library_name.");
             $this->assertEmpty($umami_library_overrides["classy/$classy_library_name"], "Umami's override for classy/$classy_library_name should be empty.");
           }
      

      Failure message:

      1) Drupal\KernelTests\Core\Theme\UmamiClassyLibraryTest::testUmamiCopiesOfClassyLibraries
      Missing the inclusion of one or more CSS files from classy/dropbutton.
      Failed asserting that an array is empty.
    • File not present:
      rename from core/profiles/demo_umami/themes/umami/css/classy/components/dropbutton.css
      rename to core/profiles/demo_umami/themes/umami/css/classy/components/dropbutton-different.css
      diff --git a/core/tests/Drupal/KernelTests/Core/Theme/UmamiClassyLibraryTest.php b/core/tests/Drupal/KernelTests/Core/Theme/UmamiClassyLibraryTest.php
      index b68e0414cf..9699a7116c 100644
      --- a/core/tests/Drupal/KernelTests/Core/Theme/UmamiClassyLibraryTest.php
      +++ b/core/tests/Drupal/KernelTests/Core/Theme/UmamiClassyLibraryTest.php
      @@ -175,7 +175,7 @@ public function testUmamiCopiesOfClassyLibraries() {
               continue;
             }
       
      -      $this->assertArrayHasKey("classy/$classy_library_name", $umami_library_overrides, "Umami should override or extend classy/$classy_library_name.");
      +      $this->assertArrayHasKey("classy/$classy_library_name", $umami_library_overrides, "Umami should override classy/$classy_library_name.");
             $this->assertEmpty($umami_library_overrides["classy/$classy_library_name"], "Umami's override for classy/$classy_library_name should be empty.");
           }
      

      Failure message:

      1) Drupal\KernelTests\Core\Theme\UmamiClassyLibraryTest::testUmamiCopiesOfClassyLibraries
      File core/profiles/demo_umami/themes/umami/css/classy/components/dropbutton.css does not exist.
      Failed asserting that file "/var/www/html/core/profiles/demo_umami/themes/umami/css/classy/components/dropbutton.css" exists.
      
    • No replacement library:
      +#classy.dropbutton:
      +#  version: VERSION
      +#  css:
      +#    component:
      +#      css/classy/components/dropbutton.css: { weight: -10 }
      diff --git a/core/tests/Drupal/KernelTests/Core/Theme/UmamiClassyLibraryTest.php b/core/tests/Drupal/KernelTests/Core/Theme/UmamiClassyLibraryTest.php
      index b68e0414cf..9699a7116c 100644
      --- a/core/tests/Drupal/KernelTests/Core/Theme/UmamiClassyLibraryTest.php
      +++ b/core/tests/Drupal/KernelTests/Core/Theme/UmamiClassyLibraryTest.php
      @@ -175,7 +175,7 @@ public function testUmamiCopiesOfClassyLibraries() {
               continue;
             }
       
      -      $this->assertArrayHasKey("classy/$classy_library_name", $umami_library_overrides, "Umami should override or extend classy/$classy_library_name.");
      +      $this->assertArrayHasKey("classy/$classy_library_name", $umami_library_overrides, "Umami should override classy/$classy_library_name.");

      Failure message:

      1) Drupal\KernelTests\Core\Theme\UmamiClassyLibraryTest::testUmamiCopiesOfClassyLibraries
      There is not an Umami equivalent for classy/dropbutton
      Failed asserting that an array has the key 'classy.dropbutton'.
      

Next doing a line-by-line CR of the patch...

xjm’s picture

Started a code review. Overall this test is excellent and thorough. I got kind of lost in the reviewing the method so I think there's some potential to simplify it with refactoring. Haven't finished reviewing yet but here are my notes so far (didn't want to lose them):

  1. +++ b/core/profiles/demo_umami/themes/umami/umami.libraries.yml
    @@ -130,3 +130,9 @@ oneplusfourgrid_section:
    +      css/classy/components/dropbutton.css: { weight: -10 }
    

    Does the theme decoupling depend on this negative weight for the overridden library? If so, this would be important to document in both the decoupling instructions and the CR.

  2. +++ b/core/tests/Drupal/KernelTests/Core/Theme/ThemeNotUsingClassyLibraryTest.php
    @@ -0,0 +1,382 @@
    +  public function testThemeNotUsingClassyLibraries($theme, $libraries_to_skip, $extends_to_skip) {
    

    General obeservation: This test method is really long. Can we factor it into smaller helper methods or such?

    Also, should/could some of the initializations we use over and over that don't change be moved to setUp()?

  3. +++ b/core/tests/Drupal/KernelTests/Core/Theme/ThemeNotUsingClassyLibraryTest.php
    @@ -0,0 +1,382 @@
    +    $libraries_already_fully_overridden = [];
    

    Is the idea that we will update this variable as we complete the decoupling of each core library? So it'll eventually be a fairly long array?

    Does it mean libraries fully overridden for just one theme, or all core themes?

    I think we should add an inline comment explaining this array.

  4. +++ b/core/tests/Drupal/KernelTests/Core/Theme/ThemeNotUsingClassyLibraryTest.php
    @@ -0,0 +1,382 @@
    +    $library_overrides = $this->themeInitialization->getActiveThemeByName($theme)->getLibrariesOverride();
    +    $library_overrides_created_by_this_theme = isset($library_overrides[$theme_path]) ? $library_overrides[$theme_path] : [];
    

    So this is a bit confusing. (Needs followup for the documentation of getLibrariesOverride, which doesn't explain the return structure at all.) If these are already the library overrides for this theme, as per the previous line, why are we checking the top-level key of the array for the path of the theme?

    This could maybe use an inline comment.

    Also, $library_overrides isn't used again (except when it's re-initialized later in the method; see later point). Should we avoid the extra variable definition?

  5. +++ b/core/tests/Drupal/KernelTests/Core/Theme/ThemeNotUsingClassyLibraryTest.php
    @@ -0,0 +1,382 @@
    +    $this_theme_libraries = $this->libraryDiscovery->getLibrariesByExtension($theme);
    

    Nit about the variable naming: Doesn't $theme_ at the start of the variable name mean the theme name passed in at the start of the method? Do we need a $this_theme_ here? Otherwise it makes it seem like it's something different. Maybe we could use $this_theme_ everywhere?

  6. +++ b/core/tests/Drupal/KernelTests/Core/Theme/ThemeNotUsingClassyLibraryTest.php
    @@ -0,0 +1,382 @@
    +      if (in_array(str_replace('classy/', '', $library_name), $libraries_to_skip) || substr($library_name, 0, 7) !== 'classy/') {
    +        continue;
    +      }
    

    I had to read this time several times to figure out where it was going. So this line is going over the list of library overrides, and checking for whether they're either on the list of libraries to skip (which is passed into the method from the data provider), or whether it already has classy in its library name (which means... that it's already in the Classy subdirectory?... and then only proceeding if neither of those conditions are true.

    Could use an inline comment.

  7. +++ b/core/tests/Drupal/KernelTests/Core/Theme/ThemeNotUsingClassyLibraryTest.php
    @@ -0,0 +1,382 @@
    +    foreach ($classy_libraries as $classy_library_name => $classy_library) {
    +      if (in_array($classy_library_name, $libraries_to_skip) || in_array("classy/$classy_library_name", $libraries_already_fully_overridden)) {
    +        continue;
    +      }
    ...
    +      // This is looking specifically for overrides, so skip if it's a library
    +      // that should be extended instead of overridden.
    +      if (in_array($classy_library_name, $libraries_to_skip) || in_array($classy_library_name, array_values($this_themes_library_extendees))) {
    +        continue;
    +      }
    

    Didn't we already foreach this above with a different compound continue? I wonder if there's a way to simplify the method structure.

  8. +++ b/core/tests/Drupal/KernelTests/Core/Theme/ThemeNotUsingClassyLibraryTest.php
    @@ -0,0 +1,382 @@
    +    $library_overrides = $this->themeInitialization->getActiveThemeByName($theme)->getLibrariesOverride();
    +    $library_overrides_created_by_this_theme = isset($library_overrides[$theme_path]) ? $library_overrides[$theme_path] : [];
    

    Aren't these two lines already at the start of the method? Why are we overwriting them here?

    If they're overwritten but the same, we can delete these two lines and move the inline comment above them to the top of the method. If they're being overwritten and changing, that's a bit brittle and we should change it.

  9. Edit: Duplicate bullet.
xjm’s picture

Edit: Duplicate post.

xjm’s picture

Status: Reviewed & tested by the community » Needs work

@bnjmnm is working on a new patch, so updating issue status to reflect that.

bnjmnm’s picture

#17.1

Does the theme decoupling depend on this negative weight for the overridden library?

The test has been expanded to check that weights and other asset properties match when it's a library copied from Classy

#17.2-8

General obeservation: This test method is really long. Can we factor it into smaller helper methods or such?

That is a legit observation, it's unwieldy! I split this into two separate tests and several helper methods, and in doing so addressed the other feedback items. It should be easier to navigate now, although it's still a bit of a chungus.

Since this was a big refactor, I've provided failing tests for each major assertion in the tests.

3096203-20-theme-is-extending-with-classy-library-FAIL.patch

Error:

Drupal\KernelTests\Core\Theme\ThemeNotUsingClassyLibraryTest::testThemeAccountsForClassyExtensions with data set "umami" ('umami', array('user/drupal.user', 'core/drupal.dialog', 'file/drupal.file', 'core/drupal.progress', 'media/media_embed_ckeditor_theme', 'media_library/view', 'media_library/widget'))
umami is extending the core library: core/drupal.dropbutton with classy/dropbutton. Core libraries should not be extended with a Classy library.

Triggered by:

+++ b/core/profiles/demo_umami/themes/umami/umami.info.yml
@@ -28,6 +29,8 @@ libraries-override:
+    - classy/dropbutton

Extending a core module library with a Classy library

3096203-20-core-lib-override-has-classy-asset-FAIL.patch

Error:

Drupal\KernelTests\Core\Theme\ThemeNotUsingClassyLibraryTest::testThemeAccountsForClassyExtensions with data set "claro" ('claro', array('core/drupal.dialog', 'core/drupal.progress', 'media/media_embed_ckeditor_theme', 'media_library/view', 'media_library/widget'))
Override is loading a classy asset: /core/themes/classy/css/components/dropbutton.css

Triggered by:

+++ b/core/profiles/demo_umami/themes/umami/umami.libraries.yml
@@ -130,3 +130,9 @@ oneplusfourgrid_section:
+classy.dropbutton:
+  version: VERSION
+  css:
+    component:
+      css/classy/components/dropbutton.css: { weight: -10 }

The library loads a css file from Classy

3096203-20-incorrectly-override-core-lib-with-classy-lib-FAIL.patch

Error:

Drupal\KernelTests\Core\Theme\ThemeNotUsingClassyLibraryTest::testThemeAccountsForClassyExtensions with data set "claro" ('claro', array('core/drupal.dialog', 'core/drupal.progress', 'media/media_embed_ckeditor_theme', 'media_library/view', 'media_library/widget'))
user/drupal.user is replaced with classy/user. The replacement should not be a Classy library.

Triggered by:

+++ b/core/tests/Drupal/KernelTests/Core/Theme/ThemeNotUsingClassyLibraryTest.php
@@ -0,0 +1,488 @@
diff --git a/core/themes/claro/claro.info.yml b/core/themes/claro/claro.info.yml

+++ b/core/themes/claro/claro.info.yml
+++ b/core/themes/claro/claro.info.yml
@@ -98,7 +98,7 @@ libraries-override:

@@ -98,7 +98,7 @@ libraries-override:
 
   classy/user: false
 
-  user/drupal.user: claro/form.password-confirm
+  user/drupal.user: classy/user

In Claro, override user/drupal.user with classy/user

3096203-20-classy-extends-corelib-but-theme-does-not-FAIL.patch

Error:

Drupal\KernelTests\Core\Theme\ThemeNotUsingClassyLibraryTest::testThemeAccountsForClassyExtensions with data set "umami" ('umami', array('core/drupal.dialog', 'file/drupal.file', 'core/drupal.progress', 'media/media_embed_ckeditor_theme', 'media_library/view', 'media_library/widget'))
user/drupal.user is extended by Classy and should be extended or overridden by umami

Triggered by

+++ b/core/tests/Drupal/KernelTests/Core/Theme/ThemeNotUsingClassyLibraryTest.php
@@ -0,0 +1,488 @@
+        'umami',
+        [
+          // 'user/drupal.user'.
+          'core/drupal.dialog',

user/drupal.user is removed from skip-list for Umami, so the test includes it as one of the Classy extends of a core library that must now be present in Umami

3096203-20-incomplete-asset-copy-FAIL.patch

Error:

Drupal\KernelTests\Core\Theme\ThemeNotUsingClassyLibraryTest::testThemeNotUsingClassyLibraries with data set "umami" ('umami', array('base', 'book-navigation', 'dialog', 'file', 'forum', 'image-widget', 'indented', 'media_library', 'node', 'progress', 'search-results', 'user', 'media_embed_error', 'media_embed_ckeditor_theme'))
Missing the inclusion of one or more CSS files from classy/dropbutton.

Triggered by:

+++ b/core/profiles/demo_umami/themes/umami/umami.libraries.yml
@@ -130,3 +130,9 @@ oneplusfourgrid_section:
+classy.dropbutton:
+  version: VERSION
+  css:
+    component:
+      css/classy/components/dropbuttonx.css: { weight: -10 }

Changed the filename in the Umami library definition so the test thinks there is not a theme-specific copy of Classy's dropbutton.css

3096203-20-asset-properties-dont-match-FAIL.patch

Error:

Drupal\KernelTests\Core\Theme\ThemeNotUsingClassyLibraryTest::testThemeNotUsingClassyLibraries with data set "umami" ('umami', array('base', 'book-navigation', 'dialog', 'file', 'forum', 'image-widget', 'indented', 'media_library', 'node', 'progress', 'search-results', 'user', 'media_embed_error', 'media_embed_ckeditor_theme'))
The copied file: components/dropbutton.css from classy/dropbutton has a non-matching property: weight
Failed asserting that -11 matches expected -10.

Triggered by:

+++ b/core/profiles/demo_umami/themes/umami/umami.libraries.yml
@@ -130,3 +130,9 @@ oneplusfourgrid_section:
+      css/classy/components/dropbutton.css: { weight: -11 }

dropbutton.css has a weight of -11, which differ's from Classy's weight of -10

3096203-20-missing-copied-library-FAIL.patch

Error:

Drupal\KernelTests\Core\Theme\ThemeNotUsingClassyLibraryTest::testThemeNotUsingClassyLibraries with data set "umami" ('umami', array('base', 'book-navigation', 'dialog', 'file', 'forum', 'image-widget', 'indented', 'media_library', 'node', 'progress', 'search-results', 'user', 'media_embed_error', 'media_embed_ckeditor_theme'))
There is not a umami equivalent for classy/dropbutton

Triggered by:

+++ b/core/profiles/demo_umami/themes/umami/umami.libraries.yml
@@ -130,3 +130,9 @@ oneplusfourgrid_section:
+
+#classy.dropbutton:
+#  version: VERSION
+#  css:
+#    component:
+#      css/classy/components/dropbutton.css: { weight: -10 }

Commented out the umami/classy.dropbutton library that should replace classy/dropbutton.

3096203-20-missing-equivalent-file-FAIL.patch

Error:

Drupal\KernelTests\Core\Theme\ThemeNotUsingClassyLibraryTest::testThemeNotUsingClassyLibraries with data set "claro" ('claro', array('book-navigation', 'file', 'forum', 'image-widget', 'indented', 'media_library', 'node', 'search-results', 'media_embed_error', 'media_embed_ckeditor_theme'))
classy/base is overridden, but the theme is still loading these files from Classy. Array
(
    [4] => css/components/container-inline.css
    [6] => css/components/exposed-filters.css
    [7] => css/components/field.css
    [9] => css/components/icons.css
    [10] => css/components/inline-form.css
    [11] => css/components/item-list.css
    [12] => css/components/link.css
    [13] => css/components/links.css
    [14] => css/components/menu.css
    [15] => css/components/more-link.css
    [19] => css/components/tablesort.css
    [21] => css/components/textarea.css
    [22] => css/components/ui-dialog.css
)

Triggered by:

+++ b/core/tests/Drupal/KernelTests/Core/Theme/ThemeNotUsingClassyLibraryTest.php
@@ -0,0 +1,488 @@
+      'claro' => [
+        'claro',
+        [
+          // 'base'.
+          'book-navigation',
+          'file',
+          'forum',

Removed claro/base from the skip list. This library is overridden, but not all files are included in the override, so some Classy ones get through.

3096203-20-missing-library-override-FAIL.patch

Error:

Drupal\KernelTests\Core\Theme\ThemeNotUsingClassyLibraryTest::testThemeNotUsingClassyLibraries with data set "umami" ('umami', array('base', 'book-navigation', 'dialog', 'file', 'forum', 'image-widget', 'indented', 'media_library', 'node', 'progress', 'search-results', 'user', 'media_embed_error', 'media_embed_ckeditor_theme'))
The classy/dropbutton library is not overridden in umami

Triggered by

+++ b/core/profiles/demo_umami/themes/umami/umami.info.yml
@@ -12,6 +12,7 @@ libraries:
 libraries-override:
   classy/messages: false
+  # classy/dropbutton: umami/classy.dropbutton

Commented out the override of classy/dropbutton

The last submitted patch, 20: 3096203-20-missing-equivalent-file-FAIL.patch, failed testing. View results

The last submitted patch, 20: 3096203-20-missing-library-override-FAIL.patch, failed testing. View results

The last submitted patch, 20: 3096203-20-incomplete-asset-copy-FAIL.patch, failed testing. View results

The last submitted patch, 20: 3096203-20-missing-copied-library-FAIL.patch, failed testing. View results

The last submitted patch, 20: 3096203-20-asset-properties-dont-match-FAIL.patch, failed testing. View results

xjm’s picture

+1 for the refactor; much easier to read.

A few nits and inane observations:

  1. +++ b/core/tests/Drupal/KernelTests/Core/Theme/ThemeNotUsingClassyLibraryTest.php
    @@ -0,0 +1,486 @@
    +    // In some cases an overridden Classy library does not use any copied assets
    +    // from Classy. This array collects those so this test knows to skip
    +    // assertions specific to those copied assets.
    

    Still confused here... what are "some cases"?

  2. +++ b/core/tests/Drupal/KernelTests/Core/Theme/ThemeNotUsingClassyLibraryTest.php
    @@ -0,0 +1,486 @@
    +    $theme_library_overrides = $this->themeInitialization->getActiveThemeByName($theme)->getLibrariesOverride()[$theme_path] ?? [];
    

    Null coalescing operator, fancy!

  3. +++ b/core/tests/Drupal/KernelTests/Core/Theme/ThemeNotUsingClassyLibraryTest.php
    @@ -0,0 +1,486 @@
    +      // If $library assets is false or a string, the override is preventing the
    

    Missing underscore for $library_assets.

  4. +++ b/core/tests/Drupal/KernelTests/Core/Theme/ThemeNotUsingClassyLibraryTest.php
    @@ -0,0 +1,486 @@
    +      // If the library override has a `css` key, some Classy CSS files may
    

    Nit: I think we should use single quotes rather than backticks around 'css', because the array key is an actual string.

xjm’s picture

Thanks 💯for the clear fail patches and explanations; definitely a big help for reviewing the issue.

xjm’s picture

Some docblock nits:

  1. +++ b/core/tests/Drupal/KernelTests/Core/Theme/ThemeNotUsingClassyLibraryTest.php
    @@ -0,0 +1,486 @@
    +   * Classy's libraries.
    ...
    +   * Libraries that Classy extends.
    

    Now that we have these, I think extending the docblocks here a little would help make the whole test easier to grok. Edit: Plus an @see to the API method returning the arrays (if such exists) is nice.

  2. +++ b/core/tests/Drupal/KernelTests/Core/Theme/ThemeNotUsingClassyLibraryTest.php
    @@ -0,0 +1,486 @@
    +   * @var array
    +   */
    +  protected $classyLibraries;
    ...
    +   * @var array
    +   */
    +  protected $classyLibrariesExtend;
    ...
    +   * @param array $library_assets
    +   *   The library assets.
    ...
    +   * @param array $classy_library_data
    +   *   The Classy library's data.
    

    Can we use a more specific data type than array, e.g. array[], string[][], etc.?

  3. +++ b/core/tests/Drupal/KernelTests/Core/Theme/ThemeNotUsingClassyLibraryTest.php
    @@ -0,0 +1,486 @@
    +  /**
    +   * Ensures that a theme is decoupled from Classy libraries.
    +   *
    +   * @dataProvider providerTestThemeNotUsingClassyLibraries
    +   */
    +  public function testThemeNotUsingClassyLibraries($theme, array $libraries_to_skip) {
    ...
    +  /**
    +   * Checks for theme-specific equivalents of all Classy library-extends.
    +   *
    +   * @dataProvider providerTestThemeAccountsForClassyExtensions
    +   */
    +  public function testThemeAccountsForClassyExtensions($theme, array $extends_to_skip) {
    

    When test methods have a data provider, I like adding parameter documentation since that documents the data in the data provider nicely.

  4. +++ b/core/tests/Drupal/KernelTests/Core/Theme/ThemeNotUsingClassyLibraryTest.php
    @@ -0,0 +1,486 @@
    +   *   The theme's copy of the classy library.
    

    Ubernit: "Classy" with a capital C.

  5. +++ b/core/tests/Drupal/KernelTests/Core/Theme/ThemeNotUsingClassyLibraryTest.php
    @@ -0,0 +1,486 @@
    +   * @param string $theme_path
    +   *   The path to the active theme.
    

    It's the path to the theme being tested, correct?

xjm’s picture

  1. +++ b/core/tests/Drupal/KernelTests/Core/Theme/ThemeNotUsingClassyLibraryTest.php
    @@ -0,0 +1,486 @@
    +    // Get a list of all css or js files loaded by the Classy library.
    

    Ubernit: "CSS and "JS" capitalized, since they're words in a sentence rather than a string literal here.

  2. +++ b/core/tests/Drupal/KernelTests/Core/Theme/ThemeNotUsingClassyLibraryTest.php
    @@ -0,0 +1,486 @@
    +    $this->assertArrayHasKey($type, $theme_copy_of_classy_library);
    ...
    +    $this->assertNotEmpty($theme_assets);
    +    $this->assertNotEmpty($classy_assets);
    

    💯 for starting off assertions like these to avoid false positives or weird fails later. Nice and robust.

  3. +++ b/core/tests/Drupal/KernelTests/Core/Theme/ThemeNotUsingClassyLibraryTest.php
    @@ -0,0 +1,486 @@
    +      $key = str_replace("$theme_path/$type/classy/", '', $item['data']);
    +      $theme_assets[$key] = $item;
    

    So based on this $item['data'] is clearly a string, if that helps with the answer to my array type docs questions.

  4. +++ b/core/tests/Drupal/KernelTests/Core/Theme/ThemeNotUsingClassyLibraryTest.php
    @@ -0,0 +1,486 @@
    +    $this->assertEmpty(array_diff_key($theme_assets, $classy_assets), "Missing the inclusion of one or more CSS files from classy/$classy_library_name.");
    

    Oops... in the assertion message, isn't it either CSS or JS? Or am I confused?

xjm’s picture

  1. +++ b/core/tests/Drupal/KernelTests/Core/Theme/ThemeNotUsingClassyLibraryTest.php
    @@ -0,0 +1,486 @@
    +    // Get a list of libraries overridden by the current theme.
    ...
    +    // Get a list of libraries extended by the current theme.
    

    I guess part of where my theme-noob questions come into play is that I'm unfamiliar with what the difference is for a library to be "overridden" versus "extended". Is this terminology documented somewhere? I think that explanation in context will make everything else in the test easier to follow. A simple example in each case might help.

  2. +++ b/core/tests/Drupal/KernelTests/Core/Theme/ThemeNotUsingClassyLibraryTest.php
    @@ -0,0 +1,486 @@
    +    // in the active theme by either 1) The active theme extends the core
    

    "active theme" again, which means something site-config-specific to me. In the comments above, we're saying "current theme". We're talking about the same thing, right? The theme as named in $theme, which is the theme currently being tested?

  3. +++ b/core/tests/Drupal/KernelTests/Core/Theme/ThemeNotUsingClassyLibraryTest.php
    @@ -0,0 +1,486 @@
    +        $override_replaces_library = (gettype($overridden_with) === 'string');
    

    Hrm? I'm guessing this means that the item will contain string data as opposed to FALSE or NULL? Could use explanation.

  4. +++ b/core/tests/Drupal/KernelTests/Core/Theme/ThemeNotUsingClassyLibraryTest.php
    @@ -0,0 +1,486 @@
    +          if (isset($overridden_with['js'])) {
    +            foreach ($overridden_with['js'] as $js_file => $options) {
    +              $this->assertFalse(strpos($js_file, 'core/themes/classy/js'), "Override is loading a classy asset: $css_file");
    +            }
    +          }
    

    Bug in the assertion message I think; shouldn't it be $js_file?

xjm’s picture

Status: Needs review » Needs work

That's probably enough small feedback to merit a NW. Now I've read all the lines of the latest patch. :)

bnjmnm’s picture

Status: Needs work » Needs review
StatusFileSize
new16.98 KB
new23.09 KB

This addresses #30, #32, #33, #34. 🤞that the additional documentation helps more than confuses...

lauriii’s picture

Status: Needs review » Needs work

Thank you @bnjmnm for adding all the documenation! It makes understanding this test much easier 👏

  1. +++ b/core/tests/Drupal/KernelTests/Core/Theme/ThemeNotUsingClassyLibraryTest.php
    @@ -0,0 +1,529 @@
    + * Tests that themes do not depend on Classy libraries.
    

    Should we document that this is specifically added to facilitate the process of decoupling from Classy and that this may be removed later?

  2. +++ b/core/tests/Drupal/KernelTests/Core/Theme/ThemeNotUsingClassyLibraryTest.php
    @@ -0,0 +1,529 @@
    +      if ($in_skip_list || $not_classy_library || $library_replaced_by_another_library) {
    +        if ($library_replaced_by_another_library) {
    ...
    +          // Classy libraries. The should not be added to the
    

    Why are we checking this again? Isn't the previous check already enough?

  3. +++ b/core/tests/Drupal/KernelTests/Core/Theme/ThemeNotUsingClassyLibraryTest.php
    @@ -0,0 +1,529 @@
    +          // Libraries with names that begin with `$theme/classy.` are copies of
    +          // Classy libraries. The should not be added to the
    +          // $libraries_without_copied_classy_assets array before exiting this
    +          // iteration of the loop.
    

    This comment is a bit confusing. It would be also useful if this would include explanation on to why we are not adding these libraries to the array.

  4. +++ b/core/tests/Drupal/KernelTests/Core/Theme/ThemeNotUsingClassyLibraryTest.php
    @@ -0,0 +1,529 @@
    +                $this->assertFalse(strpos($css_file, 'core/themes/classy/css'), "Override is loading a classy asset: $css_file");
    ...
    +              $this->assertFalse(strpos($js_file, 'core/themes/classy/js'), "Override is loading a classy asset: $js_file");
    

    Nit pick: Classy with capital. 🔬👁

bnjmnm’s picture

Status: Needs work » Needs review
StatusFileSize
new8.19 KB
new23.56 KB

Addresses #37

lauriii’s picture

Status: Needs review » Reviewed & tested by the community
+++ b/core/tests/Drupal/KernelTests/Core/Theme/ThemeNotUsingClassyLibraryTest.php
@@ -7,6 +7,13 @@
+ * This test will fail when Classy is removed from Drupal core. At this point,
+ * this test will no longer be necessary and can be removed.

I'm not sure if we actually want hold removing this test until Classy is removed. It might make sense to allow themes to make changes to these library configuration before that. This could be discussed in a follow-up issue so maybe we just omit this piece of information now. I think this can be done on commit.

Besides that, this looks great ✨

bnjmnm’s picture

StatusFileSize
new729 bytes
new23.42 KB

I think this can be done on commit.

Here's an updated patch in case it can't be done on commit.

xjm’s picture

  1. +++ b/core/tests/Drupal/KernelTests/Core/Theme/ThemeNotUsingClassyLibraryTest.php
    @@ -0,0 +1,538 @@
    +   * Classy extends several core libraries with it's own assets, these are
    

    It should be "its" rather than "it's" in this sentence. ("It's" == "it is" but not "belonging to it".)

    Also, comma splice. I'd put a period after "assets" and then just capitalized "these" for a new sentence.

  2. +++ b/core/tests/Drupal/KernelTests/Core/Theme/ThemeNotUsingClassyLibraryTest.php
    @@ -0,0 +1,538 @@
    +    // accounted for in the current theme by either 1) The current theme extends
    +    // the core library with local copy of the Classy library 2) Overriding the
    +    // core library altogether.
    

    For parallelism and agreement with "by", the first item should be "The current theme extending the core library..." (rather than "extends").

  3. +++ b/core/tests/Drupal/KernelTests/Core/Theme/ThemeNotUsingClassyLibraryTest.php
    @@ -0,0 +1,538 @@
    +   * @param array $classy_library_data
    +   *   The Classy library's data.
    +   * @param array $theme_copy_of_classy_library
    +   *   The theme's copy of the Classy library.
    

    Same question about the specific array structure. We can at least say array[]. (Or maybe mixed[][], but the latter only occurs three times in core, so we can probably stick with array[].)

  4. +++ b/core/tests/Drupal/KernelTests/Core/Theme/ThemeNotUsingClassyLibraryTest.php
    @@ -0,0 +1,538 @@
    +   * @return array
    +   *   Themes and the libraries to be ignored.
    ...
    +   * @return array
    +   *   Themes and the extensions to be ignored.
    

    This could also be array[] based on the values.

These fixes are small enough that uploading a new patch at RTBC would be fine.

bnjmnm’s picture

StatusFileSize
new3.13 KB
new23.43 KB

Addresses #41

xjm’s picture

Saving issue credit.

  • xjm committed b01c410 on 9.0.x
    Issue #3096203 by bnjmnm, xjm, lauriii: Create Classy library dependency...

  • xjm committed 0cc4e67 on 8.9.x
    Issue #3096203 by bnjmnm, xjm, lauriii: Create Classy library dependency...
xjm’s picture

Status: Reviewed & tested by the community » Fixed

Committed to 9.0.x, and backported to 8.9.x also so that the diff between the branches is meaningful for the test. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.