function BlockTemplateSuggestionsTest::testBlockThemeHookSuggestions

Same name and namespace in other branches
  1. 9 core/modules/block/tests/src/Kernel/BlockTemplateSuggestionsTest.php \Drupal\Tests\block\Kernel\BlockTemplateSuggestionsTest::testBlockThemeHookSuggestions()
  2. 10 core/modules/block_content/tests/src/Kernel/BlockTemplateSuggestionsTest.php \Drupal\Tests\block_content\Kernel\BlockTemplateSuggestionsTest::testBlockThemeHookSuggestions()
  3. 10 core/modules/block/tests/src/Kernel/BlockTemplateSuggestionsTest.php \Drupal\Tests\block\Kernel\BlockTemplateSuggestionsTest::testBlockThemeHookSuggestions()
  4. 11.x core/modules/block_content/tests/src/Kernel/BlockTemplateSuggestionsTest.php \Drupal\Tests\block_content\Kernel\BlockTemplateSuggestionsTest::testBlockThemeHookSuggestions()
  5. 11.x core/modules/block/tests/src/Kernel/BlockTemplateSuggestionsTest.php \Drupal\Tests\block\Kernel\BlockTemplateSuggestionsTest::testBlockThemeHookSuggestions()

Tests template suggestions from block_theme_suggestions_block().

File

core/modules/block/tests/src/Kernel/BlockTemplateSuggestionsTest.php, line 26

Class

BlockTemplateSuggestionsTest
Tests the <a href="/api/drupal/core%21modules%21block%21block.module/function/block_theme_suggestions_block/8.9.x" title="Implements hook_theme_suggestions_HOOK()." class="local">block_theme_suggestions_block</a>() function.

Namespace

Drupal\Tests\block\Kernel

Code

public function testBlockThemeHookSuggestions() {
    $this->installConfig([
        'system',
    ]);
    // Create a block using a plugin with derivative to be preprocessed.
    $block = Block::create([
        'plugin' => 'system_menu_block:admin',
        'region' => 'footer',
        'id' => 'machinename',
    ]);
    $variables = [];
    
    /** @var \Drupal\Core\Block\BlockPluginInterface $plugin */
    $plugin = $block->getPlugin();
    $variables['elements']['#configuration'] = $plugin->getConfiguration();
    $variables['elements']['#plugin_id'] = $plugin->getPluginId();
    $variables['elements']['#id'] = $block->id();
    $variables['elements']['#base_plugin_id'] = $plugin->getBaseId();
    $variables['elements']['#derivative_plugin_id'] = $plugin->getDerivativeId();
    $variables['elements']['content'] = [];
    $suggestions = block_theme_suggestions_block($variables);
    $this->assertSame([
        'block__system',
        'block__system_menu_block',
        'block__system_menu_block__admin',
        'block__machinename',
    ], $suggestions);
}

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