If you go to the Appearance page on a fresh installation of Drupal 8 and click "Install and set as default" next to the Stark theme, the theme will be installed, but not actually set as the default. Instead, you get an error message: "The stark theme was not found"

If you click "Set as default" afterwards, though, then it works.

Comments

honzakuchar’s picture

Confirmed on commit 8f9efdedddd5864b10ae7189b9a6f9296f1791eb

The error came from installation step. When you click install you get this error. (but theme installs) Clicking enables works without issues.

honzakuchar’s picture

Assigned: Unassigned » honzakuchar
honzakuchar’s picture

star-szr’s picture

Status: Active » Needs review
Issue tags: +Needs tests

Thanks @honzakuchar. Setting to needs review so it goes through the automated tests (aka testbot). And tagging because this needs test coverage.

honzakuchar’s picture

I'm not sure if it really needs test coverage. (writing new test for this) The code I've updated will be deleted in Drupal 9.0.

Where should go regression tests? Just into ThemeHandlerTest.php ?

honzakuchar’s picture

@Cottser bump

David_Rothstein’s picture

Status: Needs review » Needs work

The first part of the patch looks good to me, and I verified that it fixes the bug - thanks!

I don't understand the second part though. The uninstall() method is not documented as having a return value, and the function it calls does not appear to return anything either...

Regarding tests, I think that would definitely be a good idea. The code comments just say that the code in question is deprecated, but certainly not the "Install and set as default" functionality itself. Also, Drupal 9 is a long way away :)

I think Drupal\system\Tests\System\ThemeTest is the right place to add a functional test. You can see in the testSwitchDefaultTheme() method that it already has one for switching the default theme via the "Set as default" link, so probably just needs a similar one for "Install and set as default".

star-szr’s picture

Yup, what David said. Thanks :)

RavindraSingh’s picture

Status: Needs work » Needs review
StatusFileSize
new3.03 KB
new1.85 KB

Thank you @David_Rothstein, I got a little idea based on your suggestion. just creating a tests for "Install and set a default" link. Please let me know if I should not create a new testfunctions. I will optimize the code once I get more clarification on this.

Added code looks like:

/**
   * Test installing and switching to default theme.
   */
  function testInstallAndSwitchDefaultTheme() {
    // Install Bartik and set it as the default theme.
    \Drupal::service('theme_handler')->install(array('bartik'));
    $this->drupalGet('admin/appearance');
    $this->clickLink(t('Set as default'));
    $this->assertEqual($this->config('system.theme')->get('default'), 'bartik');

    // Test the default theme on the secondary links (blocks admin page).
    $this->drupalGet('admin/structure/block');
    $this->assertText('Stark(' . t('active tab') . ')', 'Default local task on blocks admin page is the default theme.');
    
    // Switch back to Stark and test again to test that the menu cache is cleared.
    $this->drupalGet('admin/appearance');
    // Classy is the first 'Set as default' link.
    $this->clickLink(t('Install and set as default'), 0);
    $this->drupalGet('admin/structure/block');
    $this->assertText('Stark(' . t('active tab') . ')', 'Default local task on blocks admin page has changed.');
  }

Logically I should not install bartik on this tests. i am already on admin/appearance page.

Status: Needs review » Needs work

The last submitted patch, 9: 2498691-install-and-set-default-theme-9.patch, failed testing.

RavindraSingh’s picture

Issue tags: +Needs reroll

Seems some API also has been changed. So adding needs reroll

error: patch failed: core/modules/system/src/Tests/System/ThemeTest.php:254
error: core/modules/system/src/Tests/System/ThemeTest.php: patch does not apply
mesch’s picture

Status: Needs work » Needs review
StatusFileSize
new1.92 KB

As per #7, removed return from uninstall method, and added simpletest method to existing ThemeTest class.

darol100’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs reroll

I have test this patch out #13 and seem to fix this issue.

wim leers’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: -Needs tests

A few nits, sorry.

  1. +++ b/core/lib/Drupal/Core/Extension/ThemeHandler.php
    @@ -167,7 +167,7 @@ public function setDefault($name) {
    -    \Drupal::service('theme_installer')->install($theme_list, $install_dependencies);
    +    return \Drupal::service('theme_installer')->install($theme_list, $install_dependencies);
    

    HAH!

  2. +++ b/core/modules/system/src/Tests/System/ThemeTest.php
    @@ -334,4 +334,21 @@ function testUninstallingThemes() {
    +    // Bartik comes uninstalled and has the second "Install and set as default" link.
    

    80 cols.

  3. +++ b/core/modules/system/src/Tests/System/ThemeTest.php
    @@ -334,4 +334,21 @@ function testUninstallingThemes() {
    +  }
     }
    

    Needs a newline in between.

mesch’s picture

Status: Needs work » Needs review
StatusFileSize
new1.93 KB

Thanks @Wim Leers.

Addressed #2 and #3. Was #1 a "that was an easy fix" HAH or a "mesch, you did something silly" HAH? :)

star-szr’s picture

Status: Needs review » Needs work

Yeah I'm pretty sure it's "HAH that was an easy fix" ;)

