function ThemeTest::testThemeUpdateManagement

Same name in other branches
  1. 10 core/modules/system/tests/src/Kernel/Theme/ThemeTest.php \Drupal\Tests\system\Kernel\Theme\ThemeTest::testThemeUpdateManagement()
  2. 11.x core/modules/system/tests/src/Kernel/Theme/ThemeTest.php \Drupal\Tests\system\Kernel\Theme\ThemeTest::testThemeUpdateManagement()

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

File

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

Class

ThemeTest
Tests low-level theme functions.

Namespace

Drupal\Tests\system\Kernel\Theme

Code

public function testThemeUpdateManagement() {
    // Install modules the theme is dependent on and enable the post update
    // function.
    \Drupal::state()->set('test_theme_depending_on_modules.post_update', TRUE);
    \Drupal::service('module_installer')->install([
        'test_module_required_by_theme',
        'test_another_module_required_by_theme',
    ]);
    
    /** @var \Drupal\Core\Update\UpdateRegistry $post_update_registry */
    $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 post update function has been added to the list of
    // existing updates.
    $this->assertContains('test_theme_depending_on_modules_post_update_module_install', \Drupal::service('keyvalue')->get('post_update')
        ->get('existing_updates'));
    \Drupal::service('theme_installer')->uninstall([
        'test_theme_depending_on_modules',
    ]);
    // Ensure the post update function has been removed from the list of
    // existing updates.
    $this->assertNotContains('test_theme_depending_on_modules_post_update_module_install', \Drupal::service('keyvalue')->get('post_update')
        ->get('existing_updates'));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.