diff --git a/core/modules/layout_builder/tests/src/Functional/Hal/LayoutBuilderEntityViewDisplayHalJsonAnonTest.php b/core/modules/layout_builder/tests/src/Functional/Hal/LayoutBuilderEntityViewDisplayHalJsonAnonTest.php new file mode 100644 index 0000000000000000000000000000000000000000..1740380108daf9e8f8c778805d2249983ec02173 --- /dev/null +++ b/core/modules/layout_builder/tests/src/Functional/Hal/LayoutBuilderEntityViewDisplayHalJsonAnonTest.php @@ -0,0 +1,31 @@ +<?php + +namespace Drupal\Tests\layout_builder\Functional\Hal; + +use Drupal\Tests\layout_builder\Functional\Rest\LayoutBuilderEntityViewDisplayResourceTestBase; +use Drupal\Tests\rest\Functional\AnonResourceTestTrait; + +/** + * @group layout_builder + * @group rest + */ +class LayoutBuilderEntityViewDisplayHalJsonAnonTest extends LayoutBuilderEntityViewDisplayResourceTestBase { + + use AnonResourceTestTrait; + + /** + * {@inheritdoc} + */ + public static $modules = ['hal']; + + /** + * {@inheritdoc} + */ + protected static $format = 'hal_json'; + + /** + * {@inheritdoc} + */ + protected static $mimeType = 'application/hal+json'; + +} diff --git a/core/modules/layout_builder/tests/src/Functional/Hal/LayoutBuilderEntityViewDisplayHalJsonBasicAuthTest.php b/core/modules/layout_builder/tests/src/Functional/Hal/LayoutBuilderEntityViewDisplayHalJsonBasicAuthTest.php new file mode 100644 index 0000000000000000000000000000000000000000..e008e042bd106b537c1de675e9cf367aedaef00b --- /dev/null +++ b/core/modules/layout_builder/tests/src/Functional/Hal/LayoutBuilderEntityViewDisplayHalJsonBasicAuthTest.php @@ -0,0 +1,26 @@ +<?php + +namespace Drupal\Tests\layout_builder\Functional\Hal; + +use Drupal\FunctionalTests\Hal\EntityViewDisplayHalJsonAnonTest; +use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait; + +/** + * @group layout_builder + * @group rest + */ +class LayoutBuilderEntityViewDisplayHalJsonBasicAuthTest extends EntityViewDisplayHalJsonAnonTest { + + use BasicAuthResourceTestTrait; + + /** + * {@inheritdoc} + */ + public static $modules = ['basic_auth']; + + /** + * {@inheritdoc} + */ + protected static $auth = 'basic_auth'; + +} diff --git a/core/modules/layout_builder/tests/src/Functional/Hal/LayoutBuilderEntityViewDisplayHalJsonCookieTest.php b/core/modules/layout_builder/tests/src/Functional/Hal/LayoutBuilderEntityViewDisplayHalJsonCookieTest.php new file mode 100644 index 0000000000000000000000000000000000000000..bbc17736b7e748aa3d8b6552d19b602b182a9dab --- /dev/null +++ b/core/modules/layout_builder/tests/src/Functional/Hal/LayoutBuilderEntityViewDisplayHalJsonCookieTest.php @@ -0,0 +1,20 @@ +<?php + +namespace Drupal\Tests\layout_builder\Functional\Hal; + +use Drupal\Tests\rest\Functional\CookieResourceTestTrait; + +/** + * @group layout_builder + * @group rest + */ +class LayoutBuilderEntityViewDisplayHalJsonCookieTest extends LayoutBuilderEntityViewDisplayHalJsonAnonTest { + + use CookieResourceTestTrait; + + /** + * {@inheritdoc} + */ + protected static $auth = 'cookie'; + +} diff --git a/core/modules/layout_builder/tests/src/Functional/Rest/EntityDisplaySectionsTest.php b/core/modules/layout_builder/tests/src/Functional/Rest/EntityDisplaySectionsTest.php deleted file mode 100644 index 32abc1c95de4d2d545d52aa8aaf89285aa920b8e..0000000000000000000000000000000000000000 --- a/core/modules/layout_builder/tests/src/Functional/Rest/EntityDisplaySectionsTest.php +++ /dev/null @@ -1,61 +0,0 @@ -<?php - -namespace Drupal\Tests\layout_builder\Functional\Rest; - -use Drupal\Core\Entity\Entity\EntityViewDisplay; -use Drupal\Core\Url; - -/** - * Tests that default layout sections are not exposed via the REST API. - * - * @group layout_builder - * @group rest - */ -class EntityDisplaySectionsTest extends LayoutRestTestBase { - - /** - * {@inheritdoc} - */ - protected static $resourceConfigId = 'entity.entity_view_display'; - - /** - * Tests the normalization does not contain layout sections. - */ - public function testLayoutEntityDisplay() { - $display_id = 'node.bundle_with_section_field.default'; - $display = EntityViewDisplay::load($display_id); - - // Assert the display has 1 section. - $this->assertCount(1, $display->getThirdPartySetting('layout_builder', 'sections')); - $response = $this->request( - 'GET', - Url::fromRoute( - 'rest.entity.entity_view_display.GET', - ['entity_view_display' => 'node.bundle_with_section_field.default']) - ); - $this->assertResourceResponse( - 200, - FALSE, - $response, - [ - 'config:core.entity_view_display.node.bundle_with_section_field.default', - 'config:rest.resource.entity.entity_view_display', - 'config:rest.settings', - 'http_response', - ], - [ - 'user.permissions', - ], - FALSE, - 'MISS' - ); - $response_data = $this->getDecodedContents($response); - $this->assertSame($display_id, $response_data['id']); - // Ensure the sections are not present in the serialized data, but other - // Layout Builder data is. - $this->assertArrayHasKey('layout_builder', $response_data['third_party_settings']); - $this->assertArrayNotHasKey('sections', $response_data['third_party_settings']['layout_builder']); - $this->assertEquals(['enabled' => TRUE, 'allow_custom' => TRUE], $response_data['third_party_settings']['layout_builder']); - } - -} diff --git a/core/modules/layout_builder/tests/src/Functional/Rest/LayoutBuilderEntityViewDisplayJsonAnonTest.php b/core/modules/layout_builder/tests/src/Functional/Rest/LayoutBuilderEntityViewDisplayJsonAnonTest.php new file mode 100644 index 0000000000000000000000000000000000000000..61fa91eff913ad3b6f70d469d5ec8cf74d3396e5 --- /dev/null +++ b/core/modules/layout_builder/tests/src/Functional/Rest/LayoutBuilderEntityViewDisplayJsonAnonTest.php @@ -0,0 +1,25 @@ +<?php + +namespace Drupal\Tests\layout_builder\Functional\Rest; + +use Drupal\Tests\rest\Functional\AnonResourceTestTrait; + +/** + * @group layout_builder + * @group rest + */ +class LayoutBuilderEntityViewDisplayJsonAnonTest extends LayoutBuilderEntityViewDisplayResourceTestBase { + + use AnonResourceTestTrait; + + /** + * {@inheritdoc} + */ + protected static $format = 'json'; + + /** + * {@inheritdoc} + */ + protected static $mimeType = 'application/json'; + +} diff --git a/core/modules/layout_builder/tests/src/Functional/Rest/LayoutBuilderEntityViewDisplayJsonBasicAuthTest.php b/core/modules/layout_builder/tests/src/Functional/Rest/LayoutBuilderEntityViewDisplayJsonBasicAuthTest.php new file mode 100644 index 0000000000000000000000000000000000000000..d92138f984639651f2700fad8f989b5d0f8e4e91 --- /dev/null +++ b/core/modules/layout_builder/tests/src/Functional/Rest/LayoutBuilderEntityViewDisplayJsonBasicAuthTest.php @@ -0,0 +1,35 @@ +<?php + +namespace Drupal\Tests\layout_builder\Functional\Rest; + +use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait; + +/** + * @group layout_builder + * @group rest + */ +class LayoutBuilderEntityViewDisplayJsonBasicAuthTest extends LayoutBuilderEntityViewDisplayResourceTestBase { + + use BasicAuthResourceTestTrait; + + /** + * {@inheritdoc} + */ + public static $modules = ['basic_auth']; + + /** + * {@inheritdoc} + */ + protected static $format = 'json'; + + /** + * {@inheritdoc} + */ + protected static $mimeType = 'application/json'; + + /** + * {@inheritdoc} + */ + protected static $auth = 'basic_auth'; + +} diff --git a/core/modules/layout_builder/tests/src/Functional/Rest/LayoutBuilderEntityViewDisplayJsonCookieTest.php b/core/modules/layout_builder/tests/src/Functional/Rest/LayoutBuilderEntityViewDisplayJsonCookieTest.php new file mode 100644 index 0000000000000000000000000000000000000000..c96e7641b27eba001cc3b163b338931cfd7c8335 --- /dev/null +++ b/core/modules/layout_builder/tests/src/Functional/Rest/LayoutBuilderEntityViewDisplayJsonCookieTest.php @@ -0,0 +1,30 @@ +<?php + +namespace Drupal\Tests\layout_builder\Functional\Rest; + +use Drupal\Tests\rest\Functional\CookieResourceTestTrait; + +/** + * @group layout_builder + * @group rest + */ +class LayoutBuilderEntityViewDisplayJsonCookieTest extends LayoutBuilderEntityViewDisplayResourceTestBase { + + use CookieResourceTestTrait; + + /** + * {@inheritdoc} + */ + protected static $format = 'json'; + + /** + * {@inheritdoc} + */ + protected static $mimeType = 'application/json'; + + /** + * {@inheritdoc} + */ + protected static $auth = 'cookie'; + +} diff --git a/core/modules/layout_builder/tests/src/Functional/Rest/LayoutBuilderEntityViewDisplayResourceTestBase.php b/core/modules/layout_builder/tests/src/Functional/Rest/LayoutBuilderEntityViewDisplayResourceTestBase.php new file mode 100644 index 0000000000000000000000000000000000000000..7da257f4a7083e7b8c9ed0fcc4504781ab33249f --- /dev/null +++ b/core/modules/layout_builder/tests/src/Functional/Rest/LayoutBuilderEntityViewDisplayResourceTestBase.php @@ -0,0 +1,46 @@ +<?php + +namespace Drupal\Tests\layout_builder\Functional\Rest; + +use Drupal\FunctionalTests\Rest\EntityViewDisplayResourceTestBase; +use Drupal\layout_builder\Plugin\SectionStorage\OverridesSectionStorage; + +/** + * Provides a base class for testing LayoutBuilderEntityViewDisplay resources. + */ +abstract class LayoutBuilderEntityViewDisplayResourceTestBase extends EntityViewDisplayResourceTestBase { + + /** + * {@inheritdoc} + */ + public static $modules = ['layout_builder']; + + /** + * {@inheritdoc} + */ + protected function createEntity() { + /** @var \Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay $entity */ + $entity = parent::createEntity(); + $entity + ->enableLayoutBuilder() + ->setOverridable() + ->save(); + $this->assertCount(1, $entity->getThirdPartySetting('layout_builder', 'sections')); + return $entity; + } + + /** + * {@inheritdoc} + */ + protected function getExpectedNormalizedEntity() { + $expected = parent::getExpectedNormalizedEntity(); + array_unshift($expected['dependencies']['module'], 'layout_builder'); + $expected['hidden'][OverridesSectionStorage::FIELD_NAME] = TRUE; + $expected['third_party_settings']['layout_builder'] = [ + 'enabled' => TRUE, + 'allow_custom' => TRUE, + ]; + return $expected; + } + +} diff --git a/core/modules/layout_builder/tests/src/Functional/Rest/LayoutBuilderEntityViewDisplayXmlAnonTest.php b/core/modules/layout_builder/tests/src/Functional/Rest/LayoutBuilderEntityViewDisplayXmlAnonTest.php new file mode 100644 index 0000000000000000000000000000000000000000..8c337c6552d5ec3a9bd7709fdbc37c47b7d8575c --- /dev/null +++ b/core/modules/layout_builder/tests/src/Functional/Rest/LayoutBuilderEntityViewDisplayXmlAnonTest.php @@ -0,0 +1,27 @@ +<?php + +namespace Drupal\Tests\layout_builder\Functional\Rest; + +use Drupal\Tests\rest\Functional\AnonResourceTestTrait; +use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait; + +/** + * @group layout_builder + * @group rest + */ +class LayoutBuilderEntityViewDisplayXmlAnonTest extends LayoutBuilderEntityViewDisplayResourceTestBase { + + use AnonResourceTestTrait; + use XmlEntityNormalizationQuirksTrait; + + /** + * {@inheritdoc} + */ + protected static $format = 'xml'; + + /** + * {@inheritdoc} + */ + protected static $mimeType = 'text/xml; charset=UTF-8'; + +} diff --git a/core/modules/layout_builder/tests/src/Functional/Rest/LayoutBuilderEntityViewDisplayXmlBasicAuthTest.php b/core/modules/layout_builder/tests/src/Functional/Rest/LayoutBuilderEntityViewDisplayXmlBasicAuthTest.php new file mode 100644 index 0000000000000000000000000000000000000000..6ec5880699fe13f4c6ceaa5e3b164006eaa62834 --- /dev/null +++ b/core/modules/layout_builder/tests/src/Functional/Rest/LayoutBuilderEntityViewDisplayXmlBasicAuthTest.php @@ -0,0 +1,37 @@ +<?php + +namespace Drupal\Tests\layout_builder\Functional\Rest; + +use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait; +use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait; + +/** + * @group layout_builder + * @group rest + */ +class LayoutBuilderEntityViewDisplayXmlBasicAuthTest extends LayoutBuilderEntityViewDisplayResourceTestBase { + + use BasicAuthResourceTestTrait; + use XmlEntityNormalizationQuirksTrait; + + /** + * {@inheritdoc} + */ + public static $modules = ['basic_auth']; + + /** + * {@inheritdoc} + */ + protected static $format = 'xml'; + + /** + * {@inheritdoc} + */ + protected static $mimeType = 'text/xml; charset=UTF-8'; + + /** + * {@inheritdoc} + */ + protected static $auth = 'basic_auth'; + +} diff --git a/core/modules/layout_builder/tests/src/Functional/Rest/LayoutBuilderEntityViewDisplayXmlCookieTest.php b/core/modules/layout_builder/tests/src/Functional/Rest/LayoutBuilderEntityViewDisplayXmlCookieTest.php new file mode 100644 index 0000000000000000000000000000000000000000..92925eca90ea8b394e4ff320c9389f2a7faa50c5 --- /dev/null +++ b/core/modules/layout_builder/tests/src/Functional/Rest/LayoutBuilderEntityViewDisplayXmlCookieTest.php @@ -0,0 +1,32 @@ +<?php + +namespace Drupal\Tests\layout_builder\Functional\Rest; + +use Drupal\Tests\rest\Functional\CookieResourceTestTrait; +use Drupal\Tests\rest\Functional\EntityResource\XmlEntityNormalizationQuirksTrait; + +/** + * @group layout_builder + * @group rest + */ +class LayoutBuilderEntityViewDisplayXmlCookieTest extends LayoutBuilderEntityViewDisplayResourceTestBase { + + use CookieResourceTestTrait; + use XmlEntityNormalizationQuirksTrait; + + /** + * {@inheritdoc} + */ + protected static $format = 'xml'; + + /** + * {@inheritdoc} + */ + protected static $mimeType = 'text/xml; charset=UTF-8'; + + /** + * {@inheritdoc} + */ + protected static $auth = 'cookie'; + +}