diff --git a/core/core.services.yml b/core/core.services.yml index e791572..1bf1fb8 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -1074,7 +1074,7 @@ services: - { name: event_subscriber } redirect_response_subscriber: class: Drupal\Core\EventSubscriber\RedirectResponseSubscriber - arguments: ['@url_generator', '@router.request_context'] + arguments: ['@unrouted_url_assembler', '@router.request_context'] tags: - { name: event_subscriber } redirect_leading_slashes_subscriber: diff --git a/core/lib/Drupal/Core/EventSubscriber/RedirectResponseSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/RedirectResponseSubscriber.php index efaf5c8..3813524 100644 --- a/core/lib/Drupal/Core/EventSubscriber/RedirectResponseSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/RedirectResponseSubscriber.php @@ -11,7 +11,8 @@ use Drupal\Component\Utility\UrlHelper; use Drupal\Core\Routing\LocalRedirectResponse; use Drupal\Core\Routing\RequestContext; -use Drupal\Core\Routing\UrlGeneratorInterface; +use Drupal\Core\Url; +use Drupal\Core\Utility\UnroutedUrlAssemblerInterface; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Event\GetResponseEvent; use Symfony\Component\HttpKernel\KernelEvents; @@ -25,22 +26,22 @@ class RedirectResponseSubscriber implements EventSubscriberInterface { /** - * The url generator service. + * The unrouted url assembler service. * - * @var \Drupal\Core\Routing\UrlGeneratorInterface + * @var \Drupal\Core\Utility\UnroutedUrlAssemblerInterface */ - protected $urlGenerator; + protected $unroutedUrlAssembler; /** * Constructs a RedirectResponseSubscriber object. * - * @param \Drupal\Core\Routing\UrlGeneratorInterface $url_generator - * The url generator service. + * @param \Drupal\Core\Routing\UnroutedUrlAssemblerInterface $url_assembler + * The unrouted url assembler service. * @param \Drupal\Core\Routing\RequestContext $request_context * The request context. */ - public function __construct(UrlGeneratorInterface $url_generator, RequestContext $request_context) { - $this->urlGenerator = $url_generator; + public function __construct(UnroutedUrlAssemblerInterface $url_assembler, RequestContext $request_context) { + $this->unroutedUrlAssembler = $url_assembler; $this->requestContext = $request_context; } @@ -120,16 +121,16 @@ protected function getDestinationAsAbsoluteUrl($destination, $scheme_and_host) { // Legacy destination query parameters can be relative paths that have // not yet been converted to URLs (outbound path processors and other // URL handling still needs to be performed). - // @todo As generateFromPath() is deprecated, remove this in - // https://www.drupal.org/node/2418219. $destination = UrlHelper::parse($destination); - $path = $destination['path']; + $uri = 'base:' . $destination['path']; $options = [ 'query' => $destination['query'], 'fragment' => $destination['fragment'], 'absolute' => TRUE, ]; - $destination = $this->urlGenerator->generateFromPath($path, $options); + // Treat this as if it's user input of a path relative to the site's + // base URL. + $destination = $this->unroutedUrlAssembler->assemble($uri, $options); } } return $destination; diff --git a/core/lib/Drupal/Core/Menu/menu.api.php b/core/lib/Drupal/Core/Menu/menu.api.php index defec19..b37fa61 100644 --- a/core/lib/Drupal/Core/Menu/menu.api.php +++ b/core/lib/Drupal/Core/Menu/menu.api.php @@ -452,7 +452,7 @@ function hook_system_breadcrumb_alter(\Drupal\Core\Breadcrumb\Breadcrumb &$bread * URL. * - url: The \Drupal\Core\Url object. * - options: An associative array of additional options that will be passed - * to either \Drupal\Core\Routing\UrlGenerator::generateFromPath() or + * to either \Drupal\Core\Utility\UnroutedUrlAssembler::assemble() or * \Drupal\Core\Routing\UrlGenerator::generateFromRoute() to generate the * href attribute for this link, and also used when generating the link. * Defaults to an empty array. It may contain the following elements: @@ -469,7 +469,7 @@ function hook_system_breadcrumb_alter(\Drupal\Core\Breadcrumb\Breadcrumb &$bread * to work as an argument for the constructor of the class * Drupal\Core\Template\Attribute($options['attributes']). * - * @see \Drupal\Core\Routing\UrlGenerator::generateFromPath() + * @see \Drupal\Core\Utility\UnroutedUrlAssembler::assemble() * @see \Drupal\Core\Routing\UrlGenerator::generateFromRoute() */ function hook_link_alter(&$variables) { diff --git a/core/lib/Drupal/Core/PathProcessor/OutboundPathProcessorInterface.php b/core/lib/Drupal/Core/PathProcessor/OutboundPathProcessorInterface.php index b350112..59f2d0c 100644 --- a/core/lib/Drupal/Core/PathProcessor/OutboundPathProcessorInterface.php +++ b/core/lib/Drupal/Core/PathProcessor/OutboundPathProcessorInterface.php @@ -22,7 +22,7 @@ * The path to process, with a leading slash. * @param array $options * An array of options such as would be passed to the generator's - * generateFromPath() method. + * generateFromRoute() method. * @param \Symfony\Component\HttpFoundation\Request $request * The HttpRequest object representing the current request. * @param \Drupal\Core\Render\BubbleableMetadata $bubbleable_metadata diff --git a/core/modules/action/src/Plugin/Action/GotoAction.php b/core/modules/action/src/Plugin/Action/GotoAction.php index 770f424..8f96991 100644 --- a/core/modules/action/src/Plugin/Action/GotoAction.php +++ b/core/modules/action/src/Plugin/Action/GotoAction.php @@ -7,12 +7,14 @@ namespace Drupal\action\Plugin\Action; +use Drupal\Component\Utility\UrlHelper; use Drupal\Core\Access\AccessResult; use Drupal\Core\Action\ConfigurableActionBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Routing\UrlGeneratorInterface; use Drupal\Core\Session\AccountInterface; +use Drupal\Core\Url; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\HttpFoundation\RedirectResponse; @@ -75,8 +77,17 @@ public static function create(ContainerInterface $container, array $configuratio * {@inheritdoc} */ public function execute($object = NULL) { - $url = $this->urlGenerator - ->generateFromPath($this->configuration['url'], array('absolute' => TRUE)); + $uri = $this->configuration['url']; + // Check for links internal to the site and make them into a URI. + if (!UrlHelper::isExternal($uri)) { + // @todo '' is valid input for BC reasons, may be removed by + // https://www.drupal.org/node/2421941 + if ($uri === '') { + $uri = ''; + } + $uri = 'internal:/' . ltrim($uri, '/'); + } + $url = Url::fromUri($uri, array('absolute' => TRUE)); $response = new RedirectResponse($url); $listener = function($event) use ($response) { $event->setResponse($response); @@ -101,7 +112,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta $form['url'] = array( '#type' => 'textfield', '#title' => t('URL'), - '#description' => t('The URL to which the user should be redirected. This can be an internal URL like node/1234 or an external URL like @url.', array('@url' => 'http://example.com')), + '#description' => t('The URL to which the user should be redirected. This can be an internal URL like /node/1234 or an external URL like @url.', array('@url' => 'http://example.com')), '#default_value' => $this->configuration['url'], '#required' => TRUE, ); diff --git a/core/modules/simpletest/src/BrowserTestBase.php b/core/modules/simpletest/src/BrowserTestBase.php index e5712c1..204fb5b 100644 --- a/core/modules/simpletest/src/BrowserTestBase.php +++ b/core/modules/simpletest/src/BrowserTestBase.php @@ -23,6 +23,7 @@ use Drupal\Core\Site\Settings; use Drupal\Core\StreamWrapper\StreamWrapperInterface; use Drupal\Core\Test\TestRunnerKernel; +use Drupal\Core\Url; use Drupal\user\UserInterface; use Symfony\Component\HttpFoundation\Request; @@ -391,7 +392,7 @@ protected function prepareRequest() { * Retrieves a Drupal path or an absolute path. * * @param string $path - * Drupal path or URL to load into Mink controlled browser. + * Drupal path like /node or URL to load into Mink controlled browser. * @param array $options * (optional) Options to be forwarded to the url generator. * @@ -404,7 +405,7 @@ protected function drupalGet($path, array $options = array()) { // The URL generator service is not necessarily available yet; e.g., in // interactive installer tests. if ($this->container->has('url_generator')) { - $url = $this->container->get('url_generator')->generateFromPath($path, $options); + $url = Url::fromUserInput($path, $options)->toString(); } else { $url = $this->getAbsoluteUrl($path); @@ -617,7 +618,7 @@ protected function drupalLogin(AccountInterface $account) { $this->drupalLogout(); } - $this->drupalGet('user'); + $this->drupalGet('/user'); $this->assertSession()->statusCodeEquals(200); $this->submitForm(array( 'name' => $account->getUsername(), @@ -642,7 +643,7 @@ protected function drupalLogout() { // idea being if you were properly logged out you should be seeing a login // screen. $assert_session = $this->assertSession(); - $this->drupalGet('user/logout', array('query' => array('destination' => 'user'))); + $this->drupalGet('/user/logout', array('query' => array('destination' => Url::fromUri('base:user')->toString()))); $assert_session->statusCodeEquals(200); $assert_session->fieldExists('name'); $assert_session->fieldExists('pass'); diff --git a/core/modules/views/src/Tests/Handler/FieldWebTest.php b/core/modules/views/src/Tests/Handler/FieldWebTest.php index 3f9a184..ddc9b50 100644 --- a/core/modules/views/src/Tests/Handler/FieldWebTest.php +++ b/core/modules/views/src/Tests/Handler/FieldWebTest.php @@ -11,6 +11,7 @@ use Drupal\Component\Utility\Unicode; use Drupal\Component\Utility\UrlHelper; use Drupal\Core\Render\RenderContext; +use Drupal\Core\Url; use Drupal\system\Tests\Cache\AssertPageCacheContextsAndTagsTrait; use Drupal\views\Views; @@ -262,7 +263,7 @@ public function testAlterUrl() { // @todo The route-based URL generator strips out NULL attributes. // $expected_result = \Drupal::url('entity.node.canonical', ['node' => '123'], ['query' => ['foo' => NULL], 'fragment' => 'bar', 'absolute' => $absolute]); - $expected_result = \Drupal::urlGenerator()->generateFromPath('node/123', array('query' => array('foo' => NULL), 'fragment' => 'bar', 'absolute' => $absolute)); + $expected_result = Url::fromUserInput('/node/123', array('query' => array('foo' => NULL), 'fragment' => 'bar', 'absolute' => $absolute))->toString(); $alter['path'] = 'node/123?foo#bar'; $result = $renderer->executeInRenderContext(new RenderContext(), function () use ($id_field, $row) { return $id_field->theme($row); diff --git a/core/tests/Drupal/Tests/Core/EventSubscriber/RedirectResponseSubscriberTest.php b/core/tests/Drupal/Tests/Core/EventSubscriber/RedirectResponseSubscriberTest.php index 193c25b..e80df61 100644 --- a/core/tests/Drupal/Tests/Core/EventSubscriber/RedirectResponseSubscriberTest.php +++ b/core/tests/Drupal/Tests/Core/EventSubscriber/RedirectResponseSubscriberTest.php @@ -10,6 +10,7 @@ use Drupal\Core\EventSubscriber\RedirectResponseSubscriber; use Drupal\Core\Routing\RequestContext; use Drupal\Core\Routing\TrustedRedirectResponse; +use Drupal\Core\Utility\UnroutedUrlAssemblerInterface; use Drupal\Tests\UnitTestCase; use Symfony\Component\DependencyInjection\Container; use Symfony\Component\EventDispatcher\EventDispatcher; @@ -34,6 +35,13 @@ class RedirectResponseSubscriberTest extends UnitTestCase { protected $requestContext; /** + * The mocked request context. + * + * @var \Drupal\Core\Utility\UnroutedUrlAssemblerInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $urlAssembler; + + /** * {@inheritdoc} */ protected function setUp() { @@ -46,6 +54,17 @@ protected function setUp() { ->method('getCompleteBaseUrl') ->willReturn('http://example.com/drupal'); + $this->urlAssembler = $this->getMock(UnroutedUrlAssemblerInterface::class); + $this->urlAssembler + ->expects($this->any()) + ->method('assemble') + ->willReturnMap([ + ['base:test', ['query' => [], 'fragment' => '', 'absolute' => TRUE], FALSE, 'http://example.com/drupal/test'], + ['base:example.com', ['query' => [], 'fragment' => '', 'absolute' => TRUE], FALSE, 'http://example.com/drupal/example.com'], + ['base:example:com', ['query' => [], 'fragment' => '', 'absolute' => TRUE], FALSE, 'http://example.com/drupal/example:com'], + ['base:javascript:alert(0)', ['query' => [], 'fragment' => '', 'absolute' => TRUE], FALSE, 'http://example.com/drupal/javascript:alert(0)'], + ]); + $container = new Container(); $container->set('router.request_context', $this->requestContext); \Drupal::setContainer($container); @@ -66,27 +85,9 @@ public function testDestinationRedirect(Request $request, $expected) { $dispatcher = new EventDispatcher(); $kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface'); $response = new RedirectResponse('http://example.com/drupal'); - $url_generator = $this->getMockBuilder('Drupal\Core\Routing\UrlGenerator') - ->disableOriginalConstructor() - ->setMethods(array('generateFromPath')) - ->getMock(); - - if ($expected) { - $url_generator - ->expects($this->any()) - ->method('generateFromPath') - ->willReturnMap([ - ['test', ['query' => [], 'fragment' => '', 'absolute' => TRUE], FALSE, 'http://example.com/drupal/test'], - ['example.com', ['query' => [], 'fragment' => '', 'absolute' => TRUE], FALSE, 'http://example.com/drupal/example.com'], - ['example:com', ['query' => [], 'fragment' => '', 'absolute' => TRUE], FALSE, 'http://example.com/drupal/example:com'], - ['javascript:alert(0)', ['query' => [], 'fragment' => '', 'absolute' => TRUE], FALSE, 'http://example.com/drupal/javascript:alert(0)'], - ['/test', ['query' => [], 'fragment' => '', 'absolute' => TRUE], FALSE, 'http://example.com/test'], - ]); - } - $request->headers->set('HOST', 'example.com'); - $listener = new RedirectResponseSubscriber($url_generator, $this->requestContext); + $listener = new RedirectResponseSubscriber($this->urlAssembler, $this->requestContext); $dispatcher->addListener(KernelEvents::RESPONSE, array($listener, 'checkRedirectUrl')); $event = new FilterResponseEvent($kernel, $request, HttpKernelInterface::SUB_REQUEST, $response); $dispatcher->dispatch(KernelEvents::RESPONSE, $event); @@ -127,32 +128,8 @@ public function testDestinationRedirectToExternalUrl($request, $expected) { $dispatcher = new EventDispatcher(); $kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface'); $response = new RedirectResponse('http://other-example.com'); - $url_generator = $this->getMockBuilder('Drupal\Core\Routing\UrlGenerator') - ->disableOriginalConstructor() - ->setMethods(array('generateFromPath')) - ->getMock(); - $request_context = $this->getMockBuilder('Drupal\Core\Routing\RequestContext') - ->disableOriginalConstructor() - ->getMock(); - $request_context->expects($this->any()) - ->method('getCompleteBaseUrl') - ->willReturn('http://example.com/drupal'); - - if ($expected) { - $url_generator - ->expects($this->any()) - ->method('generateFromPath') - ->willReturnMap([ - ['test', ['query' => [], 'fragment' => '', 'absolute' => TRUE], FALSE, 'http://example.com/drupal/test'], - ['example.com', ['query' => [], 'fragment' => '', 'absolute' => TRUE], FALSE, 'http://example.com/drupal/example.com'], - ['example:com', ['query' => [], 'fragment' => '', 'absolute' => TRUE], FALSE, 'http://example.com/drupal/example:com'], - ['javascript:alert(0)', ['query' => [], 'fragment' => '', 'absolute' => TRUE], FALSE, 'http://example.com/drupal/javascript:alert(0)'], - ['/test', ['query' => [], 'fragment' => '', 'absolute' => TRUE], FALSE, 'http://example.com/test'], - ]); - } - - $listener = new RedirectResponseSubscriber($url_generator, $request_context); + $listener = new RedirectResponseSubscriber($this->urlAssembler, $this->requestContext); $dispatcher->addListener(KernelEvents::RESPONSE, array($listener, 'checkRedirectUrl')); $event = new FilterResponseEvent($kernel, $request, HttpKernelInterface::SUB_REQUEST, $response); $dispatcher->dispatch(KernelEvents::RESPONSE, $event); @@ -167,22 +144,10 @@ public function testRedirectWithOptInExternalUrl() { $dispatcher = new EventDispatcher(); $kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface'); $response = new TrustedRedirectResponse('http://external-url.com'); - $url_generator = $this->getMockBuilder('Drupal\Core\Routing\UrlGenerator') - ->disableOriginalConstructor() - ->setMethods(array('generateFromPath')) - ->getMock(); - - $request_context = $this->getMockBuilder('Drupal\Core\Routing\RequestContext') - ->disableOriginalConstructor() - ->getMock(); - $request_context->expects($this->any()) - ->method('getCompleteBaseUrl') - ->willReturn('http://example.com/drupal'); - $request = Request::create(''); $request->headers->set('HOST', 'example.com'); - $listener = new RedirectResponseSubscriber($url_generator, $request_context); + $listener = new RedirectResponseSubscriber($this->urlAssembler, $this->requestContext); $dispatcher->addListener(KernelEvents::RESPONSE, array($listener, 'checkRedirectUrl')); $event = new FilterResponseEvent($kernel, $request, HttpKernelInterface::SUB_REQUEST, $response); $dispatcher->dispatch(KernelEvents::RESPONSE, $event); @@ -214,13 +179,8 @@ public function testDestinationRedirectWithInvalidUrl(Request $request) { $dispatcher = new EventDispatcher(); $kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface'); $response = new RedirectResponse('http://example.com/drupal'); - $url_generator = $this->getMock('Drupal\Core\Routing\UrlGeneratorInterface'); - - $request_context = $this->getMockBuilder('Drupal\Core\Routing\RequestContext') - ->disableOriginalConstructor() - ->getMock(); - $listener = new RedirectResponseSubscriber($url_generator, $request_context); + $listener = new RedirectResponseSubscriber($this->urlAssembler, $this->requestContext); $dispatcher->addListener(KernelEvents::RESPONSE, array($listener, 'checkRedirectUrl')); $event = new FilterResponseEvent($kernel, $request, HttpKernelInterface::SUB_REQUEST, $response); $dispatcher->dispatch(KernelEvents::RESPONSE, $event); @@ -257,9 +217,7 @@ public function testSanitizeDestinationForGet($input, $output) { $request = new Request(); $request->query->set('destination', $input); - $url_generator = $this->getMock('Drupal\Core\Routing\UrlGeneratorInterface'); - $request_context = new RequestContext(); - $listener = new RedirectResponseSubscriber($url_generator, $request_context); + $listener = new RedirectResponseSubscriber($this->urlAssembler, $this->requestContext); $kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface'); $event = new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST); @@ -283,9 +241,7 @@ public function testSanitizeDestinationForPost($input, $output) { $request = new Request(); $request->request->set('destination', $input); - $url_generator = $this->getMock('Drupal\Core\Routing\UrlGeneratorInterface'); - $request_context = new RequestContext(); - $listener = new RedirectResponseSubscriber($url_generator, $request_context); + $listener = new RedirectResponseSubscriber($this->urlAssembler, $this->requestContext); $kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface'); $event = new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST); diff --git a/core/tests/Drupal/Tests/Core/Form/FormSubmitterTest.php b/core/tests/Drupal/Tests/Core/Form/FormSubmitterTest.php index 6be8a5a..b4a794e 100644 --- a/core/tests/Drupal/Tests/Core/Form/FormSubmitterTest.php +++ b/core/tests/Drupal/Tests/Core/Form/FormSubmitterTest.php @@ -9,7 +9,9 @@ use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Core\Form\FormState; +use Drupal\Core\Routing\UrlGeneratorInterface; use Drupal\Core\Url; +use Drupal\Core\Utility\UnroutedUrlAssemblerInterface; use Drupal\Tests\UnitTestCase; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; @@ -29,11 +31,19 @@ class FormSubmitterTest extends UnitTestCase { protected $urlGenerator; /** + * The mocked unrouted URL assembler. + * + * @var \PHPUnit_Framework_MockObject_MockObject|\Drupal\Core\Utility\UnroutedUrlAssemblerInterface + */ + protected $unroutedUrlAssembler; + + /** * {@inheritdoc} */ protected function setUp() { parent::setUp(); - $this->urlGenerator = $this->getMock('Drupal\Core\Routing\UrlGeneratorInterface'); + $this->urlGenerator = $this->getMock(UrlGeneratorInterface::class); + $this->unroutedUrlAssembler = $this->getMock(UnroutedUrlAssemblerInterface::class); } /** @@ -187,9 +197,13 @@ public function testRedirectWithResponseObject() { public function testRedirectWithoutResult() { $form_submitter = $this->getFormSubmitter(); $this->urlGenerator->expects($this->never()) - ->method('generateFromPath'); - $this->urlGenerator->expects($this->never()) ->method('generateFromRoute'); + $this->unroutedUrlAssembler->expects($this->never()) + ->method('assemble'); + $container = new ContainerBuilder(); + $container->set('url_generator', $this->urlGenerator); + $container->set('unrouted_url_assembler', $this->unroutedUrlAssembler); + \Drupal::setContainer($container); $form_state = $this->getMock('Drupal\Core\Form\FormStateInterface'); $form_state->expects($this->once()) ->method('getRedirect') diff --git a/core/tests/Drupal/Tests/Core/Routing/UrlGeneratorTest.php b/core/tests/Drupal/Tests/Core/Routing/UrlGeneratorTest.php index 6607cb5..4d91218 100644 --- a/core/tests/Drupal/Tests/Core/Routing/UrlGeneratorTest.php +++ b/core/tests/Drupal/Tests/Core/Routing/UrlGeneratorTest.php @@ -349,79 +349,6 @@ public function testUrlGenerationWithHttpsRequirement() { } /** - * Tests path-based URL generation. - */ - public function testPathBasedURLGeneration() { - $base_path = '/subdir'; - $base_url = 'http://www.example.com' . $base_path; - - foreach (array('', 'index.php/') as $script_path) { - foreach (array(FALSE, TRUE) as $absolute) { - // Setup a fake request which looks like a Drupal installed under the - // subdir "subdir" on the domain www.example.com. - // To reproduce the values install Drupal like that and use a debugger. - $server = [ - 'SCRIPT_NAME' => '/subdir/index.php', - 'SCRIPT_FILENAME' => $this->root . '/index.php', - 'SERVER_NAME' => 'http://www.example.com', - ]; - $request = Request::create('/subdir/' . $script_path, 'GET', [], [], [], $server); - $request->headers->set('host', ['www.example.com']); - $this->requestStack->push($request); - - // Determine the expected bubbleable metadata. - $expected_cacheability = (new BubbleableMetadata()) - ->setCacheContexts($absolute ? ['url.site'] : []) - ->setCacheMaxAge(Cache::PERMANENT); - - // Get the expected start of the path string. - $base = ($absolute ? $base_url . '/' : $base_path . '/') . $script_path; - $url = $base . 'node/123'; - $result = $this->generator->generateFromPath('node/123', array('absolute' => $absolute)); - $this->assertEquals($url, $result, "$url == $result"); - $generated_url = $this->generator->generateFromPath('node/123', array('absolute' => $absolute), TRUE); - $this->assertEquals($url, $generated_url->getGeneratedUrl(), "$url == $result"); - $this->assertEquals($expected_cacheability, BubbleableMetadata::createFromObject($generated_url)); - - $url = $base . 'node/123#foo'; - $result = $this->generator->generateFromPath('node/123', array('fragment' => 'foo', 'absolute' => $absolute)); - $this->assertEquals($url, $result, "$url == $result"); - $generated_url = $this->generator->generateFromPath('node/123', array('fragment' => 'foo', 'absolute' => $absolute), TRUE); - $this->assertEquals($url, $generated_url->getGeneratedUrl(), "$url == $result"); - $this->assertEquals($expected_cacheability, BubbleableMetadata::createFromObject($generated_url)); - - $url = $base . 'node/123?foo'; - $result = $this->generator->generateFromPath('node/123', array('query' => array('foo' => NULL), 'absolute' => $absolute)); - $this->assertEquals($url, $result, "$url == $result"); - $generated_url = $this->generator->generateFromPath('node/123', array('query' => array('foo' => NULL), 'absolute' => $absolute), TRUE); - $this->assertEquals($url, $generated_url->getGeneratedUrl(), "$url == $result"); - $this->assertEquals($expected_cacheability, BubbleableMetadata::createFromObject($generated_url)); - - $url = $base . 'node/123?foo=bar&bar=baz'; - $result = $this->generator->generateFromPath('node/123', array('query' => array('foo' => 'bar', 'bar' => 'baz'), 'absolute' => $absolute)); - $this->assertEquals($url, $result, "$url == $result"); - $generated_url = $this->generator->generateFromPath('node/123', array('query' => array('foo' => 'bar', 'bar' => 'baz'), 'absolute' => $absolute), TRUE); - $this->assertEquals($url, $generated_url->getGeneratedUrl(), "$url == $result"); - $this->assertEquals($expected_cacheability, BubbleableMetadata::createFromObject($generated_url)); - - $url = $base . 'node/123?foo#bar'; - $result = $this->generator->generateFromPath('node/123', array('query' => array('foo' => NULL), 'fragment' => 'bar', 'absolute' => $absolute)); - $this->assertEquals($url, $result, "$url == $result"); - $generated_url = $this->generator->generateFromPath('node/123', array('query' => array('foo' => NULL), 'fragment' => 'bar', 'absolute' => $absolute), TRUE); - $this->assertEquals($url, $generated_url->getGeneratedUrl(), "$url == $result"); - $this->assertEquals($expected_cacheability, BubbleableMetadata::createFromObject($generated_url)); - - $url = $base; - $result = $this->generator->generateFromPath('', array('absolute' => $absolute)); - $this->assertEquals($url, $result, "$url == $result"); - $generated_url = $this->generator->generateFromPath('', array('absolute' => $absolute), TRUE); - $this->assertEquals($url, $generated_url->getGeneratedUrl(), "$url == $result"); - $this->assertEquals($expected_cacheability, BubbleableMetadata::createFromObject($generated_url)); - } - } - } - - /** * Tests generating a relative URL with no path. * * @param array $options