You are here

public function ThemeTest::testThemeUpdateManagementRemovedPostUpdates in Drupal 10

Tests the update registry is correct during theme install and uninstall.

File

core/modules/system/tests/src/Kernel/Theme/ThemeTest.php, line 188

Class

ThemeTest
Tests low-level theme functions.

Namespace

Drupal\Tests\system\Kernel\Theme

Code

public function testThemeUpdateManagementRemovedPostUpdates() {

  // Install modules the theme is dependent on and enable the removed post
  // updates function.
  \Drupal::state()
    ->set('test_theme_depending_on_modules.removed_post_updates', TRUE);
  \Drupal::service('module_installer')
    ->install([
    'test_module_required_by_theme',
    'test_another_module_required_by_theme',
  ]);
  $post_update_registry = \Drupal::service('update.post_update_registry');
  $this
    ->assertEmpty($post_update_registry
    ->getUpdateFunctions('test_theme_depending_on_modules'), 'No updates test_theme_depending_on_modules for prior to install.');
  \Drupal::service('theme_installer')
    ->install([
    'test_theme_depending_on_modules',
  ]);

  // Ensure the removed post update function has been added to the list of
  // existing updates.
  $this
    ->assertContains('test_theme_depending_on_modules_post_update_foo', \Drupal::service('keyvalue')
    ->get('post_update')
    ->get('existing_updates'));
  \Drupal::service('theme_installer')
    ->uninstall([
    'test_theme_depending_on_modules',
  ]);

  // Ensure the removed post update function has been removed from the list of
  // existing updates.
  $this
    ->assertNotContains('test_theme_depending_on_modules_post_update_foo', \Drupal::service('keyvalue')
    ->get('post_update')
    ->get('existing_updates'));
}