diff --git a/core/modules/block/lib/Drupal/block/Tests/BlockViewAlterTest.php b/core/modules/block/lib/Drupal/block/Tests/BlockViewAlterTest.php new file mode 100644 index 0000000..3a51645 --- /dev/null +++ b/core/modules/block/lib/Drupal/block/Tests/BlockViewAlterTest.php @@ -0,0 +1,51 @@ + 'Block view alter hook', + 'description' => 'Test the hook block view alter hooks.', + 'group' => 'Block', + ); + } + + function setUp() { + parent::setUp(); + + $this->drupalLogin($this->root_user); + } + + /** + * Tests if the view alter function is called when the block ID or machine + * name contains a hyphen. + */ + function testHyphen() { + // Enable our test blocks. + $this->drupalPlaceBlock('test-id-hyphen', array('machine_name' => 'test-name-hyphen')); + + $this->drupalGet(''); + $this->assertText('hook_block_view_ID_alter() invoked.'); + $this->assertText('hook_block_view_NAME_alter() invoked.'); + } + +} diff --git a/core/modules/block/tests/block_test.module b/core/modules/block/tests/block_test.module index 6abb95f..4885e12 100644 --- a/core/modules/block/tests/block_test.module +++ b/core/modules/block/tests/block_test.module @@ -12,3 +12,17 @@ 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_view_ID_alter(). + */ +function block_test_block_view_test_id_hyphen_alter(array &$build, Drupal\block\Plugin\Core\Entity\Block $block) { + $build['content']['#children'] .= 'hook_block_view_ID_alter() invoked.'; +} + +/** + * Implements hook_block_view_NAME_alter(). + */ +function block_test_block_view_test_name_hyphen_alter(array &$build, Drupal\block\Plugin\Core\Entity\Block $block) { + $build['content']['#children'] .= 'hook_block_view_NAME_alter() invoked.'; +} diff --git a/core/modules/block/tests/lib/Drupal/block_test/Plugin/block/block/TestViewAlterBlock.php b/core/modules/block/tests/lib/Drupal/block_test/Plugin/block/block/TestViewAlterBlock.php new file mode 100644 index 0000000..0b14489 --- /dev/null +++ b/core/modules/block/tests/lib/Drupal/block_test/Plugin/block/block/TestViewAlterBlock.php @@ -0,0 +1,34 @@ + state()->get('block_test.content'), + ); + } + +}