BlockPreprocessUnitTest.php 1.72 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
<?php

/**
 * @file
 * Contains \Drupal\block\Tests\BlockPreprocessUnitTest.
 */

namespace Drupal\block\Tests;

use Drupal\simpletest\WebTestBase;

/**
13 14 15
 * Tests the template_preprocess_block() function.
 *
 * @group block
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
 */
class BlockPreprocessUnitTest extends WebTestBase {

  /**
   * Modules to enable.
   *
   * @var array
   */
  public static $modules = array('block');

  /**
   * Tests block classes with template_preprocess_block().
   */
  function testBlockClasses() {
    // 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.
34
    /** @var \Drupal\block\BlockInterface $block */
35 36 37 38 39 40 41 42
    $block = entity_create('block', array(
      'plugin' => 'system_menu_block:admin',
      'region' => 'footer',
      'id' => \Drupal::config('system.theme')->get('default') . '.machinename',
    ));

    $variables = array();
    $variables['elements']['#block'] = $block;
43 44 45
    $plugin = $block->getPlugin();
    $variables['elements']['#configuration'] = $plugin->getConfiguration();
    $variables['elements']['#plugin_id'] = $plugin->getPluginId();
46
    $variables['elements']['#base_plugin_id'] = $plugin->getBaseId();
47
    $variables['elements']['#derivative_plugin_id'] = $plugin->getDerivativeId();
48
    $variables['elements']['content'] = array();
49

50 51 52
    // Test adding a class to the block content.
    $variables['content_attributes']['class'][] = 'test-class';
    template_preprocess_block($variables);
53
    $this->assertEqual($variables['content_attributes']['class'], array('test-class'), 'Test-class class added to block content_attributes');
54 55 56
  }

}