Commit d4e84161 authored by alexpott's avatar alexpott
Browse files

Issue #2936704 by Wim Leers, amateescu, alexpott, Berdir: Remove REST route...

Issue #2936704 by Wim Leers, amateescu, alexpott, Berdir: Remove REST route deprecations from DeprecationListenerTrait::getSkippedDeprecations(), use ExpectDeprecationTrait::expectDeprecation() instead
parent fbf13ed3
......@@ -5,6 +5,7 @@
use Drupal\Tests\hal\Functional\EntityResource\HalEntityNormalizationTrait;
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
use Drupal\Tests\rest\Functional\EntityResource\EntityTest\EntityTestResourceTestBase;
use Drupal\Tests\rest\Functional\EntityResource\FormatSpecificGetBcRouteTestTrait;
use Drupal\user\Entity\User;
/**
......@@ -14,6 +15,7 @@ class EntityTestHalJsonAnonTest extends EntityTestResourceTestBase {
use HalEntityNormalizationTrait;
use AnonResourceTestTrait;
use FormatSpecificGetBcRouteTestTrait;
/**
* {@inheritdoc}
......
......@@ -21,7 +21,6 @@
use Drupal\Tests\rest\Functional\ResourceTestBase;
use GuzzleHttp\RequestOptions;
use Psr\Http\Message\ResponseInterface;
use Symfony\Component\Routing\Exception\RouteNotFoundException;
/**
* Even though there is the generic EntityResource, it's necessary for every
......@@ -720,18 +719,6 @@ public function testGet() {
$path = str_replace('987654321', '{' . static::$entityTypeId . '}', $url->setAbsolute()->setOptions(['base_url' => '', 'query' => []])->toString());
$message = 'The "' . static::$entityTypeId . '" parameter was not converted for the path "' . $path . '" (route name: "rest.entity.' . static::$entityTypeId . '.GET")';
$this->assertResourceErrorResponse(404, $message, $response);
// 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->assertSame($url->toString(TRUE)->getGeneratedUrl(), $bc_route->toString(TRUE)->getGeneratedUrl());
// 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.' . static::$entityTypeId . '.GET.' . $other_format, $url->getRouteParameters(), $url->getOptions());
$bc_route_other_format->setUrlGenerator($this->container->get('url_generator'));
$this->setExpectedException(RouteNotFoundException::class);
$bc_route_other_format->toString(TRUE);
}
/**
......
......@@ -3,6 +3,7 @@
namespace Drupal\Tests\rest\Functional\EntityResource\EntityTest;
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
use Drupal\Tests\rest\Functional\EntityResource\FormatSpecificGetBcRouteTestTrait;
/**
* @group rest
......@@ -10,6 +11,7 @@
class EntityTestJsonAnonTest extends EntityTestResourceTestBase {
use AnonResourceTestTrait;
use FormatSpecificGetBcRouteTestTrait;
/**
* {@inheritdoc}
......
......@@ -5,11 +5,13 @@
use Drupal\entity_test\Entity\EntityTest;
use Drupal\Tests\rest\Functional\BcTimestampNormalizerUnixTestTrait;
use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase;
use Drupal\Tests\Traits\ExpectDeprecationTrait;
use Drupal\user\Entity\User;
abstract class EntityTestResourceTestBase extends EntityResourceTestBase {
use BcTimestampNormalizerUnixTestTrait;
use ExpectDeprecationTrait;
/**
* {@inheritdoc}
......
......@@ -3,6 +3,7 @@
namespace Drupal\Tests\rest\Functional\EntityResource\EntityTest;
use Drupal\Tests\rest\Functional\AnonResourceTestTrait;
use Drupal\Tests\rest\Functional\EntityResource\FormatSpecificGetBcRouteTestTrait;
use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait;
/**
......@@ -11,6 +12,7 @@
class EntityTestXmlAnonTest extends EntityTestResourceTestBase {
use AnonResourceTestTrait;
use FormatSpecificGetBcRouteTestTrait;
use XmlEntityNormalizationQuirksTrait;
/**
......
<?php
namespace Drupal\Tests\rest\Functional\EntityResource;
use Drupal\Core\Url;
use Symfony\Component\Routing\Exception\RouteNotFoundException;
/**
* Provides test methods to assert BC on format-specific GET routes.
*
* @internal
*/
trait FormatSpecificGetBcRouteTestTrait {
/**
* @group legacy
*
* @see \Drupal\rest\RouteProcessor\RestResourceGetRouteProcessorBC
*/
public function testFormatSpecificGetBcRoute() {
$this->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);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment