You are here

public function RestResourceConfigTest::testNormalizeRestMethod in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/rest/tests/src/Unit/Entity/RestResourceConfigTest.php \Drupal\Tests\rest\Unit\Entity\RestResourceConfigTest::testNormalizeRestMethod()
  2. 9 core/modules/rest/tests/src/Unit/Entity/RestResourceConfigTest.php \Drupal\Tests\rest\Unit\Entity\RestResourceConfigTest::testNormalizeRestMethod()

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.

File

core/modules/rest/tests/src/Unit/Entity/RestResourceConfigTest.php, line 22

Class

RestResourceConfigTest
@coversDefaultClass \Drupal\rest\Entity\RestResourceConfig

Namespace

Drupal\Tests\rest\Unit\Entity

Code

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
    ->assertEquals($expected, $entity
    ->getMethods());
}