You are here

public function UrlGeneratorTest::testBaseURLGeneration in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 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 315
Contains \Drupal\Tests\Core\Routing\UrlGeneratorTest.

Class

UrlGeneratorTest
Confirm that the UrlGenerator is functioning properly.

Namespace

Drupal\Tests\Core\Routing

Code

public function testBaseURLGeneration() {
  $options = array(
    '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 = array(
    '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 = array(
    '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 = array(
    '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));
}