BlockHiddenRegionTest.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. namespace Drupal\Tests\block\Functional;
  3. use Drupal\Tests\BrowserTestBase;
  4. /**
  5. * Tests that a newly installed theme does not inherit blocks to its hidden
  6. * regions.
  7. *
  8. * @group block
  9. */
  10. class BlockHiddenRegionTest extends BrowserTestBase {
  11. /**
  12. * An administrative user to configure the test environment.
  13. */
  14. protected $adminUser;
  15. /**
  16. * Modules to install.
  17. *
  18. * @var array
  19. */
  20. public static $modules = ['block', 'block_test', 'search'];
  21. protected function setUp() {
  22. parent::setUp();
  23. // Create administrative user.
  24. $this->adminUser = $this->drupalCreateUser([
  25. 'administer blocks',
  26. 'administer themes',
  27. 'search content',
  28. ]
  29. );
  30. $this->drupalLogin($this->adminUser);
  31. $this->drupalPlaceBlock('search_form_block');
  32. $this->drupalPlaceBlock('local_tasks_block');
  33. }
  34. /**
  35. * Tests that hidden regions do not inherit blocks when a theme is installed.
  36. */
  37. public function testBlockNotInHiddenRegion() {
  38. // Ensure that the search form block is displayed.
  39. $this->drupalGet('');
  40. $this->assertText('Search', 'Block was displayed on the front page.');
  41. // Install "block_test_theme" and set it as the default theme.
  42. $theme = 'block_test_theme';
  43. // We need to install a non-hidden theme so that there is more than one
  44. // local task.
  45. \Drupal::service('theme_handler')->install([$theme, 'stark']);
  46. $this->config('system.theme')
  47. ->set('default', $theme)
  48. ->save();
  49. // Installing a theme will cause the kernel terminate event to rebuild the
  50. // router. Simulate that here.
  51. \Drupal::service('router.builder')->rebuildIfNeeded();
  52. // Ensure that "block_test_theme" is set as the default theme.
  53. $this->drupalGet('admin/structure/block');
  54. $this->assertText('Block test theme(' . t('active tab') . ')', 'Default local task on blocks admin page is the block test theme.');
  55. // Ensure that the search form block is displayed.
  56. $this->drupalGet('');
  57. $this->assertText('Search', 'Block was displayed on the front page.');
  58. }
  59. }