function BlockTemplateSuggestionsTest::testBlockThemeHookSuggestions

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

Tests template suggestions from block_content_theme_suggestions_block().

File

core/modules/block_content/tests/src/Kernel/BlockTemplateSuggestionsTest.php, line 63

Class

BlockTemplateSuggestionsTest
Tests the block_content_theme_suggestions_block() function.

Namespace

Drupal\Tests\block_content\Kernel

Code

public function testBlockThemeHookSuggestions() : void {
    // Create a block using a block_content plugin.
    $block = Block::create([
        'plugin' => 'block_content:' . $this->blockContent
            ->uuid(),
        'region' => 'footer',
        'id' => 'machine_name',
    ]);
    $variables['elements']['#id'] = $block->id();
    $variables['elements']['#configuration']['provider'] = 'block_content';
    $variables['elements']['#configuration']['view_mode'] = 'full';
    $variables['elements']['content']['#block_content'] = $this->blockContent;
    $suggestions_empty = [];
    $suggestions_empty[] = 'block__block_content__' . $block->uuid();
    $blockTemplateSuggestionsAlter = new BlockContentHooks();
    $suggestions = $blockTemplateSuggestionsAlter->themeSuggestionsBlockAlter($suggestions_empty, $variables);
    $this->assertSame([
        'block__block_content__' . $block->uuid(),
        'block__block_content__view__full',
        'block__block_content__type__test_block',
        'block__block_content__view_type__test_block__full',
        'block__block_content__id__machine_name',
        'block__block_content__id_view__machine_name__full',
    ], $suggestions);
}

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