X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Frest%2Ftests%2Fsrc%2FFunctional%2FEntityResource%2FFormatSpecificGetBcRouteTestTrait.php;fp=web%2Fcore%2Fmodules%2Frest%2Ftests%2Fsrc%2FFunctional%2FEntityResource%2FFormatSpecificGetBcRouteTestTrait.php;h=54bf816c29a8f0e8b3b6099f23f53dd15b98fe5b;hp=0000000000000000000000000000000000000000;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hpb=680c79a86e3ed402f263faeac92e89fb6d9edcc0 diff --git a/web/core/modules/rest/tests/src/Functional/EntityResource/FormatSpecificGetBcRouteTestTrait.php b/web/core/modules/rest/tests/src/Functional/EntityResource/FormatSpecificGetBcRouteTestTrait.php new file mode 100644 index 000000000..54bf816c2 --- /dev/null +++ b/web/core/modules/rest/tests/src/Functional/EntityResource/FormatSpecificGetBcRouteTestTrait.php @@ -0,0 +1,50 @@ +provisionEntityResource(); + $url = $this->getEntityResourceUrl(); + + // BC: Format-specific GET routes are deprecated. They are available on both + // new and old sites, but trigger deprecation notices. + $bc_route = Url::fromRoute('rest.entity.' . static::$entityTypeId . '.GET.' . static::$format, $url->getRouteParameters(), $url->getOptions()); + $bc_route->setUrlGenerator($this->container->get('url_generator')); + $this->expectDeprecation(sprintf("The 'rest.entity.entity_test.GET.%s' route is deprecated since version 8.5.x and will be removed in 9.0.0. Use the 'rest.entity.entity_test.GET' route instead.", static::$format)); + $this->assertSame($url->toString(TRUE)->getGeneratedUrl(), $bc_route->toString(TRUE)->getGeneratedUrl()); + } + + /** + * @group legacy + * + * @see \Drupal\rest\Plugin\ResourceBase::routes + */ + public function testNoFormatSpecificGetBcRouteForOtherFormats() { + $this->setExpectedException(RouteNotFoundException::class); + + $this->provisionEntityResource(); + $url = $this->getEntityResourceUrl(); + + // Verify no format-specific GET BC routes are created for other formats. + $other_format = static::$format === 'json' ? 'xml' : 'json'; + $bc_route_other_format = Url::fromRoute('rest.entity.entity_test.GET.' . $other_format, $url->getRouteParameters(), $url->getOptions()); + $bc_route_other_format->setUrlGenerator($this->container->get('url_generator')); + $bc_route_other_format->toString(TRUE); + } + +}