function BlockUiTest::testCandidateBlockList

Tests the block categories on the listing page.

File

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

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().');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.