You are here

public function LinkGeneratorTest::testGenerateButton in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Core/Utility/LinkGeneratorTest.php \Drupal\Tests\Core\Utility\LinkGeneratorTest::testGenerateButton()
  2. 10 core/tests/Drupal/Tests/Core/Utility/LinkGeneratorTest.php \Drupal\Tests\Core\Utility\LinkGeneratorTest::testGenerateButton()

Tests the generate() method with the <button> route.

@covers ::generate

File

core/tests/Drupal/Tests/Core/Utility/LinkGeneratorTest.php, line 216

Class

LinkGeneratorTest
@coversDefaultClass \Drupal\Core\Utility\LinkGenerator @group Utility

Namespace

Drupal\Tests\Core\Utility

Code

public function testGenerateButton() {
  $this->urlGenerator
    ->expects($this
    ->never())
    ->method('generateFromRoute');
  $this->moduleHandler
    ->expects($this
    ->exactly(2))
    ->method('alter')
    ->with('link', $this
    ->isType('array'));
  $url = Url::fromRoute('<button>');
  $url
    ->setUrlGenerator($this->urlGenerator);
  $result = $this->linkGenerator
    ->generate('Test', $url);
  $this
    ->assertInstanceOf(GeneratedButton::class, $result);
  $this
    ->assertSame('<button type="button">Test</button>', (string) $result);

  // Validate removal of hreflang attributes.
  $url = new Url('<button>', [], [
    'language' => new Language([
      'id' => 'de',
    ]),
  ]);
  $url
    ->setUrlGenerator($this->urlGenerator);
  $result = $this->linkGenerator
    ->generate('Test With Language', $url);
  $this
    ->assertSame('<button type="button">Test With Language</button>', (string) $result);
}