diff --git a/core/modules/block/lib/Drupal/block/Tests/BlockUiTest.php b/core/modules/block/lib/Drupal/block/Tests/BlockUiTest.php index b5df464..95cab30 100644 --- a/core/modules/block/lib/Drupal/block/Tests/BlockUiTest.php +++ b/core/modules/block/lib/Drupal/block/Tests/BlockUiTest.php @@ -106,6 +106,30 @@ function testBlockAdminUiPage() { } /** + * Tests the block categories on the listing page. + */ + public function testCandidateBlockList() { + $arguments = array( + ':ul_class' => 'block-list', + ':li_class' => 'test-block-instantiation', + ':href' => 'admin/structure/block/add/test_block_instantiation/stark', + ':text' => 'Display message', + ); + + $this->drupalGet('admin/structure/block'); + $elements = $this->xpath('//details[@id="edit-block-test"]//ul[contains(@class, :ul_class)]/li[contains(@class, :li_class)]/a[contains(@href, :href) and text()=:text]', $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'); + $elements = $this->xpath('//details[@id="edit-custom-category"]//ul[contains(@class, :ul_class)]/li[contains(@class, :li_class)]/a[contains(@href, :href) and text()=:text]', $arguments); + $this->assertTrue(!empty($elements), 'The test block appears in a custom category controlled by block_test_block_alter().'); + } + + /** * Tests that the BlockFormController populates machine name correctly. */ public function testMachineNameSuggestion() { diff --git a/core/modules/block/tests/modules/block_test/block_test.module b/core/modules/block/tests/modules/block_test/block_test.module index 6abb95f..5184454 100644 --- a/core/modules/block/tests/modules/block_test/block_test.module +++ b/core/modules/block/tests/modules/block_test/block_test.module @@ -12,3 +12,12 @@ function block_test_system_theme_info() { $themes['block_test_theme'] = drupal_get_path('module', 'block_test') . '/themes/block_test_theme/block_test_theme.info.yml'; return $themes; } + +/** + * Implements hook_block_alter(). + */ +function block_test_block_alter(&$block_info) { + if (Drupal::state()->get('block_test_info_alter') && isset($block_info['test_block_instantiation'])) { + $block_info['test_block_instantiation']['category'] = t('Custom category'); + } +}