diff --git a/core/modules/rest/src/Entity/RestResourceConfig.php b/core/modules/rest/src/Entity/RestResourceConfig.php index a31a1a4cf1f6aa605e3e11637d5d690aa0577662..bb835841610e2efe9e82db6ae7347595ca16f5d4 100644 --- a/core/modules/rest/src/Entity/RestResourceConfig.php +++ b/core/modules/rest/src/Entity/RestResourceConfig.php @@ -243,24 +243,16 @@ protected function getRestResourceDependencies() { } /** - * Normalizes the method to upper case and check validity. + * Normalizes the method. * * @param string $method * The request method. * * @return string - * The normalised request method. - * - * @throws \InvalidArgumentException - * If the method is not supported. + * The normalized request method. */ protected function normalizeRestMethod($method) { - $valid_methods = ['GET', 'POST', 'PATCH', 'DELETE']; - $normalised_method = strtoupper($method); - if (!in_array($normalised_method, $valid_methods)) { - throw new \InvalidArgumentException('The method is not supported.'); - } - return $normalised_method; + return strtoupper($method); } } diff --git a/core/modules/rest/tests/src/Unit/Entity/RestResourceConfigTest.php b/core/modules/rest/tests/src/Unit/Entity/RestResourceConfigTest.php new file mode 100644 index 0000000000000000000000000000000000000000..f60225e5eae2e88b17851c14381af1d7f99795ff --- /dev/null +++ b/core/modules/rest/tests/src/Unit/Entity/RestResourceConfigTest.php @@ -0,0 +1,42 @@ +<?php + +namespace Drupal\Tests\rest\Unit\Entity; + +use Drupal\rest\Entity\RestResourceConfig; +use Drupal\rest\RestResourceConfigInterface; +use Drupal\Tests\UnitTestCase; + +/** + * @coversDefaultClass \Drupal\rest\Entity\RestResourceConfig + * + * @group rest + */ +class RestResourceConfigTest extends UnitTestCase { + + /** + * Asserts that rest methods are normalized to upper case. + * + * This also tests that no exceptions are thrown during that method so that + * alternate methods such as OPTIONS and PUT are supported. + */ + public function testNormalizeRestMethod() { + $expected = ['GET', 'PUT', 'POST', 'PATCH', 'DELETE', 'OPTIONS', 'FOO']; + $methods = ['get', 'put', 'post', 'patch', 'delete', 'options', 'foo']; + $configuration = []; + foreach ($methods as $method) { + $configuration[$method] = [ + 'supported_auth' => ['cookie'], + 'supported_formats' => ['json'], + ]; + } + + $entity = new RestResourceConfig([ + 'plugin_id' => 'entity:entity_test', + 'granularity' => RestResourceConfigInterface::METHOD_GRANULARITY, + 'configuration' => $configuration, + ], 'rest_resource_config'); + + $this->assertArrayEquals($expected, $entity->getMethods()); + } + +}