class BigPipeInterfacePreviewThemeSuggestionsTest
Same name and namespace in other branches
- 11.x core/modules/big_pipe/tests/src/Kernel/BigPipeInterfacePreviewThemeSuggestionsTest.php \Drupal\Tests\big_pipe\Kernel\BigPipeInterfacePreviewThemeSuggestionsTest
- 10 core/modules/big_pipe/tests/src/Kernel/BigPipeInterfacePreviewThemeSuggestionsTest.php \Drupal\Tests\big_pipe\Kernel\BigPipeInterfacePreviewThemeSuggestionsTest
Tests the big pipe theme suggestions.
Attributes
#[Group('big_pipe')]
#[RunTestsInSeparateProcesses]
Hierarchy
- class \Drupal\KernelTests\KernelTestBase implements \Drupal\Core\DependencyInjection\ServiceProviderInterface uses \Drupal\Tests\DrupalTestCaseTrait, \Drupal\KernelTests\AssertContentTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\ExtensionListTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\PhpUnitCompatibilityTrait, \Prophecy\PhpUnit\ProphecyTrait, \Drupal\TestTools\Extension\DeprecationBridge\ExpectDeprecationTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\big_pipe\Kernel\BigPipeInterfacePreviewThemeSuggestionsTest extends \Drupal\KernelTests\KernelTestBase
Expanded class hierarchy of BigPipeInterfacePreviewThemeSuggestionsTest
File
-
core/
modules/ big_pipe/ tests/ src/ Kernel/ BigPipeInterfacePreviewThemeSuggestionsTest.php, line 15
Namespace
Drupal\Tests\big_pipe\KernelView source
class BigPipeInterfacePreviewThemeSuggestionsTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = [
'block',
'big_pipe',
'system',
];
/**
* The block being tested.
*
* @var \Drupal\block\Entity\BlockInterface
*/
protected $block;
/**
* The block storage.
*
* @var \Drupal\Core\Config\Entity\ConfigEntityStorageInterface
*/
protected $controller;
/**
* The block view builder.
*
* @var \Drupal\block\BlockViewBuilder
*/
protected $blockViewBuilder;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$this->controller = $this->container
->get('entity_type.manager')
->getStorage('block');
$this->blockViewBuilder = $this->container
->get('entity_type.manager')
->getViewBuilder('block');
$this->container
->get('theme_installer')
->install([
'stark',
]);
}
/**
* Tests theme suggestions from big_pipe.
*/
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().
$variables['callback'] = $build['#lazy_builder'][0];
$variables['arguments'] = $build['#lazy_builder'][1];
$module_handler = $this->container
->get('module_handler');
$suggestions = $module_handler->invoke('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.