function BigPipeInterfacePreviewThemeSuggestionsTest::testBigPipeThemeHookSuggestions

Same name and namespace in other branches
  1. 10 core/modules/big_pipe/tests/src/Kernel/BigPipeInterfacePreviewThemeSuggestionsTest.php \Drupal\Tests\big_pipe\Kernel\BigPipeInterfacePreviewThemeSuggestionsTest::testBigPipeThemeHookSuggestions()

Tests template suggestions from big_pipe_theme_suggestions_big_pipe_interface_preview().

File

core/modules/big_pipe/tests/src/Kernel/BigPipeInterfacePreviewThemeSuggestionsTest.php, line 63

Class

BigPipeInterfacePreviewThemeSuggestionsTest
Tests the <a href="/api/drupal/core%21modules%21big_pipe%21big_pipe.module/function/big_pipe_theme_suggestions_big_pipe_interface_preview/11.x" title="Implements hook_theme_suggestions_HOOK()." class="local">big_pipe_theme_suggestions_big_pipe_interface_preview</a>() function.

Namespace

Drupal\Tests\big_pipe\Kernel

Code

public function testBigPipeThemeHookSuggestions() : void {
    $entity = $this->controller
        ->create([
        'id' => 'test_block1',
        'theme' => 'stark',
        'plugin' => 'system_powered_by_block',
    ]);
    $entity->save();
    // Test the rendering of a block.
    $block = Block::load('test_block1');
    // Using the BlockViewBuilder we will be able to get a lovely
    // #lazy_builder callback assigned.
    $build = $this->blockViewBuilder
        ->view($block);
    $variables = [];
    // In turn this is what createBigPipeJsPlaceholder() uses to
    // build the BigPipe JS placeholder render array which is used as input
    // for big_pipe_theme_suggestions_big_pipe_interface_preview().
    $variables['callback'] = $build['#lazy_builder'][0];
    $variables['arguments'] = $build['#lazy_builder'][1];
    $suggestions = big_pipe_theme_suggestions_big_pipe_interface_preview($variables);
    $suggested_id = preg_replace('/[^a-zA-Z0-9]/', '_', $block->id());
    $this->assertSame([
        'big_pipe_interface_preview__block',
        'big_pipe_interface_preview__block__' . $suggested_id,
        'big_pipe_interface_preview__block__full',
    ], $suggestions);
}

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