You are here

public function BlockBaseTest::testGetMachineNameSuggestion in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Block/BlockBaseTest.php \Drupal\Tests\Core\Block\BlockBaseTest::testGetMachineNameSuggestion()

Tests the machine name suggestion.

@dataProvider providerTestGetMachineNameSuggestion()

Parameters

string $label: The block label.

string $expected: The expected machine name.

See also

\Drupal\Core\Block\BlockBase::getMachineNameSuggestion()

File

core/tests/Drupal/Tests/Core/Block/BlockBaseTest.php, line 26

Class

BlockBaseTest
@coversDefaultClass \Drupal\Core\Block\BlockBase @group block

Namespace

Drupal\Tests\Core\Block

Code

public function testGetMachineNameSuggestion($label, $expected) {
  $module_handler = $this
    ->createMock('Drupal\\Core\\Extension\\ModuleHandlerInterface');
  $transliteration = $this
    ->getMockBuilder('Drupal\\Core\\Transliteration\\PhpTransliteration')
    ->setConstructorArgs([
    NULL,
    $module_handler,
  ])
    ->setMethods([
    'readLanguageOverrides',
  ])
    ->getMock();
  $config = [];
  $definition = [
    'admin_label' => $label,
    'provider' => 'block_test',
  ];
  $block_base = new TestBlockInstantiation($config, 'test_block_instantiation', $definition);
  $block_base
    ->setTransliteration($transliteration);
  $this
    ->assertEquals($expected, $block_base
    ->getMachineNameSuggestion());
}