You are here

public function TermResourceTestBase::testPatchPath in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/taxonomy/tests/src/Functional/Rest/TermResourceTestBase.php \Drupal\Tests\taxonomy\Functional\Rest\TermResourceTestBase::testPatchPath()
  2. 9 core/modules/taxonomy/tests/src/Functional/Rest/TermResourceTestBase.php \Drupal\Tests\taxonomy\Functional\Rest\TermResourceTestBase::testPatchPath()

Tests PATCHing a term's path.

For a negative test, see the similar test coverage for Node.

See also

\Drupal\Tests\rest\Functional\EntityResource\Node\NodeResourceTestBase::testPatchPath()

3 methods override TermResourceTestBase::testPatchPath()
TermXmlAnonTest::testPatchPath in core/modules/taxonomy/tests/src/Functional/Rest/TermXmlAnonTest.php
Tests PATCHing a term's path.
TermXmlBasicAuthTest::testPatchPath in core/modules/taxonomy/tests/src/Functional/Rest/TermXmlBasicAuthTest.php
Tests PATCHing a term's path.
TermXmlCookieTest::testPatchPath in core/modules/taxonomy/tests/src/Functional/Rest/TermXmlCookieTest.php
Tests PATCHing a term's path.

File

core/modules/taxonomy/tests/src/Functional/Rest/TermResourceTestBase.php, line 285

Class

TermResourceTestBase

Namespace

Drupal\Tests\taxonomy\Functional\Rest

Code

public function testPatchPath() {
  $this
    ->initAuthentication();
  $this
    ->provisionEntityResource();
  $this
    ->setUpAuthorization('GET');
  $this
    ->setUpAuthorization('PATCH');
  $url = $this
    ->getEntityResourceUrl()
    ->setOption('query', [
    '_format' => static::$format,
  ]);

  // GET term's current normalization.
  $response = $this
    ->request('GET', $url, $this
    ->getAuthenticationRequestOptions('GET'));
  $normalization = $this->serializer
    ->decode((string) $response
    ->getBody(), static::$format);

  // Change term's path alias.
  $normalization['path'][0]['alias'] .= 's-rule-the-world';

  // Create term PATCH request.
  $request_options = [];
  $request_options[RequestOptions::HEADERS]['Content-Type'] = static::$mimeType;
  $request_options = array_merge_recursive($request_options, $this
    ->getAuthenticationRequestOptions('PATCH'));
  $request_options[RequestOptions::BODY] = $this->serializer
    ->encode($normalization, static::$format);

  // PATCH request: 200.
  $response = $this
    ->request('PATCH', $url, $request_options);
  $this
    ->assertResourceResponse(200, FALSE, $response);
  $updated_normalization = $this->serializer
    ->decode((string) $response
    ->getBody(), static::$format);
  $this
    ->assertSame($normalization['path'], $updated_normalization['path']);
}