core/includes/install.core.inc | 2 +- core/lib/Drupal/Core/Url.php | 28 ++++---- .../{ExternalUrlTest.php => UnroutedUrlTest.php} | 78 ++++++++++++++-------- 3 files changed, 66 insertions(+), 42 deletions(-) diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc index d546a52..2fc2d56 100644 --- a/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -850,7 +850,7 @@ function install_get_form($form_id, array &$install_state) { * @see install_full_redirect_url() */ function install_redirect_url($install_state) { - return 'install.php?' . UrlHelper::buildQuery($install_state['parameters']); + return 'core/install.php?' . UrlHelper::buildQuery($install_state['parameters']); } /** diff --git a/core/lib/Drupal/Core/Url.php b/core/lib/Drupal/Core/Url.php index 64f252d..bdae691 100644 --- a/core/lib/Drupal/Core/Url.php +++ b/core/lib/Drupal/Core/Url.php @@ -28,7 +28,7 @@ class Url { protected $urlGenerator; /** - * The URL builder. + * The unrouted URL assembler. * * @var \Drupal\Core\Utility\UnroutedUrlAssemblerInterface */ @@ -77,7 +77,7 @@ class Url { protected $unrouted = FALSE; /** - * The non-route uri. + * The non-route URI. * * Only used if self::$unrouted is TRUE. * @@ -117,7 +117,7 @@ public function __construct($route_name, $route_parameters = array(), $options = } /** - * Creates a new routed (internal to Drupal) URL object. + * Creates a new routed (internal to Drupal) Url object. * * @param string $route_name * The name of the route @@ -142,14 +142,14 @@ public function __construct($route_name, $route_parameters = array(), $options = * and FALSE enforces HTTP. * * @return \Drupal\Core\Url - * A new routed (internal to Drupal) URL object. + * A new routed (internal to Drupal) Url object. */ public static function routed($route_name, $route_parameters = array(), $options = array()) { return new static($route_name, $route_parameters, $options); } /** - * Creates a new unrouted (external to Drupal) URL object. + * Creates a new unrouted (external to Drupal) Url object. * * @param string $uri * The URI of the external resource including the scheme. For Drupal paths @@ -174,7 +174,7 @@ public static function routed($route_name, $route_parameters = array(), $options * and FALSE enforces HTTP. * * @return \Drupal\Core\Url - * A new unrouted (external to Drupal) URL object. + * A new unrouted (external to Drupal) Url object. */ public static function unrouted($uri, $options = array()) { $url = new static($uri, array(), $options); @@ -214,13 +214,13 @@ public static function createFromRequest(Request $request) { } /** - * Sets this Url to encapselate an unrouted URI. + * Sets this Url to encapsulate an unrouted URI. * * @return $this */ protected function setUnrouted() { $this->unrouted = TRUE; - // What was passed in as the route name is actually the uri. + // What was passed in as the route name is actually the URI. $this->uri = $this->routeName; // Set empty route name and parameters. $this->routeName = NULL; @@ -387,7 +387,7 @@ public function setOption($name, $value) { */ public function getUri() { if (!$this->unrouted) { - throw new \UnexpectedValueException('Internal routes do not have uris.'); + throw new \UnexpectedValueException('Internal routes do not have URIs.'); } return $this->uri; @@ -407,7 +407,7 @@ public function setAbsolute($absolute = TRUE) { } /** - * Generates the uri for this Url object. + * Generates the URI for this Url object. */ public function toString() { if ($this->unrouted) { @@ -424,7 +424,7 @@ public function toString() { * An associative array containing all the properties of the route. */ public function toArray() { - if ($this->isExternal()) { + if ($this->unrouted) { return array( 'path' => $this->getUri(), 'options' => $this->getOptions(), @@ -478,7 +478,7 @@ public function toRenderArray() { */ public function getInternalPath() { if ($this->unrouted) { - throw new \UnexpectedValueException('External URLs do not have internal representations.'); + throw new \UnexpectedValueException('Unrouted URIs do not have internal representations.'); } return $this->urlGenerator()->getPathFromRoute($this->getRouteName(), $this->getRouteParameters()); } @@ -536,10 +536,10 @@ protected function urlGenerator() { } /** - * Gets the URL builder for non-Drupal URLs. + * Gets the unrouted URL assembler for non-Drupal URLs. * * @return \Drupal\Core\Utility\UnroutedUrlAssemblerInterface - * The URL builder. + * The unrouted URL assembler. */ protected function unroutedUrlAssembler() { if (!$this->urlAssembler) { diff --git a/core/tests/Drupal/Tests/Core/ExternalUrlTest.php b/core/tests/Drupal/Tests/Core/UnroutedUrlTest.php similarity index 62% rename from core/tests/Drupal/Tests/Core/ExternalUrlTest.php rename to core/tests/Drupal/Tests/Core/UnroutedUrlTest.php index 972e2db..0fa610d 100644 --- a/core/tests/Drupal/Tests/Core/ExternalUrlTest.php +++ b/core/tests/Drupal/Tests/Core/UnroutedUrlTest.php @@ -2,7 +2,7 @@ /** * @file - * Contains \Drupal\Tests\Core\ExternalUrlTest. + * Contains \Drupal\Tests\Core\UnroutedUrlTest. */ namespace Drupal\Tests\Core; @@ -15,9 +15,9 @@ /** * @coversDefaultClass \Drupal\Core\Url - * @group ExternalUrlTest + * @group UrlTest */ -class ExternalUrlTest extends UnitTestCase { +class UnroutedUrlTest extends UnitTestCase { /** * The URL assembler @@ -34,11 +34,18 @@ class ExternalUrlTest extends UnitTestCase { protected $router; /** - * An external URL to test. + * An unrouted, external URL to test. * * @var string */ - protected $path = 'http://drupal.org'; + protected $unrouted_external = 'http://drupal.org'; + + /** + * An unrouted, internal URL to test. + * + * @var string + */ + protected $unrouted_internal = 'base://robots.txt'; /** * {@inheritdoc} @@ -62,13 +69,20 @@ protected function setUp() { * Tests the createFromPath method. * * @covers ::createFromPath() - * @covers ::setExternal() */ public function testCreateFromPath() { - $url = Url::unrouted($this->path); - $this->assertInstanceOf('Drupal\Core\Url', $url); - $this->assertTrue($url->isExternal()); - return $url; + $urls = [ + Url::unrouted($this->unrouted_external), + Url::unrouted($this->unrouted_internal) + ]; + + $this->assertInstanceOf('Drupal\Core\Url', $urls[0]); + $this->assertTrue($urls[0]->isExternal()); + + $this->assertInstanceOf('Drupal\Core\Url', $urls[1]); + $this->assertFalse($urls[1]->isExternal()); + + return $urls; } /** @@ -96,8 +110,9 @@ public function testCreateFromRequest() { * * @covers ::isExternal() */ - public function testIsExternal(Url $url) { - $this->assertTrue($url->isExternal()); + public function testIsExternal(array $urls) { + $this->assertTrue($urls[0]->isExternal()); + $this->assertFalse($urls[1]->isExternal()); } /** @@ -107,8 +122,9 @@ public function testIsExternal(Url $url) { * * @covers ::toString() */ - public function testToString(Url $url) { - $this->assertSame($this->path, $url->toString()); + public function testToString(array $urls) { + $this->assertSame($this->unrouted_external, $urls[0]->toString()); + $this->assertSame($this->unrouted_internal, $urls[1]->toString()); } /** @@ -118,12 +134,18 @@ public function testToString(Url $url) { * * @covers ::toArray() */ - public function testToArray(Url $url) { + public function testToArray(array $urls) { $expected = array( - 'path' => $this->path, + 'path' => $this->unrouted_external, 'options' => array('external' => TRUE), ); - $this->assertSame($expected, $url->toArray()); + $this->assertSame($expected, $urls[0]->toArray()); + + $expected = array( + 'path' => $this->unrouted_internal, + 'options' => array(), + ); + $this->assertSame($expected, $urls[1]->toArray()); } /** @@ -135,8 +157,8 @@ public function testToArray(Url $url) { * * @covers ::getRouteName() */ - public function testGetRouteName(Url $url) { - $url->getRouteName(); + public function testGetRouteName(array $urls) { + $urls[0]->getRouteName(); } /** @@ -148,8 +170,8 @@ public function testGetRouteName(Url $url) { * * @covers ::getRouteParameters() */ - public function testGetRouteParameters(Url $url) { - $url->getRouteParameters(); + public function testGetRouteParameters(array $urls) { + $urls[0]->getRouteParameters(); } /** @@ -161,8 +183,8 @@ public function testGetRouteParameters(Url $url) { * * @expectedException \Exception */ - public function testGetInternalPath(Url $url) { - $this->assertNull($url->getInternalPath()); + public function testGetInternalPath(array $urls) { + $this->assertNull($urls[0]->getInternalPath()); } /** @@ -172,8 +194,9 @@ public function testGetInternalPath(Url $url) { * * @covers ::getUri() */ - public function testGetUri(Url $url) { - $this->assertNotNull($url->getUri()); + public function testGetUri(array $urls) { + $this->assertNotNull($urls[0]->getUri()); + $this->assertNotNull($urls[1]->getUri()); } /** @@ -183,8 +206,9 @@ public function testGetUri(Url $url) { * * @covers ::getOptions() */ - public function testGetOptions(Url $url) { - $this->assertInternalType('array', $url->getOptions()); + public function testGetOptions(array $urls) { + $this->assertInternalType('array', $urls[0]->getOptions()); + $this->assertInternalType('array', $urls[1]->getOptions()); } }