public function NodeResourceTestBase::testPatchPath in Drupal 10
Same name and namespace in other branches
- 8 core/modules/node/tests/src/Functional/Rest/NodeResourceTestBase.php \Drupal\Tests\node\Functional\Rest\NodeResourceTestBase::testPatchPath()
- 9 core/modules/node/tests/src/Functional/Rest/NodeResourceTestBase.php \Drupal\Tests\node\Functional\Rest\NodeResourceTestBase::testPatchPath()
Tests PATCHing a node's path with and without 'create url aliases'.
For a positive test, see the similar test coverage for Term.
See also
\Drupal\Tests\rest\Functional\EntityResource\Term\TermResourceTestBase::testPatchPath()
6 methods override NodeResourceTestBase::testPatchPath()
- ModeratedNodeXmlAnonTest::testPatchPath in core/
modules/ rest/ tests/ src/ Functional/ EntityResource/ ModeratedNode/ ModeratedNodeXmlAnonTest.php - Tests PATCHing a node's path with and without 'create url aliases'.
- ModeratedNodeXmlBasicAuthTest::testPatchPath in core/
modules/ rest/ tests/ src/ Functional/ EntityResource/ ModeratedNode/ ModeratedNodeXmlBasicAuthTest.php - Tests PATCHing a node's path with and without 'create url aliases'.
- ModeratedNodeXmlCookieTest::testPatchPath in core/
modules/ rest/ tests/ src/ Functional/ EntityResource/ ModeratedNode/ ModeratedNodeXmlCookieTest.php - Tests PATCHing a node's path with and without 'create url aliases'.
- NodeXmlAnonTest::testPatchPath in core/
modules/ node/ tests/ src/ Functional/ Rest/ NodeXmlAnonTest.php - Tests PATCHing a node's path with and without 'create url aliases'.
- NodeXmlBasicAuthTest::testPatchPath in core/
modules/ node/ tests/ src/ Functional/ Rest/ NodeXmlBasicAuthTest.php - Tests PATCHing a node's path with and without 'create url aliases'.
File
- core/
modules/ node/ tests/ src/ Functional/ Rest/ NodeResourceTestBase.php, line 231
Class
Namespace
Drupal\Tests\node\Functional\RestCode
public function testPatchPath() {
$this
->initAuthentication();
$this
->provisionEntityResource();
$this
->setUpAuthorization('GET');
$this
->setUpAuthorization('PATCH');
$url = $this
->getEntityResourceUrl()
->setOption('query', [
'_format' => static::$format,
]);
// GET node's current normalization.
$response = $this
->request('GET', $url, $this
->getAuthenticationRequestOptions('GET'));
$normalization = $this->serializer
->decode((string) $response
->getBody(), static::$format);
// Change node's path alias.
$normalization['path'][0]['alias'] .= 's-rule-the-world';
// Create node 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: 403 when creating URL aliases unauthorized. Before
// asserting the 403 response, assert that the stored path alias remains
// unchanged.
$response = $this
->request('PATCH', $url, $request_options);
$this
->assertSame('/llama', $this->entityStorage
->loadUnchanged($this->entity
->id())
->get('path')->alias);
$this
->assertResourceErrorResponse(403, "Access denied on updating field 'path'. " . static::$patchProtectedFieldNames['path'], $response);
// Grant permission to create URL aliases.
$this
->grantPermissionsToTestedRole([
'create url aliases',
]);
// Repeat 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']);
}