function TermResourceTestBase::testPatchPath

Same name in other branches
  1. 9 core/modules/taxonomy/tests/src/Functional/Rest/TermResourceTestBase.php \Drupal\Tests\taxonomy\Functional\Rest\TermResourceTestBase::testPatchPath()
  2. 8.9.x core/modules/taxonomy/tests/src/Functional/Rest/TermResourceTestBase.php \Drupal\Tests\taxonomy\Functional\Rest\TermResourceTestBase::testPatchPath()
  3. 11.x 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()

File

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

Class

TermResourceTestBase

Namespace

Drupal\Tests\taxonomy\Functional\Rest

Code

public function testPatchPath() : void {
    $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']);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.