You are here

public function UninstallKernelTest::testUninstallPluginCacheClear in Drupal 10

Same name and namespace in other branches
  1. 9 core/modules/system/tests/src/Kernel/Installer/UninstallKernelTest.php \Drupal\Tests\system\Kernel\Installer\UninstallKernelTest::testUninstallPluginCacheClear()

Tests uninstalling a module with a plugin cache clearer service.

File

core/modules/system/tests/src/Kernel/Installer/UninstallKernelTest.php, line 55

Class

UninstallKernelTest
Tests the uninstallation of modules.

Namespace

Drupal\Tests\system\Kernel\Installer

Code

public function testUninstallPluginCacheClear() {
  \Drupal::service('module_installer')
    ->install([
    'module_test',
  ]);
  $this
    ->assertFalse($this->container
    ->get('state')
    ->get(PluginManagerCacheClearer::class));
  \Drupal::service('module_installer')
    ->install([
    'dblog',
  ]);
  $this
    ->assertTrue($this->container
    ->get('state')
    ->get(PluginManagerCacheClearer::class));

  // The plugin cache clearer service should be called during dblog uninstall
  // without the dependency.
  \Drupal::service('module_installer')
    ->uninstall([
    'dblog',
  ]);
  $this
    ->assertFalse($this->container
    ->get('state')
    ->get(PluginManagerCacheClearer::class));

  // The service should not be called during module_test uninstall.
  $this->container
    ->get('state')
    ->delete(PluginManagerCacheClearer::class);
  \Drupal::service('module_installer')
    ->uninstall([
    'module_test',
  ]);
  $this
    ->assertNull($this->container
    ->get('state')
    ->get(PluginManagerCacheClearer::class));
}