BlockBaseTest.php 1.82 KB
Newer Older
1 2 3 4
<?php

/**
 * @file
5
 * Contains \Drupal\block\Tests\BlockBaseTest.
6 7
 */

8
namespace Drupal\block\Tests;
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61

use Drupal\block_test\Plugin\Block\TestBlockInstantiation;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\Transliteration\PHPTransliteration;
use Drupal\Tests\UnitTestCase;

// @todo Remove once the constants are replaced with constants on classes.
if (!defined('DRUPAL_NO_CACHE')) {
  define('DRUPAL_NO_CACHE', -1);
}

/**
 * Tests the base block plugin.
 *
 * @see \Drupal\block\BlockBase
 */
class BlockBaseTest extends UnitTestCase {

  public static function getInfo() {
    return array(
      'name' => 'Base plugin',
      'description' => 'Tests the base block plugin.',
      'group' => 'Block',
    );
  }

  /**
   * Tests the machine name suggestion.
   *
   * @see \Drupal\block\BlockBase::getMachineNameSuggestion().
   */
  public function testGetMachineNameSuggestion() {
    $transliteraton = $this->getMockBuilder('Drupal\Core\Transliteration\PHPTransliteration')
      // @todo Inject the module handler into PHPTransliteration.
      ->setMethods(array('readLanguageOverrides'))
      ->getMock();

    $container = new ContainerBuilder();
    $container->set('transliteration', $transliteraton);
    \Drupal::setContainer($container);

    $config = array();
    $definition = array('admin_label' => 'Admin label', 'module' => 'block_test');
    $block_base = new TestBlockInstantiation($config, 'test_block_instantiation', $definition);
    $this->assertEquals('adminlabel', $block_base->getMachineNameSuggestion());

    // Test with more unicodes.
    $definition = array('admin_label' =>'über åwesome', 'module' => 'block_test');
    $block_base = new TestBlockInstantiation($config, 'test_block_instantiation', $definition);
    $this->assertEquals('uberawesome', $block_base->getMachineNameSuggestion());
  }

}