From abb88f9f78d455203879ec3a5b78733c623ad512 Mon Sep 17 00:00:00 2001 From: Nathaniel Catchpole Date: Fri, 16 May 2014 10:53:47 +0100 Subject: [PATCH] Issue #2266377 by dawehner, bkosborne, pwolanin: Speed up UrlGenerator a little by setting the 'external' option in the Url object . --- core/lib/Drupal/Core/Url.php | 2 ++ core/tests/Drupal/Tests/Core/ExternalUrlTest.php | 6 ++---- core/tests/Drupal/Tests/Core/Utility/LinkGeneratorTest.php | 7 +++++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/core/lib/Drupal/Core/Url.php b/core/lib/Drupal/Core/Url.php index b8fcdeb8e97..93b329a7548 100644 --- a/core/lib/Drupal/Core/Url.php +++ b/core/lib/Drupal/Core/Url.php @@ -171,6 +171,8 @@ class Url extends DependencySerialization { // Set empty route name and parameters. $this->routeName = NULL; $this->routeParameters = array(); + // Flag the path as external so the UrlGenerator does not need to check. + $this->options['external'] = TRUE; return $this; } diff --git a/core/tests/Drupal/Tests/Core/ExternalUrlTest.php b/core/tests/Drupal/Tests/Core/ExternalUrlTest.php index 37f1a40bc3f..c44e3028983 100644 --- a/core/tests/Drupal/Tests/Core/ExternalUrlTest.php +++ b/core/tests/Drupal/Tests/Core/ExternalUrlTest.php @@ -64,9 +64,7 @@ class ExternalUrlTest extends UnitTestCase { $this->urlGenerator = $this->getMock('Drupal\Core\Routing\UrlGeneratorInterface'); $this->urlGenerator->expects($this->any()) ->method('generateFromPath') - ->will($this->returnCallback(function ($path) { - return $path; - })); + ->will($this->returnArgument(0)); $this->router = $this->getMock('Drupal\Tests\Core\Routing\TestRouterInterface'); $container = new ContainerBuilder(); @@ -143,7 +141,7 @@ class ExternalUrlTest extends UnitTestCase { public function testToArray(Url $url) { $expected = array( 'path' => $this->path, - 'options' => array(), + 'options' => array('external' => TRUE), ); $this->assertSame($expected, $url->toArray()); } diff --git a/core/tests/Drupal/Tests/Core/Utility/LinkGeneratorTest.php b/core/tests/Drupal/Tests/Core/Utility/LinkGeneratorTest.php index 1d01b165b4a..d862ec14e62 100644 --- a/core/tests/Drupal/Tests/Core/Utility/LinkGeneratorTest.php +++ b/core/tests/Drupal/Tests/Core/Utility/LinkGeneratorTest.php @@ -17,6 +17,9 @@ use Drupal\Tests\UnitTestCase; * * @see \Drupal\Core\Utility\LinkGenerator * + * @group Drupal + * @group Utility + * * @coversDefaultClass \Drupal\Core\Utility\LinkGenerator */ class LinkGeneratorTest extends UnitTestCase { @@ -159,8 +162,8 @@ class LinkGeneratorTest extends UnitTestCase { public function testGenerateFromUrlExternal() { $this->urlGenerator->expects($this->once()) ->method('generateFromPath') - ->with('http://drupal.org', array('set_active_class' => TRUE) + $this->defaultOptions) - ->will($this->returnValue('http://drupal.org')); + ->with('http://drupal.org', array('set_active_class' => TRUE, 'external' => TRUE) + $this->defaultOptions) + ->will($this->returnArgument(0)); $this->moduleHandler->expects($this->once()) ->method('alter')