function BlockTemplateSuggestionsUnitTest::testBlockThemeHookSuggestions

Test if template_preprocess_block() handles the suggestions right.

File

drupal/core/modules/block/lib/Drupal/block/Tests/BlockTemplateSuggestionsUnitTest.php, line 35
Definition of Drupal\block\Tests\BlockTemplateSuggestionsUnitTest.

Class

BlockTemplateSuggestionsUnitTest
Unit tests for template_preprocess_block().

Namespace

Drupal\block\Tests

Code

function testBlockThemeHookSuggestions() {

  // Define a block with a derivative to be preprocessed, which includes both
  // an underscore (not transformed) and a hyphen (transformed to underscore),
  // and generates possibilities for each level of derivative.
  // @todo Clarify this comment.
  $block = entity_create('block', array(
    'plugin' => 'system_menu_block:menu-admin',
    'region' => 'footer',
    'id' => config('system.theme')
      ->get('default') . '.machinename',
  ));
  $variables = array();
  $variables['elements']['#block'] = $block;
  $variables['elements']['#configuration'] = $block
    ->getPlugin()
    ->getConfig();
  $variables['elements']['#plugin_id'] = $block
    ->get('plugin');
  $variables['elements']['content'] = array();

  // Test adding a class to the block content.
  $variables['content_attributes']['class'][] = 'test-class';
  template_preprocess_block($variables);
  $this
    ->assertEqual($variables['theme_hook_suggestions'], array(
    'block__system',
    'block__system_menu_block',
    'block__system_menu_block__menu_admin',
    'block__machinename',
  ));
  $this
    ->assertEqual($variables['content_attributes']['class'], array(
    'test-class',
    'content',
  ), 'Default .content class added to block content_attributes');
}