SevenLayoutBuilderTest.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. namespace Drupal\FunctionalTests\Theme;
  3. use Drupal\Tests\BrowserTestBase;
  4. /**
  5. * Tests the Seven theme.
  6. *
  7. * @group seven
  8. */
  9. class SevenLayoutBuilderTest extends BrowserTestBase {
  10. /**
  11. * {@inheritdoc}
  12. */
  13. protected $defaultTheme = 'seven';
  14. /**
  15. * {@inheritdoc}
  16. */
  17. public static $modules = [
  18. 'views',
  19. 'layout_builder',
  20. 'layout_builder_views_test',
  21. 'layout_test',
  22. 'block',
  23. 'block_test',
  24. 'node',
  25. 'layout_builder_test',
  26. ];
  27. /**
  28. * {@inheritdoc}
  29. */
  30. protected function setUp() {
  31. parent::setUp();
  32. $this->drupalPlaceBlock('page_title_block', ['region' => 'header']);
  33. $this->drupalPlaceBlock('local_tasks_block', ['region' => 'header']);
  34. // Create two nodes.
  35. $this->createContentType([
  36. 'type' => 'bundle_with_section_field',
  37. 'name' => 'Bundle with section field',
  38. ]);
  39. $this->createNode([
  40. 'type' => 'bundle_with_section_field',
  41. 'title' => 'The first node title',
  42. 'body' => [
  43. [
  44. 'value' => 'The first node body',
  45. ],
  46. ],
  47. ]);
  48. $this->createNode([
  49. 'type' => 'bundle_with_section_field',
  50. 'title' => 'The second node title',
  51. 'body' => [
  52. [
  53. 'value' => 'The second node body',
  54. ],
  55. ],
  56. ]);
  57. }
  58. /**
  59. * Tests the layout builder has expected contextual links with Seven.
  60. *
  61. * @see seven.theme
  62. */
  63. public function testContextualLinks() {
  64. $assert_session = $this->assertSession();
  65. $page = $this->getSession()->getPage();
  66. $this->drupalLogin($this->drupalCreateUser([
  67. 'configure any layout',
  68. 'administer node display',
  69. 'administer node fields',
  70. 'access contextual links',
  71. ]));
  72. $field_ui_prefix = 'admin/structure/types/manage/bundle_with_section_field';
  73. // From the manage display page, go to manage the layout.
  74. $this->drupalGet("$field_ui_prefix/display/default");
  75. $assert_session->linkNotExists('Manage layout');
  76. $assert_session->fieldDisabled('layout[allow_custom]');
  77. $this->drupalPostForm(NULL, ['layout[enabled]' => TRUE], 'Save');
  78. $assert_session->linkExists('Manage layout');
  79. $this->clickLink('Manage layout');
  80. // Add a new block.
  81. $assert_session->linkExists('Add block');
  82. $this->clickLink('Add block');
  83. $assert_session->linkExists('Powered by Drupal');
  84. $this->clickLink('Powered by Drupal');
  85. $page->fillField('settings[label]', 'This is the label');
  86. $page->checkField('settings[label_display]');
  87. $page->pressButton('Add block');
  88. // Test that the block has the contextual class applied and the container
  89. // for contextual links.
  90. $assert_session->elementExists('css', 'div.block-system-powered-by-block.contextual-region div[data-contextual-id]');
  91. // Ensure other blocks do not have contextual links.
  92. $assert_session->elementExists('css', 'div.block-page-title-block');
  93. $assert_session->elementNotExists('css', 'div.block-page-title-block.contextual-region div[data-contextual-id]');
  94. }
  95. }