function BlockTest::testUninstallTheme

Same name and namespace in other branches
  1. 8.9.x core/modules/block/tests/src/Functional/BlockTest.php \Drupal\Tests\block\Functional\BlockTest::testUninstallTheme()
  2. 10 core/modules/block/tests/src/Functional/BlockTest.php \Drupal\Tests\block\Functional\BlockTest::testUninstallTheme()
  3. 11.x core/modules/block/tests/src/Functional/BlockTest.php \Drupal\Tests\block\Functional\BlockTest::testUninstallTheme()

Tests that uninstalling a theme removes its block configuration.

File

core/modules/block/tests/src/Functional/BlockTest.php, line 528

Class

BlockTest
Tests basic block functionality.

Namespace

Drupal\Tests\block\Functional

Code

public function testUninstallTheme() {
    
    /** @var \Drupal\Core\Extension\ThemeInstallerInterface $theme_installer */
    $theme_installer = \Drupal::service('theme_installer');
    $theme_installer->install([
        'claro',
    ]);
    $this->config('system.theme')
        ->set('default', 'claro')
        ->save();
    $block = $this->drupalPlaceBlock('system_powered_by_block', [
        'theme' => 'claro',
        'region' => 'help',
    ]);
    $this->drupalGet('<front>');
    $this->assertSession()
        ->pageTextContains('Powered by Drupal');
    $this->config('system.theme')
        ->set('default', 'stark')
        ->save();
    $theme_installer->uninstall([
        'claro',
    ]);
    // Ensure that the block configuration does not exist anymore.
    $this->assertNull(Block::load($block->id()));
}

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