function LinkGeneratorTest::testGenerateUrlWithQuotes

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

Tests the generate() method with a URL containing double quotes.

@covers ::generate

File

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

Class

LinkGeneratorTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Utility%21LinkGenerator.php/class/LinkGenerator/11.x" 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 testGenerateUrlWithQuotes() : void {
    $this->urlAssembler
        ->expects($this->once())
        ->method('assemble')
        ->with('base:example', [
        'query' => [
            'foo' => '"bar"',
            'zoo' => 'baz',
        ],
    ] + $this->defaultOptions)
        ->willReturn((new GeneratedUrl())->setGeneratedUrl('/example?foo=%22bar%22&zoo=baz'));
    $path_validator = $this->createMock('Drupal\\Core\\Path\\PathValidatorInterface');
    $container_builder = new ContainerBuilder();
    $container_builder->set('path.validator', $path_validator);
    \Drupal::setContainer($container_builder);
    $path = '/example?foo="bar"&zoo=baz';
    $url = Url::fromUserInput($path);
    $url->setUrlGenerator($this->urlGenerator);
    $url->setUnroutedUrlAssembler($this->urlAssembler);
    $result = $this->linkGenerator
        ->generate('Drupal', $url);
    $this->assertLink([
        'attributes' => [
            'href' => '/example?foo=%22bar%22&zoo=baz',
        ],
        'content' => 'Drupal',
    ], $result, 1);
}

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