From cffc13a8cd1321b752fb4ccbec44d571d1ddd662 Mon Sep 17 00:00:00 2001
From: Alex Pott <alex.a.pott@googlemail.com>
Date: Thu, 16 Jul 2015 20:24:48 +0100
Subject: [PATCH] Issue #2498691 by cilefen, mesch, deepakaryan1988,
 RavindraSingh, honzakuchar, darol100, kattekrab, Cottser, David_Rothstein:
 "Install and set as default" link on the Appearance page doesn't work

---
 .../Drupal/Core/Extension/ThemeHandler.php    |  2 +-
 .../system/src/Tests/System/ThemeTest.php     | 24 +++++++++++++++++++
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/core/lib/Drupal/Core/Extension/ThemeHandler.php b/core/lib/Drupal/Core/Extension/ThemeHandler.php
index f53bb0c997d5..4059d791cd26 100644
--- a/core/lib/Drupal/Core/Extension/ThemeHandler.php
+++ b/core/lib/Drupal/Core/Extension/ThemeHandler.php
@@ -167,7 +167,7 @@ public function setDefault($name) {
   public function install(array $theme_list, $install_dependencies = TRUE) {
     // We keep the old install() method as BC layer but redirect directly to the
     // theme installer.
-    \Drupal::service('theme_installer')->install($theme_list, $install_dependencies);
+    return \Drupal::service('theme_installer')->install($theme_list, $install_dependencies);
   }
 
   /**
diff --git a/core/modules/system/src/Tests/System/ThemeTest.php b/core/modules/system/src/Tests/System/ThemeTest.php
index 3c36ae4308d9..84745b7c2977 100644
--- a/core/modules/system/src/Tests/System/ThemeTest.php
+++ b/core/modules/system/src/Tests/System/ThemeTest.php
@@ -334,4 +334,28 @@ function testUninstallingThemes() {
     $this->clickLink(t('Uninstall'));
     $this->assertRaw('The <em class="placeholder">Classy</em> theme has been uninstalled');
   }
+
+  /**
+   * Tests installing a theme and setting it as default.
+   */
+  function testInstallAndSetAsDefault() {
+    $this->drupalGet('admin/appearance');
+    // Bartik is uninstalled in the test profile and has the second "Install and
+    // set as default" link.
+    $this->clickLink(t('Install and set as default'), 1);
+    // Test the confirmation message.
+    $this->assertText('Bartik is now the default theme.');
+    // Make sure Bartik is now set as the default theme in config.
+    $this->assertEqual($this->config('system.theme')->get('default'), 'bartik');
+
+    // This checks for a regression. See https://www.drupal.org/node/2498691.
+    $this->assertNoText('The bartik theme was not found.');
+
+    $themes = \Drupal::service('theme_handler')->rebuildThemeData();
+    $version = $themes['bartik']->info['version'];
+
+    // Confirm Bartik is indicated as the default theme.
+    $this->assertTextPattern('/Bartik ' . preg_quote($version) . '\s{2,}\(default theme\)/');
+  }
+
 }
-- 
GitLab