3 namespace Drupal\Tests\block\Functional;
5 use Drupal\block\Entity\Block;
6 use Drupal\Tests\BrowserTestBase;
9 * Tests the block_theme_suggestions_block() function.
13 class BlockTemplateSuggestionsTest extends BrowserTestBase {
20 public static $modules = ['block'];
23 * Tests template suggestions from block_theme_suggestions_block().
25 public function testBlockThemeHookSuggestions() {
26 // Define a block with a derivative to be preprocessed, which includes both
27 // an underscore (not transformed) and a hyphen (transformed to underscore),
28 // and generates possibilities for each level of derivative.
29 // @todo Clarify this comment.
30 $block = Block::create([
31 'plugin' => 'system_menu_block:admin',
33 'id' => 'machinename',
37 $plugin = $block->getPlugin();
38 $variables['elements']['#configuration'] = $plugin->getConfiguration();
39 $variables['elements']['#plugin_id'] = $plugin->getPluginId();
40 $variables['elements']['#id'] = $block->id();
41 $variables['elements']['#base_plugin_id'] = $plugin->getBaseId();
42 $variables['elements']['#derivative_plugin_id'] = $plugin->getDerivativeId();
43 $variables['elements']['content'] = [];
44 $suggestions = block_theme_suggestions_block($variables);
45 $this->assertEqual($suggestions, ['block__system', 'block__system_menu_block', 'block__system_menu_block__admin', 'block__machinename']);