BlockDemoTest.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace Drupal\Tests\block\Functional;
  3. use Drupal\Tests\BrowserTestBase;
  4. /**
  5. * Tests the block demo page with admin themes.
  6. *
  7. * @group block
  8. */
  9. class BlockDemoTest extends BrowserTestBase {
  10. /**
  11. * Modules to enable.
  12. *
  13. * @var array
  14. */
  15. public static $modules = ['block'];
  16. /**
  17. * Check for the accessibility of the admin block demo page.
  18. */
  19. public function testBlockDemo() {
  20. // Create administrative user.
  21. $admin_user = $this->drupalCreateUser(['administer blocks', 'administer themes']);
  22. $this->drupalLogin($admin_user);
  23. // Confirm we have access to the block demo page for the default theme.
  24. $config = $this->container->get('config.factory')->get('system.theme');
  25. $default_theme = $config->get('default');
  26. $this->drupalGet('admin/structure/block/demo/' . $default_theme);
  27. $this->assertResponse(200);
  28. $this->assertLinkByHref('admin/structure/block');
  29. $this->assertNoLinkByHref('admin/structure/block/list/' . $default_theme);
  30. // All available themes in core.
  31. $available_themes = [
  32. 'bartik',
  33. 'classy',
  34. 'seven',
  35. 'stark',
  36. ];
  37. // All available themes minute minus the default theme.
  38. $themes = array_diff($available_themes, [$default_theme]);
  39. foreach ($themes as $theme) {
  40. // Install theme.
  41. $this->container->get('theme_handler')->install([$theme]);
  42. // Confirm access to the block demo page for the theme.
  43. $this->drupalGet('admin/structure/block/demo/' . $theme);
  44. $this->assertResponse(200);
  45. // Confirm existence of link for "Exit block region demonstration".
  46. $this->assertLinkByHref('admin/structure/block/list/' . $theme);
  47. }
  48. // Confirm access to the block demo page is denied for an invalid theme.
  49. $this->drupalGet('admin/structure/block/demo/invalid_theme');
  50. $this->assertResponse(403);
  51. }
  52. }