function TermTest::testPatchPath
Same name in other branches
- 9 core/modules/jsonapi/tests/src/Functional/TermTest.php \Drupal\Tests\jsonapi\Functional\TermTest::testPatchPath()
- 10 core/modules/jsonapi/tests/src/Functional/TermTest.php \Drupal\Tests\jsonapi\Functional\TermTest::testPatchPath()
- 11.x core/modules/jsonapi/tests/src/Functional/TermTest.php \Drupal\Tests\jsonapi\Functional\TermTest::testPatchPath()
Tests PATCHing a term's path.
For a negative test, see the similar test coverage for Node.
See also
\Drupal\Tests\jsonapi\Functional\NodeTest::testPatchPath()
\Drupal\Tests\rest\Functional\EntityResource\Node\NodeResourceTestBase::testPatchPath()
File
-
core/
modules/ jsonapi/ tests/ src/ Functional/ TermTest.php, line 370
Class
- TermTest
- JSON:API integration test for the "Term" content entity type.
Namespace
Drupal\Tests\jsonapi\FunctionalCode
public function testPatchPath() {
$this->setUpAuthorization('GET');
$this->setUpAuthorization('PATCH');
$this->config('jsonapi.settings')
->set('read_only', FALSE)
->save(TRUE);
// @todo Remove line below in favor of commented line in https://www.drupal.org/project/drupal/issues/2878463.
$url = Url::fromRoute(sprintf('jsonapi.%s.individual', static::$resourceTypeName), [
'entity' => $this->entity
->uuid(),
]);
// $url = $this->entity->toUrl('jsonapi');
$request_options = [];
$request_options[RequestOptions::HEADERS]['Accept'] = 'application/vnd.api+json';
$request_options[RequestOptions::HEADERS]['Content-Type'] = 'application/vnd.api+json';
$request_options = NestedArray::mergeDeep($request_options, $this->getAuthenticationRequestOptions());
// GET term's current normalization.
$response = $this->request('GET', $url, $request_options);
$normalization = Json::decode((string) $response->getBody());
// Change term's path alias.
$normalization['data']['attributes']['path']['alias'] .= 's-rule-the-world';
// Create term PATCH request.
$request_options[RequestOptions::BODY] = Json::encode($normalization);
// PATCH request: 200.
$response = $this->request('PATCH', $url, $request_options);
$this->assertResourceResponse(200, FALSE, $response);
$updated_normalization = Json::decode((string) $response->getBody());
$this->assertSame($normalization['data']['attributes']['path']['alias'], $updated_normalization['data']['attributes']['path']['alias']);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.