function LinkGeneratorTest::testGenerateUrlWithQuotes

Same name in other branches
  1. 8.9.x core/tests/Drupal/Tests/Core/Utility/LinkGeneratorTest.php \Drupal\Tests\Core\Utility\LinkGeneratorTest::testGenerateUrlWithQuotes()
  2. 10 core/tests/Drupal/Tests/Core/Utility/LinkGeneratorTest.php \Drupal\Tests\Core\Utility\LinkGeneratorTest::testGenerateUrlWithQuotes()
  3. 11.x 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 281

Class

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

Namespace

Drupal\Tests\Core\Utility

Code

public function testGenerateUrlWithQuotes() {
    $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.