function BlockBaseTest::testGetMachineNameSuggestion

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Block/BlockBaseTest.php \Drupal\Tests\Core\Block\BlockBaseTest::testGetMachineNameSuggestion()
  2. 8.9.x core/tests/Drupal/Tests/Core/Block/BlockBaseTest.php \Drupal\Tests\Core\Block\BlockBaseTest::testGetMachineNameSuggestion()
  3. 10 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 30

Class

BlockBaseTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Block%21BlockBase.php/class/BlockBase/11.x" title="Defines a base block implementation that most blocks plugins will extend." class="local">\Drupal\Core\Block\BlockBase</a> @group block

Namespace

Drupal\Tests\Core\Block

Code

public function testGetMachineNameSuggestion($label, $expected) : void {
    $module_handler = $this->createMock('Drupal\\Core\\Extension\\ModuleHandlerInterface');
    $transliteration = $this->getMockBuilder('Drupal\\Core\\Transliteration\\PhpTransliteration')
        ->setConstructorArgs([
        NULL,
        $module_handler,
    ])
        ->onlyMethods([
        '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());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.