class OverrideSectionsTest
Same name in other branches
- 9 core/modules/layout_builder/tests/src/Functional/Rest/OverrideSectionsTest.php \Drupal\Tests\layout_builder\Functional\Rest\OverrideSectionsTest
- 8.9.x core/modules/layout_builder/tests/src/Functional/Rest/OverrideSectionsTest.php \Drupal\Tests\layout_builder\Functional\Rest\OverrideSectionsTest
- 11.x core/modules/layout_builder/tests/src/Functional/Rest/OverrideSectionsTest.php \Drupal\Tests\layout_builder\Functional\Rest\OverrideSectionsTest
Tests that override layout sections are not exposed via the REST API.
@group layout_builder @group rest
Hierarchy
- class \Drupal\Tests\BrowserTestBase extends \PHPUnit\Framework\TestCase uses \Drupal\Core\Test\FunctionalTestSetupTrait, \Drupal\Tests\UiHelperTrait, \Drupal\Core\Test\TestSetupTrait, \Drupal\Tests\block\Traits\BlockCreationTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\node\Traits\NodeCreationTrait, \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\user\Traits\UserCreationTrait, \Drupal\Tests\XdebugRequestTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\ExtensionListTestTrait
- class \Drupal\Tests\rest\Functional\ResourceTestBase extends \Drupal\Tests\BrowserTestBase
- class \Drupal\Tests\layout_builder\Functional\Rest\LayoutRestTestBase extends \Drupal\Tests\rest\Functional\ResourceTestBase uses \Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait
- class \Drupal\Tests\layout_builder\Functional\Rest\OverrideSectionsTest extends \Drupal\Tests\layout_builder\Functional\Rest\LayoutRestTestBase
- class \Drupal\Tests\layout_builder\Functional\Rest\LayoutRestTestBase extends \Drupal\Tests\rest\Functional\ResourceTestBase uses \Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait
- class \Drupal\Tests\rest\Functional\ResourceTestBase extends \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of OverrideSectionsTest
File
-
core/
modules/ layout_builder/ tests/ src/ Functional/ Rest/ OverrideSectionsTest.php, line 18
Namespace
Drupal\Tests\layout_builder\Functional\RestView source
class OverrideSectionsTest extends LayoutRestTestBase {
/**
* {@inheritdoc}
*/
protected static $resourceConfigId = 'entity.node';
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
// @todo Figure why field definitions have to cleared in
// https://www.drupal.org/project/drupal/issues/2985882.
$this->container
->get('entity_field.manager')
->clearCachedFieldDefinitions();
}
/**
* Tests that the layout override field is not normalized.
*/
public function testOverrideField() : void {
$this->assertCount(1, $this->node
->get(OverridesSectionStorage::FIELD_NAME));
// Make a GET request and ensure override field is not included.
$response = $this->request('GET', Url::fromRoute('rest.entity.node.GET', [
'node' => $this->node
->id(),
]));
$this->assertResourceResponse(200, FALSE, $response, [
'config:filter.format.plain_text',
'config:rest.resource.entity.node',
'http_response',
'node:1',
], [
'languages:language_interface',
'theme',
'url.site',
'user.permissions',
], FALSE, 'MISS');
$get_data = $this->getDecodedContents($response);
$this->assertSame('A node at rest will stay at rest.', $get_data['title'][0]['value']);
$this->assertArrayNotHasKey('layout_builder__layout', $get_data);
// Make a POST request without the override field.
$new_node = [
'type' => [
[
'target_id' => 'bundle_with_section_field',
],
],
'title' => [
[
'value' => 'On with the rest of the test.',
],
],
];
$response = $this->request('POST', Url::fromRoute('rest.entity.node.POST'), [
RequestOptions::BODY => $this->serializer
->encode($new_node, static::$format),
]);
$this->assertResourceResponse(201, FALSE, $response);
$posted_node = $this->nodeStorage
->load(2);
$this->assertEquals('On with the rest of the test.', $posted_node->getTitle());
// Make a POST request with override field.
$new_node['layout_builder__layout'] = [];
$post_contents = $this->serializer
->encode($new_node, static::$format);
$response = $this->request('POST', Url::fromRoute('rest.entity.node.POST'), [
RequestOptions::BODY => $post_contents,
]);
$this->assertResourceErrorResponse(403, 'Access denied on creating field \'layout_builder__layout\'.', $response);
// Make a PATCH request without the override field.
$patch_data = [
'title' => [
[
'value' => 'New and improved title',
],
],
'type' => [
[
'target_id' => 'bundle_with_section_field',
],
],
];
$response = $this->request('PATCH', Url::fromRoute('rest.entity.node.PATCH', [
'node' => 1,
]), [
RequestOptions::BODY => $this->serializer
->encode($patch_data, static::$format),
]);
$this->assertResourceResponse(200, FALSE, $response);
$this->nodeStorage
->resetCache([
1,
]);
$this->node = $this->nodeStorage
->load(1);
$this->assertEquals('New and improved title', $this->node
->getTitle());
// Make a PATCH request with the override field.
$patch_data['title'][0]['value'] = 'This title will not save.';
$patch_data['layout_builder__layout'] = [];
$response = $this->request('PATCH', Url::fromRoute('rest.entity.node.PATCH', [
'node' => 1,
]), [
RequestOptions::BODY => $this->serializer
->encode($patch_data, static::$format),
]);
$this->assertResourceErrorResponse(403, 'Access denied on updating field \'layout_builder__layout\'.', $response);
// Ensure the title has not changed.
$this->assertEquals('New and improved title', Node::load(1)->getTitle());
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title | Overrides |
---|---|---|---|---|---|
BasicAuthResourceTestTrait::getAuthenticationRequestOptions | protected | function | |||
BrowserTestBase::cleanupEnvironment | protected | function | Clean up the test environment. | ||
BrowserTestBase::config | protected | function | Configuration accessor for tests. Returns non-overridden configuration. | ||
BrowserTestBase::filePreDeleteCallback | public static | function | Ensures test files are deletable. | ||
BrowserTestBase::getDefaultDriverInstance | protected | function | Gets an instance of the default Mink driver. | ||
BrowserTestBase::getDrupalSettings | protected | function | Gets the JavaScript drupalSettings variable for the currently-loaded page. | 1 | |
BrowserTestBase::getHttpClient | protected | function | Obtain the HTTP client for the system under test. | ||
BrowserTestBase::getMinkDriverArgs | protected | function | Gets the Mink driver args from an environment variable. | 1 | |
BrowserTestBase::getOptions | protected | function | Helper function to get the options of select field. | ||
BrowserTestBase::getSession | public | function | Returns Mink session. | ||
BrowserTestBase::getSessionCookies | protected | function | Get session cookies from current session. | ||
BrowserTestBase::getTestMethodCaller | protected | function | Retrieves the current calling line in the class under test. | Overrides BrowserHtmlDebugTrait::getTestMethodCaller | |
BrowserTestBase::initFrontPage | protected | function | Visits the front page when initializing Mink. | 3 | |
BrowserTestBase::initMink | protected | function | Initializes Mink sessions. | 1 | |
BrowserTestBase::installDrupal | public | function | Installs Drupal into the test site. | 2 | |
BrowserTestBase::registerSessions | protected | function | Registers additional Mink sessions. | ||
BrowserTestBase::setUpAppRoot | protected | function | Sets up the root application path. | ||
BrowserTestBase::setUpBeforeClass | public static | function | 1 | ||
BrowserTestBase::tearDown | protected | function | 3 | ||
BrowserTestBase::translatePostValues | protected | function | Transforms a nested array into a flat array suitable for submitForm(). | ||
BrowserTestBase::xpath | protected | function | Performs an xpath search on the contents of the internal browser. | ||
BrowserTestBase::__get | public | function | |||
BrowserTestBase::__sleep | public | function | Prevents serializing any properties. | ||
FunctionalTestSetupTrait::prepareRequestForGenerator | protected | function | Creates a mock request and sets it on the generator. | ||
FunctionalTestSetupTrait::prepareSettings | protected | function | Prepares site settings and services before installation. | 4 | |
FunctionalTestSetupTrait::rebuildContainer | protected | function | Rebuilds \Drupal::getContainer(). | ||
FunctionalTestSetupTrait::resetAll | protected | function | Resets all data structures after having enabled new modules. | ||
FunctionalTestSetupTrait::setContainerParameter | protected | function | Changes parameters in the services.yml file. | ||
FunctionalTestSetupTrait::writeSettings | protected | function | Rewrites the settings.php file of the test site. | 1 | |
LayoutRestTestBase::assertAuthenticationEdgeCases | protected | function | Overrides BasicAuthResourceTestTrait::assertAuthenticationEdgeCases | ||
LayoutRestTestBase::assertNormalizationEdgeCases | protected | function | Overrides ResourceTestBase::assertNormalizationEdgeCases | ||
LayoutRestTestBase::assertResponseWhenMissingAuthentication | protected | function | Overrides BasicAuthResourceTestTrait::assertResponseWhenMissingAuthentication | ||
LayoutRestTestBase::getDecodedContents | protected | function | Gets the decoded contents. | ||
LayoutRestTestBase::getExpectedUnauthorizedAccessCacheability | protected | function | Overrides ResourceTestBase::getExpectedUnauthorizedAccessCacheability | ||
LayoutRestTestBase::request | protected | function | Overrides ResourceTestBase::request | ||
LayoutRestTestBase::setUpAuthorization | protected | function | Overrides ResourceTestBase::setUpAuthorization | ||
OverrideSectionsTest::setUp | protected | function | Overrides LayoutRestTestBase::setUp | ||
OverrideSectionsTest::testOverrideField | public | function | Tests that the layout override field is not normalized. | ||
ResourceTestBase::assertResourceErrorResponse | protected | function | Asserts that a resource error response has the given message. | ||
ResourceTestBase::assertResourceResponse | protected | function | Asserts that a resource response has the given status code and body. | ||
ResourceTestBase::decorateWithXdebugCookie | protected | function | Adds the Xdebug cookie to the request options. | ||
ResourceTestBase::getExpectedUnauthorizedAccessMessage | protected | function | Return the expected error message. | 5 | |
ResourceTestBase::grantPermissionsToAnonymousRole | protected | function | Grants permissions to the anonymous role. | ||
ResourceTestBase::grantPermissionsToAuthenticatedRole | protected | function | Grants permissions to the authenticated role. | ||
ResourceTestBase::grantPermissionsToTestedRole | protected | function | Grants permissions to the tested role: anonymous or authenticated. | ||
ResourceTestBase::initAuthentication | protected | function | Initializes authentication. | ||
ResourceTestBase::provisionResource | protected | function | Provisions the REST resource under test. | ||
ResourceTestBase::recursiveKSort | protected static | function | Recursively sorts an array by key. | ||
ResourceTestBase::refreshTestStateAfterRestConfigChange | protected | function | Refreshes the state of the tester to be in sync with the testee. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.