diff --git a/core/lib/Drupal/Core/Url.php b/core/lib/Drupal/Core/Url.php index f1b44a6..fb45da4 100644 --- a/core/lib/Drupal/Core/Url.php +++ b/core/lib/Drupal/Core/Url.php @@ -313,7 +313,7 @@ protected static function fromEntityUri(array $uri_parts, $options, $uri) { * Creates a new Url object for 'user-path:' URIs. * * @param array $uri_parts - * Parts from an URI of the form user-path:{path} as from parse_url(). + * Parts from an URI of the form user-path:{path} as from parse_url(). * @param array $options * An array of options, see static::fromUri() for details. * diff --git a/core/tests/Drupal/Tests/Core/UrlTest.php b/core/tests/Drupal/Tests/Core/UrlTest.php index d3cf641..d4cd977 100644 --- a/core/tests/Drupal/Tests/Core/UrlTest.php +++ b/core/tests/Drupal/Tests/Core/UrlTest.php @@ -9,7 +9,6 @@ use Drupal\Core\Access\AccessManagerInterface; use Drupal\Core\DependencyInjection\ContainerBuilder; -use Drupal\Core\Entity\EntityType; use Drupal\Core\Routing\RouteMatch; use Drupal\Core\Url; use Drupal\Tests\UnitTestCase; @@ -18,7 +17,6 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Exception\InvalidParameterException; use Symfony\Component\Routing\Exception\ResourceNotFoundException; -use Symfony\Component\Routing\Exception\RouteNotFoundException; use Symfony\Component\Routing\Route; /** @@ -483,7 +481,7 @@ public function testFromRouteMatch() { /** * Data provider for testing entity URIs */ - public function entityUris() { + public function providerTestEntityUris() { return [ [ 'entity:test_entity/1', @@ -517,7 +515,7 @@ public function entityUris() { * * @covers ::fromUri * - * @dataProvider entityUris + * @dataProvider providerTestEntityUris */ public function testEntityUris($uri, $options, $route_name, $route_parameters, $query, $fragment) { $url = Url::fromUri($uri, $options); @@ -547,49 +545,75 @@ public function testInvalidEntityUriParameter() { * Tests the toUriString() method with entity: URIs. * * @covers ::toUriString + * + * @dataProvider providerTestToUriStringForEntity + */ + public function testToUriStringForEntity($uri, $options, $uri_string) { + $url = Url::fromUri($uri, $options); + $this->assertSame($url->toUriString(), $uri_string); + } + + /** + * Data provider for testing string entity URIs */ - public function testToUriStringForEntity() { - $url = Url::fromUri('entity:test_entity/1'); - $this->assertSame($url->toUriString(), 'route:entity.test_entity.canonical;test_entity=1'); - $url = Url::fromUri('entity:test_entity/1', ['fragment' => 'top', 'query' => ['page' => '2']]); - $this->assertSame($url->toUriString(), 'route:entity.test_entity.canonical;test_entity=1?page=2#top'); - $url = Url::fromUri('entity:test_entity/1?page=2#top'); - $this->assertSame($url->toUriString(), 'route:entity.test_entity.canonical;test_entity=1?page=2#top'); + public function providerTestToUriStringForEntity() { + return [ + ['entity:test_entity/1', [], 'route:entity.test_entity.canonical;test_entity=1'], + ['entity:test_entity/1', ['fragment' => 'top', 'query' => ['page' => '2']], 'route:entity.test_entity.canonical;test_entity=1?page=2#top'], + ['entity:test_entity/1?page=2#top', [], 'route:entity.test_entity.canonical;test_entity=1?page=2#top'], + ]; } /** * Tests the toUriString() method with user-path: URIs. * * @covers ::toUriString + * + * @dataProvider providerTestToUriStringForUserPath */ - public function testToUriStringForUserPath() { + public function testToUriStringForUserPath($uri, $options, $uri_string) { $url = Url::fromRoute('entity.test_entity.canonical', ['test_entity' => '1']); $this->pathValidator->expects($this->any()) ->method('getUrlIfValidWithoutAccessCheck') ->with('test-entity/1') ->willReturn($url); - $url = Url::fromUri('user-path:test-entity/1'); - $this->assertSame($url->toUriString(), 'route:entity.test_entity.canonical;test_entity=1'); - $url = Url::fromUri('user-path:test-entity/1', ['fragment' => 'top']); - $this->assertSame($url->toUriString(), 'route:entity.test_entity.canonical;test_entity=1#top'); - $url = Url::fromUri('user-path:test-entity/1', ['fragment' => 'top', 'query' => ['page' => '2']]); - $this->assertSame($url->toUriString(), 'route:entity.test_entity.canonical;test_entity=1?page=2#top'); - $url = Url::fromUri('user-path:test-entity/1?page=2#top'); - $this->assertSame($url->toUriString(), 'route:entity.test_entity.canonical;test_entity=1?page=2#top'); + $url = Url::fromUri($uri, $options); + $this->assertSame($url->toUriString(), $uri_string); + } + + /** + * Data provider for testing user-path URIs + */ + public function providerTestToUriStringForUserPath() { + return [ + ['user-path:test-entity/1', [], 'route:entity.test_entity.canonical;test_entity=1'], + ['user-path:test-entity/1', ['fragment' => 'top'], 'route:entity.test_entity.canonical;test_entity=1#top'], + ['user-path:test-entity/1', ['fragment' => 'top', 'query' => ['page' => '2']], 'route:entity.test_entity.canonical;test_entity=1?page=2#top'], + ['user-path:test-entity/1?page=2#top', [], 'route:entity.test_entity.canonical;test_entity=1?page=2#top'], + ]; } /** * Tests the toUriString() method with route: URIs. * * @covers ::toUriString + * + * @dataProvider providerTestToUriStringForRoute + */ + public function testToUriStringForRoute($uri, $options, $uri_string) { + $url = Url::fromUri($uri, $options); + $this->assertSame($url->toUriString(), $uri_string); + } + + /** + * Data provider for testing user-path URIs */ - public function testToUriStringForRoute() { - $url = Url::fromUri('route:entity.test_entity.canonical;test_entity=1'); - $this->assertSame($url->toUriString(), 'route:entity.test_entity.canonical;test_entity=1'); - $url = Url::fromUri('route:entity.test_entity.canonical;test_entity=1', ['fragment' => 'top', 'query' => ['page' => '2']]); - $this->assertSame($url->toUriString(), 'route:entity.test_entity.canonical;test_entity=1?page=2#top'); - $url = Url::fromUri('route:entity.test_entity.canonical;test_entity=1?page=2#top'); - $this->assertSame($url->toUriString(), 'route:entity.test_entity.canonical;test_entity=1?page=2#top'); + public function providerTestToUriStringForRoute() { + return [ + ['route:entity.test_entity.canonical;test_entity=1', [], 'route:entity.test_entity.canonical;test_entity=1'], + ['route:entity.test_entity.canonical;test_entity=1', ['fragment' => 'top', 'query' => ['page' => '2']], 'route:entity.test_entity.canonical;test_entity=1?page=2#top'], + ['route:entity.test_entity.canonical;test_entity=1?page=2#top', [], 'route:entity.test_entity.canonical;test_entity=1?page=2#top'], + ]; } /**