You are here

public function BlockUiTest::testCandidateBlockList in Drupal 9

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

Tests the block categories on the listing page.

File

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

Class

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

Namespace

Drupal\Tests\block\Functional

Code

public function testCandidateBlockList() {
  $arguments = [
    ':title' => 'Display message',
    ':category' => 'Block test',
    ':href' => 'admin/structure/block/add/test_block_instantiation/classy',
  ];
  $pattern = '//tr[.//td/div[text()=:title] and .//td[text()=:category] and .//td//a[contains(@href, :href)]]';
  $this
    ->drupalGet('admin/structure/block');
  $this
    ->clickLink('Place block');
  $elements = $this
    ->xpath($pattern, $arguments);
  $this
    ->assertTrue(!empty($elements), 'The test block appears in the category for its module.');

  // Trigger the custom category addition in block_test_block_alter().
  $this->container
    ->get('state')
    ->set('block_test_info_alter', TRUE);
  $this->container
    ->get('plugin.manager.block')
    ->clearCachedDefinitions();
  $this
    ->drupalGet('admin/structure/block');
  $this
    ->clickLink('Place block');
  $arguments[':category'] = 'Custom category';
  $elements = $this
    ->xpath($pattern, $arguments);
  $this
    ->assertTrue(!empty($elements), 'The test block appears in a custom category controlled by block_test_block_alter().');
}