Follow-up to #2228093: Modernize theme initialization
Problem
#2228093: Modernize theme initialization introduced the following two changes, which are highly problematic, since each of them is priming theme configuration ahead of time, which doesn't actually exist yet, and unfortunately worse, they conflict with actual expectations of the installation profile as well as tests:
+++ b/core/config/install/core.extension.yml
@@ -1,4 +1,5 @@
-theme: {}
+theme:
+ stark: 0
+++ b/core/modules/simpletest/src/KernelTestBase.php
@@ -176,7 +176,7 @@ protected function setUp() {
- \Drupal::service('config.storage')->write('core.extension', array('module' => array(), 'theme' => array()));
+ \Drupal::service('config.storage')->write('core.extension', array('module' => array(), 'theme' => array('seven' => 1, 'stark' => 1)));
These two changes present a critical problem, since priming the configuration ahead of time will cause all new code to be based on the expectation that the configuration "magically" exists already - even though it should not and must not exist, because no code asked for it.
The affected extensions are already marked as installed and will be loaded by default. Their default configuration will not be installed. hook_install() will never be invoked. All tests are running against the changed extension configuration, which does not resemble a clean slate Drupal application.
In other words: Patches that transitioned to RTBC since 2014-08-21 17:00 UTC might not be safe to commit, since fundamental conditions/expectations of the testing framework have changed.
Therefore, we need to fix this ASAP.
Expected behavior
-
The installer is supposed to use the
'distribution:install:theme'property of the installation profile's.info.ymlfile, if defined, otherwise fall back to 'seven'.Nevermind. This still works as before and as expected, because neither
_drupal_maintenance_theme()norinstall_begin_request()was changed by #2228093: Modernize theme initialization -
Kernel tests are supposed to be executed against "no theme at all" by default; i.e., whatever gets rendered is exclusively rendered through the unmodified, original theme functions/templates of modules only.
The primary purpose of asserting output in kernel tests is to assert the original output of a module, without any kind of theme interaction — unless a theme was explicitly installed manually by a test.
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | interdiff.txt | 2.21 KB | sun |
| #9 | theme.prime_.9.patch | 10.34 KB | sun |
| #6 | interdiff.txt | 5.72 KB | sun |
| #6 | theme.prime_.6.patch | 8.9 KB | sun |
| #4 | theme.prime_.4.patch | 4.57 KB | sun |
Comments
Comment #1
sunIt's not really clear to me what fails without those changes and why they were necessary, so let's start with this.
Comment #3
sunBriefly discussed with @dawehner in IRC already.
We probably need a custom theme negotiator in the (early) installer to resemble the original behavior of a custom installation profile theme. That should get us past the initial "Drupal installation failed" test failure.
The other expectation for kernel tests likely needs an adjustment to
ThemeInitializationservice, so as to fall back to the (fake) "core" theme in case no default theme is configured, or no themes are enabled.Some helpful links:
Installer theme selection in
install_begin_request():http://cgit.drupalcode.org/drupal/tree/core/includes/install.core.inc#n395
The case of "no/unknown theme" was handled by the
if (!$theme || !isset($themes[$theme]))condition indrupal_theme_initialize()in:http://cgit.drupalcode.org/drupal/diff/core/includes/theme.inc?id=a4125e...
Comment #4
sunAttached patch allows me to manually install locally. Let's see what the bot has to say.
In essence, this just simply resurrects the original code from http://cgit.drupalcode.org/drupal/diff/core/includes/theme.inc?id=a4125e...
Comment #5
dawehnerIn general I like that actually not much code has to be changed.
I wonder whether storing the active_theme for 'core' makes sense.
OT: I prefer to use [] in new code
Comment #6
sunKernelTestBaseTest, which would have prevented at least theKTB::setUp()change, but didn't exist yet, so it's no surprise that the unintentional change in behavior wasn't caught :)Comment #8
sunThe installer still works as before and as expected, because neither
_drupal_maintenance_theme()norinstall_begin_request()was changed by #2228093: Modernize theme initializationThe expected behavior is covered by the
DistributionProfileTestalready.Updating issue summary accordingly.
That said, while the KTB expectations can be tested, the expected emptiness of the
core.extension.ymldefault config cannot.That is, unless we'd write a relatively dumb test that would do nothing else than to load the default config file and assert that it's empty.
Sounds a little wonky, but might actually be worth to add.
Comment #9
sunAdded clean regression unit test for
core.extension.yml+ slightly adjusted docs inThemeInitialization.Comment #10
sunLast patch should still be green, adds regression test coverage, and thus should be ready to be committed.
Clarified the issue summary.
Comment #11
tim.plunkettSorry, only committers can add that tag.
This can block release, but the issue summary seems to exaggerate the urgency of this issue.
Comment #12
dawehnerI would suggest to just check that the keys you have here, have the proper value. Otherwise it would be more complex to add new configuration, which might happen in the future.
Comment #13
sun@dawehner: I considered that, but (1) it's unlikely to change any time soon, and (2) in case a new property would be added, then this test should cover that new property, too, but individual assertions would miss the addition, so the new property would be able to prime an extension ahead of time. The test should intentionally fail in case of any change.
Comment #15
dawehnerI am already convinced by (2). This though means that we have to ensure that we don't include UIs into Core at some point, which hopefully won't happen.
Comment #16
webchickI admit this patch is a bit over my head, but looks to have been thoroughly reviewed, and unblocks a critical.
Committed and pushed to 8.x. Thanks!