You are here

public function LinkGeneratorTest::testGenerateUrlWithQuotes in Drupal 10

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Core/Utility/LinkGeneratorTest.php \Drupal\Tests\Core\Utility\LinkGeneratorTest::testGenerateUrlWithQuotes()
  2. 9 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);
}