Commit 144568ec authored by catch's avatar catch
Browse files

Issue #3279850 by alexpott, dww, lauriii: Theme post updates are not...

Issue #3279850 by alexpott, dww, lauriii: Theme post updates are not recognised when the theme is used in the installer
parent 199f2b4b
Loading
Loading
Loading
Loading
+9 −2
Original line number Diff line number Diff line
@@ -337,16 +337,23 @@ protected function includeThemes(): bool {
  public function onConfigSave(ConfigCrudEvent $event) {
    $config = $event->getConfig();
    if ($config->getName() === 'core.extension') {
      // Build the old extension configuration list from configuration rather
      // than using $this->enabledExtensions. This ensures that if the
      // UpdateRegistry is constructed after _drupal_maintenance_theme() has
      // added a theme to the theme handler it will not be considered as already
      // installed.
      $old_extension_list = array_keys($config->getOriginal('module') ?? []);
      $new_extension_list = array_keys($config->get('module'));
      if ($this->includeThemes()) {
        $new_extension_list = array_merge($new_extension_list, array_keys($config->get('theme')));
        $old_extension_list = array_merge($old_extension_list, array_keys($config->getOriginal('theme') ?? []));
      }

      // The list of extensions installed or uninstalled. In regular operation
      // only one of the lists will have a single value. This is because Drupal
      // can only install one extension at a time.
      $uninstalled_extensions = array_diff($this->enabledExtensions, $new_extension_list);
      $installed_extensions = array_diff($new_extension_list, $this->enabledExtensions);
      $uninstalled_extensions = array_diff($old_extension_list, $new_extension_list);
      $installed_extensions = array_diff($new_extension_list, $old_extension_list);

      // Set the list of enabled extensions correctly so update function
      // discovery works as expected.
+74 −0
Original line number Diff line number Diff line
<?php

namespace Drupal\Tests\system\Functional\Theme;

use Drupal\Core\Serialization\Yaml;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\RequirementsPageTrait;

/**
 * Ensures theme update functions are registered for maintenance themes.
 *
 * @group Theme
 */
class MaintenanceThemeUpdateRegistryTest extends BrowserTestBase {
  use RequirementsPageTrait;

  /**
   * {@inheritdoc}
   */
  protected $profile = 'theme_test_profile';

  /**
   * {@inheritdoc}
   */
  protected function prepareSettings() {
    parent::prepareSettings();
    $this->writeSettings([
      'settings' => [
        'maintenance_theme' => (object) [
          'value' => 'test_theme_updates',
          'required' => TRUE,
        ],
      ],
    ]);
  }

  /**
   * {@inheritdoc}
   */
  protected function prepareEnvironment() {
    parent::prepareEnvironment();
    $info = [
      'type' => 'profile',
      'core_version_requirement' => '*',
      'name' => 'Theme test profile',
      'themes' => [
        'test_theme_updates',
      ],
    ];
    // Create an install profile that uses the test theme.
    $path = $this->siteDirectory . '/profiles/theme_test_profile';
    mkdir($path, 0777, TRUE);
    file_put_contents("$path/theme_test_profile.info.yml", Yaml::encode($info));

    // Create a system.theme.yml file for the profile so the test theme is used.
    $path = $this->siteDirectory . '/profiles/theme_test_profile/config/install';
    mkdir($path, 0777, TRUE);
    $theme_config = Yaml::decode(file_get_contents(\Drupal::moduleHandler()->getModule('system')->getPath() . '/config/install/system.theme.yml'));
    $theme_config['default'] = 'test_theme_updates';
    file_put_contents("$path/system.theme.yml", Yaml::encode($theme_config));
  }

  /**
   * Tests that after installing the profile there are no outstanding updates.
   */
  public function testMaintenanceThemeUpdateRegistration() {
    $this->drupalLogin($this->rootUser);
    $this->drupalGet('update.php/selection');
    $this->updateRequirementsProblem();
    $this->drupalGet('update.php/selection');
    $this->assertSession()->pageTextContains('No pending updates.');
  }

}
+5 −0
Original line number Diff line number Diff line
name: Test Theme Updates
type: theme
description: A theme that has a post update.
version: VERSION
base theme: false
+13 −0
Original line number Diff line number Diff line
<?php

/**
 * @file
 * Update functions for the theme.
 */

/**
 * Tests post updates for themes.
 */
function test_theme_updates_post_update_test(&$sandbox = NULL) {
  // Do nothing.
}