function UrlGeneratorTest::testBaseURLGeneration

Same name in other branches
  1. 8.9.x core/tests/Drupal/Tests/Core/Routing/UrlGeneratorTest.php \Drupal\Tests\Core\Routing\UrlGeneratorTest::testBaseURLGeneration()
  2. 10 core/tests/Drupal/Tests/Core/Routing/UrlGeneratorTest.php \Drupal\Tests\Core\Routing\UrlGeneratorTest::testBaseURLGeneration()
  3. 11.x core/tests/Drupal/Tests/Core/Routing/UrlGeneratorTest.php \Drupal\Tests\Core\Routing\UrlGeneratorTest::testBaseURLGeneration()

Confirms that explicitly setting the base_url works with generated routes.

File

core/tests/Drupal/Tests/Core/Routing/UrlGeneratorTest.php, line 434

Class

UrlGeneratorTest
Confirm that the UrlGenerator is functioning properly.

Namespace

Drupal\Tests\Core\Routing

Code

public function testBaseURLGeneration() {
    $options = [
        'base_url' => 'http://www.example.com:8888',
    ];
    $this->assertGenerateFromRoute('test_1', [], $options, 'http://www.example.com:8888/hello/world', (new BubbleableMetadata())->setCacheMaxAge(Cache::PERMANENT));
    $options = [
        'base_url' => 'http://www.example.com:8888',
        'https' => TRUE,
    ];
    $this->assertGenerateFromRoute('test_1', [], $options, 'https://www.example.com:8888/hello/world', (new BubbleableMetadata())->setCacheMaxAge(Cache::PERMANENT));
    $options = [
        'base_url' => 'https://www.example.com:8888',
        'https' => FALSE,
    ];
    $this->assertGenerateFromRoute('test_1', [], $options, 'http://www.example.com:8888/hello/world', (new BubbleableMetadata())->setCacheMaxAge(Cache::PERMANENT));
    $this->routeProcessorManager
        ->expects($this->exactly(2))
        ->method('processOutbound')
        ->with($this->anything());
    $options = [
        'base_url' => 'http://www.example.com:8888',
        'fragment' => 'top',
    ];
    // Extra parameters should appear in the query string.
    $this->assertGenerateFromRoute('test_1', [
        'zoo' => 5,
    ], $options, 'http://www.example.com:8888/hello/world?zoo=5#top', (new BubbleableMetadata())->setCacheMaxAge(Cache::PERMANENT));
}

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