/**
  * Test that the 'scheme' route requirement is respected during url generation.
  */
 public function testUrlGenerationWithHttpsRequirement()
 {
     $url = $this->generator->generate('test_4', array(), TRUE);
     $this->assertEquals('https://localhost/test/four', $url);
     $this->routeProcessorManager->expects($this->exactly(1))->method('processOutbound')->with($this->anything());
     $options = array('absolute' => TRUE, 'https' => TRUE);
     $url = $this->generator->generateFromRoute('test_1', array(), $options);
     $this->assertEquals('https://localhost/hello/world', $url);
 }
示例#2
0
 /**
  * Asserts \Drupal\Core\Routing\UrlGenerator::generateFromRoute()'s output.
  *
  * @param $route_name
  *   The route name to test.
  * @param array $route_parameters
  *   The route parameters to test.
  * @param array $options
  *   The options to test.
  * @param $expected_url
  *   The expected generated URL string.
  * @param \Drupal\Core\Cache\CacheableMetadata $expected_cacheability
  *   The expected generated cacheability metadata.
  */
 protected function assertGenerateFromRoute($route_name, array $route_parameters, array $options, $expected_url, CacheableMetadata $expected_cacheability)
 {
     // First, test with $collect_cacheability_metadata set to the default value.
     $url = $this->generator->generateFromRoute($route_name, $route_parameters, $options);
     $this->assertSame($expected_url, $url);
     // Second, test with it set to TRUE.
     $generated_url = $this->generator->generateFromRoute($route_name, $route_parameters, $options, TRUE);
     $this->assertSame($expected_url, $generated_url->getGeneratedUrl());
     $this->assertEquals($expected_cacheability, CacheableMetadata::createFromObject($generated_url));
 }
 /**
  * Test that the 'scheme' route requirement is respected during url generation.
  */
 public function testUrlGenerationWithHttpsRequirement()
 {
     $url = $this->generator->generate('test_4', array(), TRUE);
     $this->assertEquals('https://localhost/test/four', $url);
     $this->routeProcessorManager->expects($this->exactly(2))->method('processOutbound')->with($this->anything());
     $options = array('absolute' => TRUE, 'https' => TRUE);
     // Mixed-mode sessions are not enabled, so the https option is ignored.
     $url = $this->generator->generateFromRoute('test_1', array(), $options);
     $this->assertEquals('http://localhost/hello/world', $url);
     // Mixed-mode sessions are enabled, so the https option is obeyed.
     $url = $this->generatorMixedMode->generateFromRoute('test_1', array(), $options);
     $this->assertEquals('https://localhost/hello/world', $url);
 }