View source
<?php
namespace Drupal\Tests\layout_builder\Functional\Rest;
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Url;
use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait;
use Drupal\Tests\rest\Functional\ResourceTestBase;
use GuzzleHttp\RequestOptions;
use Psr\Http\Message\ResponseInterface;
abstract class LayoutRestTestBase extends ResourceTestBase {
use BasicAuthResourceTestTrait;
protected static $modules = [
'node',
'layout_builder',
'serialization',
'basic_auth',
];
protected $node;
protected $nodeStorage;
public function setUp() {
parent::setUp();
$assert_session = $this
->assertSession();
$this
->createContentType([
'type' => 'bundle_with_section_field',
]);
$this
->drupalLogin($this
->drupalCreateUser([
'configure any layout',
'administer node display',
'administer display modes',
'bypass node access',
'create bundle_with_section_field content',
'edit any bundle_with_section_field content',
]));
$page = $this
->getSession()
->getPage();
$field_ui_prefix = 'admin/structure/types/manage/bundle_with_section_field/display';
$this
->drupalGet("{$field_ui_prefix}/default");
$page
->checkField('layout[enabled]');
$page
->pressButton('Save');
$page
->checkField('layout[allow_custom]');
$page
->pressButton('Save');
$this->node = $this
->createNode([
'type' => 'bundle_with_section_field',
'title' => 'A node at rest will stay at rest.',
]);
$this
->drupalGet('node/' . $this->node
->id() . '/layout');
$page
->clickLink('Add block');
$page
->clickLink('Powered by Drupal');
$page
->fillField('settings[label]', 'This is an override');
$page
->checkField('settings[label_display]');
$page
->pressButton('Add block');
$page
->pressButton('Save layout');
$assert_session
->pageTextContains('This is an override');
$this->nodeStorage = $this->container
->get('entity_type.manager')
->getStorage('node');
$this->node = $this->nodeStorage
->load($this->node
->id());
$this
->drupalLogout();
$this
->setUpAuthorization('ALL');
$this
->provisionResource([
static::$format,
], [
'basic_auth',
]);
}
protected function request($method, Url $url, array $request_options = []) {
$request_options[RequestOptions::HEADERS] = [
'Content-Type' => static::$mimeType,
];
$request_options = NestedArray::mergeDeep($request_options, $this
->getAuthenticationRequestOptions($method));
$request_options[RequestOptions::QUERY] = [
'_format' => static::$format,
];
return parent::request($method, $url, $request_options);
}
protected function setUpAuthorization($method) {
$permissions = array_keys($this->container
->get('user.permissions')
->getPermissions());
$this->account = $this
->drupalCreateUser($permissions);
}
protected function assertResponseWhenMissingAuthentication($method, ResponseInterface $response) {
}
protected function assertNormalizationEdgeCases($method, Url $url, array $request_options) {
}
protected function assertAuthenticationEdgeCases($method, Url $url, array $request_options) {
}
protected function getExpectedUnauthorizedAccessCacheability() {
}
protected function getDecodedContents(ResponseInterface $response) {
return $this->serializer
->decode((string) $response
->getBody(), static::$format);
}
}