public function BlockStyleBaseTest::testBuild in Block Style Plugins 8
Same name and namespace in other branches
- 8.2 tests/src/Unit/Plugin/BlockStyleBaseTest.php \Drupal\Tests\block_style_plugins\Unit\Plugin\BlockStyleBaseTest::testBuild()
Tests the build method.
@TODO Create a provider so that more combinations can be tested.
See also
::build()
File
- tests/
src/ Unit/ Plugin/ BlockStyleBaseTest.php, line 232
Class
- BlockStyleBaseTest
- @coversDefaultClass \Drupal\block_style_plugins\Plugin\BlockStyleBase @group block_style_plugins
Namespace
Drupal\Tests\block_style_plugins\Unit\PluginCode
public function testBuild() {
$block = $this
->prophesize(ConfigEntityInterface::CLASS);
$storage = $this
->prophesize(EntityStorageInterface::CLASS);
$storage
->load(1)
->willReturn($block
->reveal());
$this->entityTypeManager
->getStorage('block')
->willReturn($storage
->reveal());
// No element ID is passed through the variables.
$variables = [];
$return = $this->plugin
->build($variables);
$this
->assertArrayEquals($variables, $return);
// No styles attached to the block.
$block
->getThirdPartySetting('block_style_plugins', 'block_style_plugins')
->willReturn(FALSE);
$variables = [
'elements' => [
'#id' => 1,
],
];
$return = $this->plugin
->build($variables);
$this
->assertArrayEquals($variables, $return);
// Return the third party styles set in the plugin.
$block
->getThirdPartySetting('block_style_plugins', 'block_style_plugins')
->willReturn([
'class1',
'class2',
]);
$variables = [
'elements' => [
'#id' => 1,
],
];
$expected = [
'elements' => [
'#id' => 1,
],
'block_styles' => [
'block_style_plugins' => [
'class1',
'class2',
],
],
'attributes' => [
'class' => [
'class1',
'class2',
],
],
];
$return = $this->plugin
->build($variables);
$this
->assertArrayEquals($expected, $return);
// Don't set a class for integers.
$block
->getThirdPartySetting('block_style_plugins', 'block_style_plugins')
->willReturn([
'class1',
1,
'class2',
0,
]);
$variables = [
'elements' => [
'#id' => 1,
],
];
$expected = [
'elements' => [
'#id' => 1,
],
'block_styles' => [
'block_style_plugins' => [
'class1',
1,
'class2',
0,
],
],
'attributes' => [
'class' => [
'class1',
'class2',
],
],
];
$return = $this->plugin
->build($variables);
$this
->assertArrayEquals($expected, $return);
}