function LinkGeneratorTest::testGenerateNoLink

Same name and namespace in other branches
  1. 8.9.x core/tests/Drupal/Tests/Core/Utility/LinkGeneratorTest.php \Drupal\Tests\Core\Utility\LinkGeneratorTest::testGenerateNoLink()
  2. 10 core/tests/Drupal/Tests/Core/Utility/LinkGeneratorTest.php \Drupal\Tests\Core\Utility\LinkGeneratorTest::testGenerateNoLink()
  3. 11.x core/tests/Drupal/Tests/Core/Utility/LinkGeneratorTest.php \Drupal\Tests\Core\Utility\LinkGeneratorTest::testGenerateNoLink()

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

The set_active_class option is set to TRUE to ensure we do not get the active class and the data-drupal-link-system-path attribute.

@covers ::generate

File

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

Class

LinkGeneratorTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Utility%21LinkGenerator.php/class/LinkGenerator/9" title="Provides a class which generates a link with route names and parameters." class="local">\Drupal\Core\Utility\LinkGenerator</a> @group Utility

Namespace

Drupal\Tests\Core\Utility

Code

public function testGenerateNoLink() {
    $this->urlGenerator
        ->expects($this->never())
        ->method('generateFromRoute');
    $this->moduleHandler
        ->expects($this->exactly(2))
        ->method('alter')
        ->with('link', $this->isType('array'));
    $url = Url::fromRoute('<nolink>');
    $url->setUrlGenerator($this->urlGenerator);
    $url->setOption('set_active_class', TRUE);
    $result = $this->linkGenerator
        ->generate('Test', $url);
    $this->assertInstanceOf(GeneratedNoLink::class, $result);
    $this->assertSame('<span>Test</span>', (string) $result);
    // Validate removal of hreflang attributes.
    $url = Url::fromRoute('<nolink>', [], [
        'language' => new Language([
            'id' => 'de',
        ]),
    ]);
    $url->setUrlGenerator($this->urlGenerator);
    $result = $this->linkGenerator
        ->generate('Test With Language', $url);
    $this->assertSame('<span>Test With Language</span>', (string) $result);
}

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