BlockAdminThemeTest.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. namespace Drupal\Tests\block\Functional;
  3. use Drupal\Tests\BrowserTestBase;
  4. /**
  5. * Tests the block system with admin themes.
  6. *
  7. * @group block
  8. */
  9. class BlockAdminThemeTest extends BrowserTestBase {
  10. /**
  11. * Modules to install.
  12. *
  13. * @var array
  14. */
  15. public static $modules = ['block', 'contextual'];
  16. /**
  17. * Check for the accessibility of the admin theme on the block admin page.
  18. */
  19. public function testAdminTheme() {
  20. // Create administrative user.
  21. $admin_user = $this->drupalCreateUser(['administer blocks', 'administer themes']);
  22. $this->drupalLogin($admin_user);
  23. // Ensure that access to block admin page is denied when theme is not
  24. // installed.
  25. $this->drupalGet('admin/structure/block/list/bartik');
  26. $this->assertResponse(403);
  27. // Install admin theme and confirm that tab is accessible.
  28. \Drupal::service('theme_handler')->install(['bartik']);
  29. $edit['admin_theme'] = 'bartik';
  30. $this->drupalPostForm('admin/appearance', $edit, t('Save configuration'));
  31. $this->drupalGet('admin/structure/block/list/bartik');
  32. $this->assertResponse(200);
  33. }
  34. /**
  35. * Ensure contextual links are disabled in Seven theme.
  36. */
  37. public function testSevenAdminTheme() {
  38. // Create administrative user.
  39. $admin_user = $this->drupalCreateUser([
  40. 'access administration pages',
  41. 'administer themes',
  42. 'access contextual links',
  43. 'view the administration theme',
  44. ]);
  45. $this->drupalLogin($admin_user);
  46. // Install admin theme and confirm that tab is accessible.
  47. \Drupal::service('theme_handler')->install(['seven']);
  48. $edit['admin_theme'] = 'seven';
  49. $this->drupalPostForm('admin/appearance', $edit, t('Save configuration'));
  50. // Define our block settings.
  51. $settings = [
  52. 'theme' => 'seven',
  53. 'region' => 'header',
  54. ];
  55. // Place a block.
  56. $block = $this->drupalPlaceBlock('local_tasks_block', $settings);
  57. // Open admin page.
  58. $this->drupalGet('admin');
  59. // Check if contextual link classes are unavailable.
  60. $this->assertNoRaw('<div data-contextual-id="block:block=' . $block->id() . ':langcode=en"></div>');
  61. $this->assertNoRaw('contextual-region');
  62. }
  63. }