You are here

public function BlockStyleTest::testThemeSuggestion in Block Style Plugins 8

Same name and namespace in other branches
  1. 8.2 tests/src/Unit/Plugin/BlockStyleTest.php \Drupal\Tests\block_style_plugins\Unit\Plugin\BlockStyleTest::testThemeSuggestion()

Tests the themeSuggestion method.

See also

::themeSuggestion()

File

tests/src/Unit/Plugin/BlockStyleTest.php, line 153

Class

BlockStyleTest
@coversDefaultClass \Drupal\block_style_plugins\Plugin\BlockStyle @group block_style_plugins

Namespace

Drupal\Tests\block_style_plugins\Unit\Plugin

Code

public function testThemeSuggestion() {
  $block = $this
    ->prophesize(ConfigEntityInterface::CLASS);
  $storage = $this
    ->prophesize(EntityStorageInterface::CLASS);
  $storage
    ->load(1)
    ->willReturn($block
    ->reveal());
  $this->entityTypeManager
    ->getStorage('block')
    ->willReturn($storage
    ->reveal());

  // Return the third party styles set in the plugin.
  $block
    ->getThirdPartySetting('block_style_plugins', 'block_style_plugins')
    ->willReturn([
    'class1',
    'class2',
  ]);

  // Use reflection to alter the protected $this->plugin->pluginDefinition.
  $reflectionObject = new \ReflectionObject($this->plugin);
  $property = $reflectionObject
    ->getProperty('pluginDefinition');
  $property
    ->setAccessible(TRUE);
  $property
    ->setValue($this->plugin, [
    'template' => 'custom_template',
  ]);
  $suggestions = [];
  $variables = [
    'elements' => [
      '#id' => 1,
    ],
  ];
  $expected = [
    'custom_template',
  ];
  $return = $this->plugin
    ->themeSuggestion($suggestions, $variables);
  $this
    ->assertArrayEquals($expected, $return);
}