You are here

public function SettingsTrayTest::testOptOut in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/settings_tray/tests/src/Functional/SettingsTrayTest.php \Drupal\Tests\settings_tray\Functional\SettingsTrayTest::testOptOut()

Tests that certain blocks opt out from Settings Tray.

File

core/modules/settings_tray/tests/src/Functional/SettingsTrayTest.php, line 88

Class

SettingsTrayTest
Tests opening and saving block forms in the off-canvas dialog.

Namespace

Drupal\Tests\settings_tray\Functional

Code

public function testOptOut() {
  $web_assert = $this
    ->assertSession();
  $non_excluded_block = $this
    ->placeBlock('system_powered_by_block');
  $excluded_block_plugin_ids = [
    'page_title_block',
    'system_main_block',
    'settings_tray_test_false',
  ];
  $block_selectors = [];

  // Place blocks that should be excluded.
  foreach ($excluded_block_plugin_ids as $excluded_block_plugin_id) {

    // The block HTML 'id' attribute will be "block-[block_id]".
    $block_selectors[] = $this
      ->getBlockSelector($this
      ->placeBlock($excluded_block_plugin_id));
  }
  $this
    ->drupalGet('');

  // Assert that block has been marked as "editable" and contextual that
  // should exist does.
  $web_assert
    ->elementExists('css', $this
    ->getBlockSelector($non_excluded_block) . "[data-drupal-settingstray=\"editable\"]");

  // Assert that each block that has a "forms[settings_tray] = FALSE" annotation:
  // - is still rendered on the page
  // - but is not marked as "editable" by settings_tray_preprocess_block()
  // - and does not have the Settings Tray contextual link.
  foreach ($block_selectors as $block_selector) {
    $web_assert
      ->elementExists('css', $block_selector);
    $web_assert
      ->elementNotExists('css', "{$block_selector}[data-drupal-settingstray=\"editable\"]");
    $web_assert
      ->elementNotExists('css', "{$block_selector} [data-settings-tray-edit]");
  }
}