Couple more remaining nits:

  1. +++ b/core/modules/system/src/Tests/System/ThemeTest.php
    @@ -334,4 +334,23 @@ function testUninstallingThemes() {
    +  /**
    +   * Test installing a theme and setting it as default.
    +   */
    +  function testInstallAndSetAsDefault() {
    

    Docblock usually start plural "Tests" per https://www.drupal.org/node/1354#functions. (I'm not an English major but this part - third person singular present tense verb).

  2. +++ b/core/modules/system/src/Tests/System/ThemeTest.php
    @@ -334,4 +334,23 @@ function testUninstallingThemes() {
    +  ¶
    

    Trailing whitespace here.

wim leers’s picture

Indeed it was the positive one :)

darol100’s picture

Assigned: honzakuchar » Unassigned
StatusFileSize
new2.37 KB

Here is the patch with #16 suggestions.

darol100’s picture

Status: Needs work » Needs review
star-szr’s picture

Changes look good, thanks @darol100, next time please provide an interdiff :)

I'm not sure that we've seen a test-only patch yet.

Can we get a test-only version of the patch posted, along with the same patch from #18? Like on the bottom of https://www.drupal.org/contributor-tasks/write-tests.

mesch’s picture

star-szr’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Quick fix

Excellent, that newline should be there :)

RTBC*, has tests and fixes the bug.

This should get kicked back to needs work because the test-only patch was uploaded second (upload it first to prevent this in the future). I do declare that anyone can re-RTBC it today on my behalf.

* The RTBC is also conditional on the test-only patch failing :)

The last submitted patch, 21: theme-install-set-as-default_2498691_21.patch, failed testing.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 21: theme-install-set-as-default-test_2498691_21.patch, failed testing.

star-szr’s picture

Seems not worth retesting at this point, testbot is having a bad day.

Status: Needs work » Needs review
star-szr’s picture

Status: Needs review » Reviewed & tested by the community

Taking a chance, things seem to have calmed down somewhat.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 21: theme-install-set-as-default-test_2498691_21.patch, failed testing.

star-szr’s picture

Status: Needs work » Reviewed & tested by the community

Now as long as the testbot re-testing RTBC patches doesn't mess this up…

David_Rothstein’s picture

Status: Reviewed & tested by the community » Needs work
+    $this->assertText('Bartik ' . t('is now the default theme.'));

This isn't a correct use of translations.

I think the simplest way to fix that is just to change it to $this->assertText('Bartik is now the default theme.'). (Since it's running in the context of a test site, we know it will be in English.) A number of existing tests do it like that.

Otherwise, all looks good. The rest of the test looks consistent with how the existing testSwitchDefaultTheme() test is done.

wim leers’s picture

I think the simplest way to fix that is just to change it

Yep.

deepakaryan1988’s picture

Assigned: Unassigned » deepakaryan1988
deepakaryan1988’s picture

Assigned: deepakaryan1988 » Unassigned
Status: Needs work » Needs review
StatusFileSize
new1.92 KB
new1.13 KB

Addressing the fixes in #31

Status: Needs review » Needs work

The last submitted patch, 34: theme-install-set-as-default_2498691_34.patch, failed testing.

deepakaryan1988’s picture

Status: Needs work » Needs review
StatusFileSize
new1.13 KB
new1.92 KB

Fixing up!

star-szr’s picture

+++ b/core/modules/system/src/Tests/System/ThemeTest.php
@@ -334,4 +334,23 @@ function testUninstallingThemes() {
+    $this->assertText('Bartik(' . t('active tab') . ')', 'Default local task on blocks admin page is the default theme.');

Would the same comment apply here?

mesch’s picture

I find the simpletest documentation on t() is a bit unclear on when and where the strings are translated. The t() function is used elsewhere in this class (e.g. testInvalidTheme()) with assertText() and likewise in the simpletest examples module.

The alternative:

$this->assertText(t('@theme is now the default theme.', array('@theme' => 'Bartik')));
star-szr’s picture

But it should probably match the current translatable string in that case, which uses % and then you'd use assertRaw() instead I think. Not sure.

David_Rothstein’s picture

Yeah, using the actual translatable string from the main codebase (plus switching to assertRaw if necessary) is another option.

For 'Bartik(' . t('active tab') . ')', I agree it looks suspicious also; I didn't comment on it earlier because the existing test does the exact same thing, so if it's a problem it's a preexisting one :)

kattekrab’s picture

cilefen’s picture

I do not see the value of loading the blocks admin page to check the default theme. This checks the appearance form output and for the regression caused by ThemeHandler::install() not returning anything. I am a bit of a mad wizard with regexes so somebody give it a hard look please.

The last submitted patch, 42: install_and_set_as-2498691-42-fail.patch, failed testing.

cilefen’s picture

This is less fragile.

The last submitted patch, 44: install_and_set_as-2498691-44-FAIL.patch, failed testing.

almaudoh’s picture

Status: Needs review » Reviewed & tested by the community

Had this same issue, was looking to file a bug, then saw this issue. So I've done a manual test of patch #44. The patch fixes the issue for me and the test is great.

kattekrab’s picture

Issue summary: View changes
StatusFileSize
new16.4 KB

Manual Test ok.

RTBC++

screenshot shows error before patch and success message after patch

mangy.fox’s picture

Manually tested patch #44 and works perfectly.

RTBC from me too.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

This fixes the bug and has a test - nice. Committed cffc13a and pushed to 8.0.x. Thanks!

  • alexpott committed cffc13a on 8.0.x
    Issue #2498691 by cilefen, mesch, deepakaryan1988, RavindraSingh,...

Status: Fixed » Closed (fixed)

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