You are here

public function BlockUiTest::testBlockPlacementIndicator in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/block/tests/src/Functional/BlockUiTest.php \Drupal\Tests\block\Functional\BlockUiTest::testBlockPlacementIndicator()
  2. 9 core/modules/block/tests/src/Functional/BlockUiTest.php \Drupal\Tests\block\Functional\BlockUiTest::testBlockPlacementIndicator()

Tests the block placement indicator.

File

core/modules/block/tests/src/Functional/BlockUiTest.php, line 302

Class

BlockUiTest
Tests that the block configuration UI exists and stores data correctly.

Namespace

Drupal\Tests\block\Functional

Code

public function testBlockPlacementIndicator() {

  // Test the block placement indicator with using the domain as URL language
  // indicator. This causes destination query parameters to be absolute URLs.
  \Drupal::service('module_installer')
    ->install([
    'language',
    'locale',
  ]);
  $this->container = \Drupal::getContainer();
  ConfigurableLanguage::createFromLangcode('it')
    ->save();
  $config = $this
    ->config('language.types');
  $config
    ->set('negotiation.language_interface.enabled', [
    LanguageNegotiationUrl::METHOD_ID => -10,
  ]);
  $config
    ->save();
  $config = $this
    ->config('language.negotiation');
  $config
    ->set('url.source', LanguageNegotiationUrl::CONFIG_DOMAIN);
  $config
    ->set('url.domains', [
    'en' => \Drupal::request()
      ->getHost(),
    'it' => 'it.example.com',
  ]);
  $config
    ->save();

  // Select the 'Powered by Drupal' block to be placed.
  $block = [];
  $block['id'] = strtolower($this
    ->randomMachineName());
  $block['theme'] = 'stark';
  $block['region'] = 'content';

  // After adding a block, it will indicate which block was just added.
  $this
    ->drupalGet('admin/structure/block/add/system_powered_by_block');
  $this
    ->submitForm($block, 'Save block');
  $this
    ->assertSession()
    ->addressEquals('admin/structure/block/list/stark?block-placement=' . Html::getClass($block['id']));

  // Resaving the block page will remove the block placement indicator.
  $this
    ->submitForm([], 'Save blocks');
  $this
    ->assertSession()
    ->addressEquals('admin/structure/block/list/stark');

  // Place another block and test the remove functionality works with the
  // block placement indicator. Click the first 'Place block' link to bring up
  // the list of blocks to place in the first available region.
  $this
    ->clickLink('Place block');

  // Select the first available block, which is the 'test_xss_title' plugin,
  // with a default machine name 'scriptalertxsssubjectscript' that is used
  // for the 'block-placement' querystring parameter.
  $this
    ->clickLink('Place block');
  $this
    ->submitForm([], 'Save block');
  $this
    ->assertSession()
    ->addressEquals('admin/structure/block/list/stark?block-placement=scriptalertxsssubjectscript');

  // Removing a block will remove the block placement indicator.
  $this
    ->clickLink('Remove');
  $this
    ->submitForm([], 'Remove');

  // @todo https://www.drupal.org/project/drupal/issues/2980527 this should be
  //   'admin/structure/block/list/stark' but there is a bug.
  $this
    ->assertSession()
    ->addressEquals('admin/structure/block');
}