Commit d553a65e authored by catch's avatar catch

Issue #3013125 by tim.plunkett, johndevman, Dylan Donkersgoed: Content section...

Issue #3013125 by tim.plunkett, johndevman, Dylan Donkersgoed: Content section component label_display setting is not saved when unchecked
parent 39f95a14
......@@ -3,6 +3,8 @@
namespace Drupal\layout_builder\Field;
use Drupal\Core\Field\FieldItemList;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\layout_builder\Section;
use Drupal\layout_builder\SectionListInterface;
use Drupal\layout_builder\SectionStorage\SectionStorageTrait;
......@@ -55,4 +57,21 @@ public function getEntity() {
return $entity;
}
/**
* {@inheritdoc}
*/
public function equals(FieldItemListInterface $list_to_compare) {
if (!$list_to_compare instanceof LayoutSectionItemList) {
return FALSE;
}
// Convert arrays of section objects to array values for comparison.
$convert = function (LayoutSectionItemList $list) {
return array_map(function (Section $section) {
return $section->toArray();
}, $list->getSections());
};
return $convert($this) === $convert($list_to_compare);
}
}
......@@ -59,6 +59,49 @@ protected function setUp() {
]);
}
/**
* Tests functionality of Layout Builder for overrides.
*/
public function testOverrides() {
$assert_session = $this->assertSession();
$page = $this->getSession()->getPage();
$this->drupalLogin($this->drupalCreateUser([
'configure any layout',
'administer node display',
]));
// From the manage display page, go to manage the layout.
$this->drupalGet('admin/structure/types/manage/bundle_with_section_field/display/default');
$this->drupalPostForm(NULL, ['layout[enabled]' => TRUE], 'Save');
$this->drupalPostForm(NULL, ['layout[allow_custom]' => TRUE], 'Save');
// @todo This should not be necessary.
$this->container->get('entity_field.manager')->clearCachedFieldDefinitions();
// Add a block with a custom label.
$this->drupalGet('node/1');
$page->clickLink('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->clickLink('Save Layout');
$assert_session->pageTextContains('This is an override');
// Get the UUID of the component.
$components = Node::load(1)->get('layout_builder__layout')->getSection(0)->getComponents();
end($components);
$uuid = key($components);
$this->drupalGet('layout_builder/update/block/overrides/node.1/0/content/' . $uuid);
$page->uncheckField('settings[label_display]');
$page->pressButton('Update');
$assert_session->pageTextNotContains('This is an override');
$page->clickLink('Save Layout');
$assert_session->pageTextNotContains('This is an override');
}
/**
* {@inheritdoc}
*/
......
......@@ -2,6 +2,7 @@
namespace Drupal\Tests\layout_builder\Kernel;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\entity_test\Entity\EntityTestBaseFieldDisplay;
use Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay;
use Drupal\layout_builder\Plugin\SectionStorage\OverridesSectionStorage;
......@@ -49,4 +50,25 @@ protected function getSectionStorage(array $section_data) {
return $entity->get(OverridesSectionStorage::FIELD_NAME);
}
/**
* @covers ::equals
*/
public function testEquals() {
$this->sectionStorage->getSection(0)->setLayoutSettings(['foo' => 1]);
$second_section_storage = clone $this->sectionStorage;
$this->assertTrue($this->sectionStorage->equals($second_section_storage));
$second_section_storage->getSection(0)->setLayoutSettings(['foo' => '1']);
$this->assertFalse($this->sectionStorage->equals($second_section_storage));
}
/**
* @covers ::equals
*/
public function testEqualsNonSection() {
$list = $this->prophesize(FieldItemListInterface::class);
$this->assertFalse($this->sectionStorage->equals($list->reveal()));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment