Problem/Motivation

As seen in #3041053-2: Mark Layout Builder as a stable module, \Drupal\Tests\rest\Functional\EntityResource\EntityResourceRestTestCoverageTest enforces a set of expected tests for all stable modules.

Proposed resolution

Replace the existing one-off EntityDisplaySectionsTest with the expected suite.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Comments

tim.plunkett created an issue. See original summary.

tim.plunkett’s picture

Status: Active » Needs review
StatusFileSize
new14.03 KB
new13.26 KB
new789 bytes

The FAIL patch comments out the line in \Drupal\layout_builder\Normalizer\LayoutEntityDisplayNormalizer that removes the section data we do not want to expose.

wim leers’s picture

Issue tags: +API-First Initiative
  1. +++ b/core/modules/layout_builder/tests/src/Functional/Hal/LayoutBuilderEntityViewDisplayHalJsonAnonTest.php
    @@ -0,0 +1,31 @@
    +  public static $modules = ['layout_builder', 'hal'];
    
    +++ b/core/modules/layout_builder/tests/src/Functional/Hal/LayoutBuilderEntityViewDisplayHalJsonBasicAuthTest.php
    @@ -0,0 +1,26 @@
    +  public static $modules = ['layout_builder', 'basic_auth'];
    
    +++ b/core/modules/layout_builder/tests/src/Functional/Hal/LayoutBuilderEntityViewDisplayHalJsonCookieTest.php
    @@ -0,0 +1,25 @@
    +  public static $modules = ['layout_builder'];
    
    +++ b/core/modules/layout_builder/tests/src/Functional/Rest/LayoutBuilderEntityViewDisplayJsonAnonTest.php
    @@ -0,0 +1,30 @@
    +  public static $modules = ['layout_builder'];
    
    +++ b/core/modules/layout_builder/tests/src/Functional/Rest/LayoutBuilderEntityViewDisplayResourceTestBase.php
    @@ -0,0 +1,45 @@
    +abstract class LayoutBuilderEntityViewDisplayResourceTestBase extends EntityViewDisplayResourceTestBase {
    
    +++ b/core/modules/layout_builder/tests/src/Functional/Rest/LayoutBuilderEntityViewDisplayXmlAnonTest.php
    @@ -0,0 +1,32 @@
    +  public static $modules = ['layout_builder'];
    

    🔍🤔 Übernit: you can omit 'layout_builder' from these and just set this in the base test class :)

  2. +++ b/core/modules/layout_builder/tests/src/Functional/Rest/LayoutBuilderEntityViewDisplayResourceTestBase.php
    @@ -0,0 +1,45 @@
    +  protected static $resourceConfigId = 'entity.entity_view_display';
    

    🤔 AFAICT this can be removed?

  3. +++ b/core/modules/layout_builder/tests/src/Functional/Rest/LayoutBuilderEntityViewDisplayResourceTestBase.php
    @@ -0,0 +1,45 @@
    +  protected function createEntity() {
    +    /** @var \Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay $entity */
    +    $entity = parent::createEntity();
    +    $entity
    +      ->enableLayoutBuilder()
    +      ->setOverridable()
    +      ->save();
    +    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;
    +  }
    

    👍 Perfect!

The last submitted patch, 2: 3041107-rest-2-FAIL.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

wim leers’s picture

StatusFileSize
new8.03 KB
new12.75 KB

Addressed #3.

As far as I'm concerned, this is then RTBC. @tim.plunkett, are you +1 to the changes in this interdiff?

tim.plunkett’s picture

I had the same interdiff I was about to post. So yes, agreed! This looks great, happy to be doing things The Right Way™

wim leers’s picture

Status: Needs review » Reviewed & tested by the community

Alright, RTBC it is then 🥳

wim leers’s picture

+++ /dev/null
@@ -1,61 +0,0 @@
-    // 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']);

+++ b/core/modules/layout_builder/tests/src/Functional/Rest/LayoutBuilderEntityViewDisplayResourceTestBase.php
@@ -0,0 +1,45 @@
+  protected function createEntity() {
+    /** @var \Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay $entity */
+    $entity = parent::createEntity();
+    $entity
+      ->enableLayoutBuilder()
+      ->setOverridable()
+      ->save();
+    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,

For core committers: these assertions have essentially been moved and now run in more scenarios.

tim.plunkett’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new785 bytes
new12.82 KB

Okay not 100% the same as I had locally, because I fixed the @todo I left in there.

wim leers’s picture

Status: Needs review » Reviewed & tested by the community

Ah yes, thanks! I had forgotten to call that out in my review even though I noticed it. My bad. Thanks for fixing it!

xjm’s picture

Guessing this is about the most literal stable blocker we could have.

xjm’s picture

Status: Reviewed & tested by the community » Needs review
+++ /dev/null
@@ -1,61 +0,0 @@
-    // Assert the display has 1 section.
-    $this->assertCount(1, $display->getThirdPartySetting('layout_builder', 'sections'));

+++ b/core/modules/layout_builder/tests/src/Functional/Rest/LayoutBuilderEntityViewDisplayResourceTestBase.php
@@ -0,0 +1,45 @@
+  protected function createEntity() {
+    /** @var \Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay $entity */
+    $entity = parent::createEntity();
+    $entity
+      ->enableLayoutBuilder()
+      ->setOverridable()
+      ->save();
+    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;
+  }

One thing we're losing here is assertions about the expected format of the entity when not served over REST (basically, that the layout has one section which is not served over REST because we've excluded section data from the response). So the test could have a false positive from a layout with no sections... and actually, didn't we change the default behavior to no longer add a section automatically, so it'd be easy to get in a situation that has that false positive?

tim.plunkett’s picture

StatusFileSize
new12.91 KB
new728 bytes

Defaults get one section by default for all the fields that were previously displayed. But just to help prove there's no regression, I can add this.

wim leers’s picture

Status: Needs review » Reviewed & tested by the community
xjm’s picture

Version: 8.8.x-dev » 8.7.x-dev

That works. This is ready for commit after the freeze is over.

  • xjm committed fe95def on 8.8.x
    Issue #3041107 by tim.plunkett, Wim Leers, xjm: Remove...
xjm’s picture

Committed and pushed to 8.8.x. We'll backport to 8.7.x in a bit.

Thanks!

  • xjm committed e67533f on 8.7.x
    Issue #3041107 by tim.plunkett, Wim Leers, xjm: Remove...
gábor hojtsy’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.