Unverified Commit b9fce45b authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3115223 by bnjmnm, lauriii, tedbow, xjm, alexpott: Remove Stable as a...

Issue #3115223 by bnjmnm, lauriii, tedbow, xjm, alexpott: Remove Stable as a base theme of core themes
parent f156b5c6
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -493,7 +493,7 @@ public function testEntityBundleDelete() {
   */
  public function testExtensionValidation() {
    \Drupal::service('module_installer')->install(['node']);
    \Drupal::service('theme_installer')->install(['bartik']);
    \Drupal::service('theme_installer')->install(['test_subtheme']);
    $this->rebuildContainer();

    $sync = $this->container->get('config.storage.sync');
@@ -504,9 +504,9 @@ public function testExtensionValidation() {
    $module_data = $this->container->get('extension.list.module')->getList();
    $this->assertTrue(isset($module_data['node']->requires['text']), 'The Node module depends on the Text module.');
    // Bartik depends on Stable.
    unset($core['theme']['stable']);
    unset($core['theme']['test_basetheme']);
    $theme_data = \Drupal::service('theme_handler')->rebuildThemeData();
    $this->assertTrue(isset($theme_data['bartik']->requires['stable']), 'The Bartik theme depends on the Stable theme.');
    $this->assertTrue(isset($theme_data['test_subtheme']->requires['test_basetheme']), 'The Test Subtheme theme depends on the Test Basetheme theme.');
    // This module does not exist.
    $core['module']['does_not_exist'] = 0;
    // This theme does not exist.
@@ -516,7 +516,7 @@ public function testExtensionValidation() {
    $this->drupalPostForm('admin/config/development/configuration', [], t('Import all'));
    $this->assertText('The configuration cannot be imported because it failed validation for the following reasons:');
    $this->assertText('Unable to uninstall the Text module since the Node module is installed.');
    $this->assertText('Unable to uninstall the Stable theme since the Bartik theme is installed.');
    $this->assertText('Unable to uninstall the Theme test base theme theme since the Theme test subtheme theme is installed.');
    $this->assertText('Unable to install the does_not_exist module since it does not exist.');
    $this->assertText('Unable to install the does_not_exist theme since it does not exist.');
  }
+22 −0
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@
use Drupal\Core\Entity\ContentEntityType;
use Drupal\Core\Entity\ContentEntityTypeInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Extension\Exception\UnknownExtensionException;

/**
 * Implements hook_removed_post_updates().
@@ -125,3 +126,24 @@ function system_post_update_uninstall_classy() {
    // depending on it.
  }
}

/**
 * Uninstall Stable if it is no longer needed.
 *
 * This needs to run after system_post_update_uninstall_classy(). This will be
 * the case since getAvailableUpdateFunctions() returns an alphabetically sorted
 * list of post_update hooks to be run.
 *
 * @see Drupal\Core\Update\UpdateRegistry::getAvailableUpdateFunctions()
 */
function system_post_update_uninstall_stable() {
  /** @var \Drupal\Core\Extension\ThemeInstallerInterface $theme_installer */
  $theme_installer = \Drupal::getContainer()->get('theme_installer');
  try {
    $theme_installer->uninstall(['stable']);
  }
  catch (\InvalidArgumentException | UnknownExtensionException $exception) {
    // Exception is thrown if Stable wasn't installed or if there are themes
    // depending on it.
  }
}
+2 −1
Original line number Diff line number Diff line
@@ -28,13 +28,14 @@ public function testUpdate() {
    /** @var \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler */
    $theme_handler = $this->container->get('theme_handler');
    $this->assertTrue($theme_handler->themeExists('classy'));
    $this->assertTrue($theme_handler->themeExists('seven'));

    $this->runUpdates();

    // Ensure that Classy is not installed after running updates.
    $theme_handler->refreshInfo();
    $this->assertFalse($theme_handler->themeExists('classy'));
    $this->assertTrue($theme_handler->themeExists('stable'));
    $this->assertTrue($theme_handler->themeExists('seven'));
  }

  /**
+89 −0
Original line number Diff line number Diff line
<?php

namespace Drupal\Tests\system\Functional\Update;

use Drupal\FunctionalTests\Update\UpdatePathTestBase;

/**
 * Ensures that update hook uninstalls Stable when it's no longer needed.
 *
 * @group Update
 * @see system_post_update_uninstall_stable()
 */
class StableUninstallUpdateTest extends UpdatePathTestBase {

  /**
   * {@inheritdoc}
   */
  protected function setDatabaseDumpFiles() {
    $this->databaseDumpFiles = [
      __DIR__ . '/../../../fixtures/update/drupal-8.8.0.bare.standard.php.gz',
    ];
  }

  /**
   * Ensures that Stable is disabled if it's no longer needed.
   */
  public function testUpdate() {
    /** @var \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler */
    $theme_handler = $this->container->get('theme_handler');
    $this->assertTrue($theme_handler->themeExists('stable'));
    $this->assertTrue($theme_handler->themeExists('seven'));

    $this->runUpdates();

    // Ensure that Stable is not installed after running updates.
    $theme_handler->refreshInfo();
    $this->assertFalse($theme_handler->themeExists('stable'));
    $this->assertTrue($theme_handler->themeExists('seven'));
  }

  /**
   * Ensures that updates run without errors when Stable is not installed.
   */
  public function testUpdateStableNotInstalled() {
    /** @var \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler */
    $theme_handler = $this->container->get('theme_handler');
    $theme_list = array_keys($theme_handler->listInfo());
    /** @var \Drupal\Core\Extension\ThemeInstallerInterface $theme_installer */
    $theme_installer = $this->container->get('theme_installer');
    $theme_installer->install(['stark']);
    $this->container->get('config.factory')
      ->getEditable('system.theme')
      ->set('default', 'stark')
      ->set('admin', '')
      ->save();
    $theme_handler->refreshInfo();

    // Uninstall all themes that were installed prior to enabling Stark.
    $theme_installer->uninstall($theme_list);

    // Ensure that Stable is not installed anymore.
    $theme_handler->refreshInfo();
    $this->assertFalse($theme_handler->themeExists('stable'));

    $this->runUpdates();

    $theme_handler->refreshInfo();
    $this->assertFalse($theme_handler->themeExists('stable'));
  }

  /**
   * Ensures that updates run without errors when Stable is still needed.
   */
  public function testUpdateStableNeeded() {
    /** @var \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler */
    $theme_handler = $this->container->get('theme_handler');
    /** @var \Drupal\Core\Extension\ThemeInstallerInterface $theme_installer */
    $theme_installer = $this->container->get('theme_installer');
    $theme_installer->install(['test_theme_depending_on_stable']);
    $this->assertTrue($theme_handler->themeExists('stable'));

    $this->runUpdates();

    // Ensure that Stable is still installed after running tests.
    $theme_handler->refreshInfo();
    $this->assertTrue($theme_handler->themeExists('stable'));
  }

}
+4 −0
Original line number Diff line number Diff line
type: theme
base theme: stable
name: 'Test theme depending on Stable'
version: VERSION
Loading