composer update

This commit is contained in:
Oliver Davies 2019-01-24 08:00:03 +00:00
parent f6abc3dce2
commit 71dfaca858
1753 changed files with 45274 additions and 14619 deletions

View file

@ -0,0 +1,3 @@
# See \Drupal\layout_builder_fieldblock_test\Plugin\Block\FieldBlock.
block.settings.field_block_test:*:*:*:
type: block.settings.field_block:*:*:*

View file

@ -0,0 +1,6 @@
name: 'Layout Builder test'
type: module
description: 'Support module for testing layout building.'
package: Testing
version: VERSION
core: 8.x

View file

@ -0,0 +1,27 @@
<?php
namespace Drupal\layout_builder_fieldblock_test\Plugin\Block;
use Drupal\layout_builder\Plugin\Block\FieldBlock as LayoutBuilderFieldBlock;
/**
* Provides test field block to test with Block UI.
*
* \Drupal\Tests\layout_builder\FunctionalJavascript\FieldBlockTest provides
* test coverage of complex AJAX interactions within certain field blocks.
* layout_builder_plugin_filter_block__block_ui_alter() removes certain blocks
* with 'layout_builder' as the provider. To make these blocks available during
* testing, this plugin uses the same deriver but each derivative will have a
* different provider.
*
* @Block(
* id = "field_block_test",
* deriver = "\Drupal\layout_builder\Plugin\Derivative\FieldBlockDeriver",
* )
*
* @see \Drupal\Tests\layout_builder\FunctionalJavascript\FieldBlockTest
* @see layout_builder_plugin_filter_block__block_ui_alter()
*/
class FieldBlock extends LayoutBuilderFieldBlock {
}

View file

@ -22,6 +22,7 @@ class LayoutBuilderTest extends BrowserTestBase {
'layout_builder_views_test',
'layout_test',
'block',
'block_test',
'node',
'layout_builder_test',
];
@ -90,7 +91,7 @@ class LayoutBuilderTest extends BrowserTestBase {
// The body field is only present once.
$assert_session->elementsCount('css', '.field--name-body', 1);
// The extra field is only present once.
$this->assertTextAppearsOnce('Placeholder for the "Extra label" field');
$assert_session->pageTextContainsOnce('Placeholder for the "Extra label" field');
// Save the defaults.
$assert_session->linkExists('Save Layout');
$this->clickLink('Save Layout');
@ -105,7 +106,7 @@ class LayoutBuilderTest extends BrowserTestBase {
// The body field is only present once.
$assert_session->elementsCount('css', '.field--name-body', 1);
// The extra field is only present once.
$this->assertTextAppearsOnce('Placeholder for the "Extra label" field');
$assert_session->pageTextContainsOnce('Placeholder for the "Extra label" field');
// Add a new block.
$assert_session->linkExists('Add Block');
@ -316,6 +317,11 @@ class LayoutBuilderTest extends BrowserTestBase {
$page->fillField('id', 'myothermenu');
$page->pressButton('Save');
$page->clickLink('Add link');
$page->fillField('title[0][value]', 'My link');
$page->fillField('link[0][uri]', '/');
$page->pressButton('Save');
$this->drupalPostForm('admin/structure/types/manage/bundle_with_section_field/display', ['layout[enabled]' => TRUE], 'Save');
$assert_session->linkExists('Manage layout');
$this->clickLink('Manage layout');
@ -514,13 +520,68 @@ class LayoutBuilderTest extends BrowserTestBase {
}
/**
* Asserts that a text string only appears once on the page.
* Tests the usage of placeholders for empty blocks.
*
* @param string $needle
* The string to look for.
* @see \Drupal\Core\Block\BlockPluginInterface::getPlaceholderString()
* @see \Drupal\layout_builder\EventSubscriber\BlockComponentRenderArray::onBuildRender()
*/
protected function assertTextAppearsOnce($needle) {
$this->assertEquals(1, substr_count($this->getSession()->getPage()->getContent(), $needle), "'$needle' only appears once on the page.");
public function testBlockPlaceholder() {
$assert_session = $this->assertSession();
$page = $this->getSession()->getPage();
$this->drupalLogin($this->drupalCreateUser([
'configure any layout',
'administer node display',
]));
$field_ui_prefix = 'admin/structure/types/manage/bundle_with_section_field';
$this->drupalPostForm("$field_ui_prefix/display/default", ['layout[enabled]' => TRUE], 'Save');
// Customize the default view mode.
$this->drupalGet("$field_ui_prefix/display-layout/default");
// Add a block whose content is controlled by state and is empty by default.
$this->clickLink('Add Block');
$this->clickLink('Test block caching');
$page->fillField('settings[label]', 'The block label');
$page->pressButton('Add Block');
$block_content = 'I am content';
$placeholder_content = 'Placeholder for the "The block label" block';
// The block placeholder is displayed and there is no content.
$assert_session->pageTextContains($placeholder_content);
$assert_session->pageTextNotContains($block_content);
// Set block content and reload the page.
\Drupal::state()->set('block_test.content', $block_content);
$this->getSession()->reload();
// The block placeholder is no longer displayed and the content is visible.
$assert_session->pageTextNotContains($placeholder_content);
$assert_session->pageTextContains($block_content);
}
/**
* Tests the Block UI when Layout Builder is installed.
*/
public function testBlockUiListing() {
$assert_session = $this->assertSession();
$page = $this->getSession()->getPage();
$this->drupalLogin($this->drupalCreateUser([
'administer blocks',
]));
$this->drupalGet('admin/structure/block');
$page->clickLink('Place block');
// Ensure that blocks expected to appear are available.
$assert_session->pageTextContains('Test HTML block');
$assert_session->pageTextContains('Block test');
// Ensure that blocks not expected to appear are not available.
$assert_session->pageTextNotContains('Body');
$assert_session->pageTextNotContains('Content fields');
}
}

View file

@ -4,6 +4,7 @@ namespace Drupal\Tests\layout_builder\Functional;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay;
use Drupal\layout_builder\Plugin\SectionStorage\OverridesSectionStorage;
use Drupal\layout_builder\Section;
use Drupal\layout_builder\SectionComponent;
use Drupal\Tests\BrowserTestBase;
@ -20,13 +21,6 @@ class LayoutSectionTest extends BrowserTestBase {
*/
public static $modules = ['field_ui', 'layout_builder', 'node', 'block_test'];
/**
* The name of the layout section field.
*
* @var string
*/
protected $fieldName = 'layout_builder__layout';
/**
* {@inheritdoc}
*/
@ -226,7 +220,7 @@ class LayoutSectionTest extends BrowserTestBase {
]);
$entity->addTranslation('es', [
'title' => 'Translated node title',
$this->fieldName => [
OverridesSectionStorage::FIELD_NAME => [
[
'section' => new Section('layout_twocol', [], [
'foo' => new SectionComponent('foo', 'first', [
@ -373,7 +367,7 @@ class LayoutSectionTest extends BrowserTestBase {
'value' => 'The node body',
],
],
$this->fieldName => $section_values,
OverridesSectionStorage::FIELD_NAME => $section_values,
]);
}

View file

@ -16,7 +16,14 @@ class FieldBlockTest extends WebDriverTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['block', 'datetime', 'layout_builder', 'user'];
protected static $modules = [
'block',
'datetime',
'layout_builder',
'user',
// See \Drupal\layout_builder_fieldblock_test\Plugin\Block\FieldBlock.
'layout_builder_fieldblock_test',
];
/**
* {@inheritdoc}
@ -67,7 +74,7 @@ class FieldBlockTest extends WebDriverTestBase {
$assert_session->pageTextNotContains('Initial email');
$assert_session->pageTextContains('Date field');
$block_url = 'admin/structure/block/add/field_block%3Auser%3Auser%3Afield_date/classy';
$block_url = 'admin/structure/block/add/field_block_test%3Auser%3Auser%3Afield_date/classy';
$assert_session->linkByHrefExists($block_url);
$this->drupalGet($block_url);

View file

@ -192,8 +192,8 @@ class InlineBlockPrivateFilesTest extends InlineBlockTestBase {
$page = $this->getSession()->getPage();
$page->clickLink('Add Block');
$assert_session->assertWaitOnAjaxRequest();
$this->assertNotEmpty($assert_session->waitForElementVisible('css', '.block-categories details:contains(Create new block)'));
$this->clickLink('Basic block');
$this->assertNotEmpty($assert_session->waitForLink('Create custom block'));
$this->clickLink('Create custom block');
$assert_session->assertWaitOnAjaxRequest();
$assert_session->fieldValueEquals('Title', '');
$page->findField('Title')->setValue($title);

View file

@ -428,4 +428,74 @@ class InlineBlockTest extends InlineBlockTestBase {
$assert_session->pageTextNotContains('You are not authorized to access this page');
}
/**
* Tests the workflow for adding an inline block depending on number of types.
*
* @throws \Behat\Mink\Exception\ElementNotFoundException
* @throws \Behat\Mink\Exception\ExpectationException
*/
public function testAddWorkFlow() {
$assert_session = $this->assertSession();
$page = $this->getSession()->getPage();
$type_storage = $this->container->get('entity_type.manager')->getStorage('block_content_type');
foreach ($type_storage->loadByProperties() as $type) {
$type->delete();
}
$this->drupalLogin($this->drupalCreateUser([
'access contextual links',
'configure any layout',
'administer node display',
'administer node fields',
]));
// Enable layout builder and overrides.
$this->drupalPostForm(
static::FIELD_UI_PREFIX . '/display/default',
['layout[enabled]' => TRUE, 'layout[allow_custom]' => TRUE],
'Save'
);
$layout_default_path = 'admin/structure/types/manage/bundle_with_section_field/display-layout/default';
$this->drupalGet($layout_default_path);
// Add a basic block with the body field set.
$page->clickLink('Add Block');
$assert_session->assertWaitOnAjaxRequest();
// Confirm that with no block content types the link does not appear.
$assert_session->linkNotExists('Create custom block');
$this->createBlockContentType('basic', 'Basic block');
$this->drupalGet($layout_default_path);
// Add a basic block with the body field set.
$page->clickLink('Add Block');
$assert_session->assertWaitOnAjaxRequest();
// Confirm with only 1 type the "Create custom block" link goes directly t
// block add form.
$assert_session->linkNotExists('Basic block');
$this->clickLink('Create custom block');
$assert_session->assertWaitOnAjaxRequest();
$assert_session->fieldExists('Title');
$this->createBlockContentType('advanced', 'Advanced block');
$this->drupalGet($layout_default_path);
// Add a basic block with the body field set.
$page->clickLink('Add Block');
// Confirm that, when more than 1 type exists, "Create custom block" shows a
// list of block types.
$assert_session->assertWaitOnAjaxRequest();
$assert_session->linkNotExists('Basic block');
$assert_session->linkNotExists('Advanced block');
$this->clickLink('Create custom block');
$assert_session->assertWaitOnAjaxRequest();
$assert_session->fieldNotExists('Title');
$assert_session->linkExists('Basic block');
$assert_session->linkExists('Advanced block');
$this->clickLink('Advanced block');
$assert_session->assertWaitOnAjaxRequest();
$assert_session->fieldExists('Title');
}
}

View file

@ -71,13 +71,7 @@ abstract class InlineBlockTestBase extends WebDriverTestBase {
],
],
]);
$bundle = BlockContentType::create([
'id' => 'basic',
'label' => 'Basic block',
'revision' => 1,
]);
$bundle->save();
block_content_add_body_field($bundle->id());
$this->createBlockContentType('basic', 'Basic block');
$this->blockStorage = $this->container->get('entity_type.manager')->getStorage('block_content');
}
@ -146,8 +140,8 @@ abstract class InlineBlockTestBase extends WebDriverTestBase {
$page = $this->getSession()->getPage();
$page->clickLink('Add Block');
$assert_session->assertWaitOnAjaxRequest();
$this->assertNotEmpty($assert_session->waitForElementVisible('css', '.block-categories details:contains(Create new block)'));
$this->clickLink('Basic block');
$this->assertNotEmpty($assert_session->waitForLink('Create custom block'));
$this->clickLink('Create custom block');
$assert_session->assertWaitOnAjaxRequest();
$textarea = $assert_session->waitForElement('css', '[name="settings[block_form][body][0][value]"]');
$this->assertNotEmpty($textarea);
@ -219,4 +213,22 @@ abstract class InlineBlockTestBase extends WebDriverTestBase {
}
}
/**
* Creates a block content type.
*
* @param string $id
* The block type id.
* @param string $label
* The block type label.
*/
protected function createBlockContentType($id, $label) {
$bundle = BlockContentType::create([
'id' => $id,
'label' => $label,
'revision' => 1,
]);
$bundle->save();
block_content_add_body_field($bundle->id());
}
}

View file

@ -0,0 +1,94 @@
<?php
namespace Drupal\Tests\layout_builder\FunctionalJavascript;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
/**
* Tests the Layout Builder UI.
*
* @group layout_builder
*/
class LayoutBuilderUiTest extends WebDriverTestBase {
/**
* Path prefix for the field UI for the test bundle.
*
* @var string
*/
const FIELD_UI_PREFIX = 'admin/structure/types/manage/bundle_with_section_field';
public static $modules = [
'layout_builder',
'block',
'node',
];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
// @todo The Layout Builder UI relies on local tasks; fix in
// https://www.drupal.org/project/drupal/issues/2917777.
$this->drupalPlaceBlock('local_tasks_block');
$this->createContentType(['type' => 'bundle_with_section_field']);
$this->drupalLogin($this->drupalCreateUser([
'configure any layout',
'administer node display',
'administer node fields',
]));
}
/**
* Tests the message indicating unsaved changes.
*/
public function testUnsavedChangesMessage() {
$assert_session = $this->assertSession();
$page = $this->getSession()->getPage();
// Enable layout builder.
$this->drupalPostForm(
static::FIELD_UI_PREFIX . '/display/default',
['layout[enabled]' => TRUE],
'Save'
);
// Make and then cancel changes.
$this->assertModifiedLayout(static::FIELD_UI_PREFIX . '/display-layout/default');
$page->clickLink('Cancel Layout');
$assert_session->pageTextNotContains('You have unsaved changes.');
// Make and then save changes.
$this->assertModifiedLayout(static::FIELD_UI_PREFIX . '/display-layout/default');
$page->clickLink('Save Layout');
$assert_session->pageTextNotContains('You have unsaved changes.');
}
/**
* Asserts that modifying a layout works as expected.
*
* @param string $path
* The path to a Layout Builder UI page.
*/
protected function assertModifiedLayout($path) {
$assert_session = $this->assertSession();
$page = $this->getSession()->getPage();
$this->drupalGet($path);
$page->clickLink('Add Section');
$assert_session->assertWaitOnAjaxRequest();
$assert_session->pageTextNotContains('You have unsaved changes.');
$page->clickLink('One column');
$assert_session->assertWaitOnAjaxRequest();
$assert_session->pageTextContainsOnce('You have unsaved changes.');
// Reload the page.
$this->drupalGet($path);
$assert_session->pageTextContainsOnce('You have unsaved changes.');
}
}

View file

@ -230,11 +230,10 @@ class FieldBlockTest extends EntityKernelTestBase {
* @covers ::build
* @dataProvider providerTestBuild
*/
public function testBuild(PromiseInterface $promise, $in_preview, $expected_markup, $log_message = '', $log_arguments = []) {
public function testBuild(PromiseInterface $promise, $expected_markup, $log_message = '', $log_arguments = []) {
$entity = $this->prophesize(FieldableEntityInterface::class);
$field = $this->prophesize(FieldItemListInterface::class);
$entity->get('the_field_name')->willReturn($field->reveal());
$entity->in_preview = $in_preview;
$field->view(Argument::type('array'))->will($promise);
$field_definition = $this->prophesize(FieldDefinitionInterface::class);
@ -269,40 +268,20 @@ class FieldBlockTest extends EntityKernelTestBase {
*/
public function providerTestBuild() {
$data = [];
$data['array, no preview'] = [
$data['array'] = [
new ReturnPromise([['content' => ['#markup' => 'The field value']]]),
FALSE,
'The field value',
];
$data['array, preview'] = [
new ReturnPromise([['content' => ['#markup' => 'The field value']]]),
TRUE,
'The field value',
];
$data['empty array, no preview'] = [
$data['empty array'] = [
new ReturnPromise([[]]),
FALSE,
'',
];
$data['empty array, preview'] = [
new ReturnPromise([[]]),
TRUE,
'Placeholder for the "The Field Label" field',
];
$data['exception, no preview'] = [
$data['exception'] = [
new ThrowPromise(new \Exception('The exception message')),
FALSE,
'',
'The field "%field" failed to render with the error of "%error".',
['%field' => 'the_field_name', '%error' => 'The exception message'],
];
$data['exception, preview'] = [
new ThrowPromise(new \Exception('The exception message')),
TRUE,
'Placeholder for the "The Field Label" field',
'The field "%field" failed to render with the error of "%error".',
['%field' => 'the_field_name', '%error' => 'The exception message'],
];
return $data;
}

View file

@ -2,6 +2,7 @@
namespace Drupal\Tests\layout_builder\Kernel;
use Drupal\layout_builder\Plugin\SectionStorage\OverridesSectionStorage;
use Drupal\layout_builder\Section;
/**
@ -56,7 +57,7 @@ class LayoutBuilderFieldLayoutCompatibilityTest extends LayoutBuilderCompatibili
// Add a layout override.
$this->enableOverrides();
/** @var \Drupal\layout_builder\SectionStorageInterface $field_list */
$field_list = $this->entity->get('layout_builder__layout');
$field_list = $this->entity->get(OverridesSectionStorage::FIELD_NAME);
$field_list->appendSection(new Section('layout_onecol'));
$this->entity->save();

View file

@ -4,6 +4,7 @@ namespace Drupal\Tests\layout_builder\Kernel;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\layout_builder\Plugin\SectionStorage\OverridesSectionStorage;
use Drupal\layout_builder\Section;
/**
@ -35,7 +36,7 @@ class LayoutBuilderInstallTest extends LayoutBuilderCompatibilityTestBase {
// Add a layout override.
$this->enableOverrides();
$this->entity = $this->reloadEntity($this->entity);
$this->entity->get('layout_builder__layout')->appendSection(new Section('layout_onecol'));
$this->entity->get(OverridesSectionStorage::FIELD_NAME)->appendSection(new Section('layout_onecol'));
$this->entity->save();
// The rendered entity has now changed. The non-configurable field is shown
@ -50,7 +51,7 @@ class LayoutBuilderInstallTest extends LayoutBuilderCompatibilityTestBase {
$this->assertNotEmpty($this->cssSelect('.layout--onecol'));
// Removing the layout restores the original rendering of the entity.
$this->entity->get('layout_builder__layout')->removeSection(0);
$this->entity->get(OverridesSectionStorage::FIELD_NAME)->removeSection(0);
$this->entity->save();
$this->assertFieldAttributes($this->entity, $expected_fields);

View file

@ -4,6 +4,7 @@ namespace Drupal\Tests\layout_builder\Kernel;
use Drupal\entity_test\Entity\EntityTestBaseFieldDisplay;
use Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay;
use Drupal\layout_builder\Plugin\SectionStorage\OverridesSectionStorage;
/**
* Tests the field type for Layout Sections.
@ -42,10 +43,10 @@ class LayoutSectionItemListTest extends SectionStorageTestBase {
}, $section_data);
$entity = EntityTestBaseFieldDisplay::create([
'name' => 'The test entity',
'layout_builder__layout' => $section_data,
OverridesSectionStorage::FIELD_NAME => $section_data,
]);
$entity->save();
return $entity->get('layout_builder__layout');
return $entity->get(OverridesSectionStorage::FIELD_NAME);
}
}

View file

@ -137,6 +137,17 @@ abstract class SectionStorageTestBase extends EntityKernelTestBase {
$this->assertSections($expected);
}
/**
* Tests __clone().
*/
public function testClone() {
$this->assertSame([], $this->sectionStorage->getSection(0)->getLayoutSettings());
$new_section_storage = clone $this->sectionStorage;
$new_section_storage->getSection(0)->setLayoutSettings(['asdf' => 'qwer']);
$this->assertSame([], $this->sectionStorage->getSection(0)->getLayoutSettings());
}
/**
* Asserts that the field list has the expected sections.
*

View file

@ -11,6 +11,7 @@ use Drupal\Core\Cache\Cache;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Plugin\Context\ContextHandlerInterface;
use Drupal\Core\Render\PreviewFallbackInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\layout_builder\Access\LayoutPreviewAccessAllowed;
use Drupal\layout_builder\Event\SectionComponentBuildRenderArrayEvent;
@ -252,6 +253,98 @@ class BlockComponentRenderArrayTest extends UnitTestCase {
$this->assertEquals($expected_cache, $result);
}
/**
* @covers ::onBuildRender
*/
public function testOnBuildRenderInPreviewEmptyBuild() {
$block = $this->prophesize(BlockPluginInterface::class)->willImplement(PreviewFallbackInterface::class);
$block->access($this->account->reveal(), TRUE)->shouldNotBeCalled();
$block->getCacheContexts()->willReturn([]);
$block->getCacheTags()->willReturn(['test']);
$block->getCacheMaxAge()->willReturn(Cache::PERMANENT);
$block->getConfiguration()->willReturn([]);
$block->getPluginId()->willReturn('block_plugin_id');
$block->getBaseId()->willReturn('block_plugin_id');
$block->getDerivativeId()->willReturn(NULL);
$placeholder_string = 'The placeholder string';
$block->getPreviewFallbackString()->willReturn($placeholder_string);
$block_content = [];
$block->build()->willReturn($block_content);
$this->blockManager->createInstance('some_block_id', ['id' => 'some_block_id'])->willReturn($block->reveal());
$component = new SectionComponent('some-uuid', 'some-region', ['id' => 'some_block_id']);
$event = new SectionComponentBuildRenderArrayEvent($component, [], TRUE);
$subscriber = new BlockComponentRenderArray($this->account->reveal());
$expected_build = [
'#theme' => 'block',
'#weight' => 0,
'#configuration' => [],
'#plugin_id' => 'block_plugin_id',
'#base_plugin_id' => 'block_plugin_id',
'#derivative_plugin_id' => NULL,
'content' => $block_content,
];
$expected_build['content']['#markup'] = $placeholder_string;
$expected_cache = $expected_build + [
'#cache' => [
'contexts' => [],
'tags' => ['test'],
'max-age' => 0,
],
];
$subscriber->onBuildRender($event);
$result = $event->getBuild();
$this->assertEquals($expected_build, $result);
$event->getCacheableMetadata()->applyTo($result);
$this->assertEquals($expected_cache, $result);
}
/**
* @covers ::onBuildRender
*/
public function testOnBuildRenderEmptyBuild() {
$block = $this->prophesize(BlockPluginInterface::class);
$access_result = AccessResult::allowed();
$block->access($this->account->reveal(), TRUE)->willReturn($access_result)->shouldBeCalled();
$block->getCacheContexts()->willReturn([]);
$block->getCacheTags()->willReturn(['test']);
$block->getCacheMaxAge()->willReturn(Cache::PERMANENT);
$block->getConfiguration()->willReturn([]);
$block->getPluginId()->willReturn('block_plugin_id');
$block->getBaseId()->willReturn('block_plugin_id');
$block->getDerivativeId()->willReturn(NULL);
$block->build()->willReturn([]);
$this->blockManager->createInstance('some_block_id', ['id' => 'some_block_id'])->willReturn($block->reveal());
$component = new SectionComponent('some-uuid', 'some-region', ['id' => 'some_block_id']);
$event = new SectionComponentBuildRenderArrayEvent($component, [], FALSE);
$subscriber = new BlockComponentRenderArray($this->account->reveal());
$expected_build = [];
$expected_cache = $expected_build + [
'#cache' => [
'contexts' => [],
'tags' => ['test'],
'max-age' => -1,
],
];
$subscriber->onBuildRender($event);
$result = $event->getBuild();
$this->assertEquals($expected_build, $result);
$event->getCacheableMetadata()->applyTo($result);
$this->assertEquals($expected_cache, $result);
}
/**
* @covers ::onBuildRender
*/

View file

@ -16,6 +16,7 @@ class LayoutTempstoreRepositoryTest extends UnitTestCase {
/**
* @covers ::get
* @covers ::has
*/
public function testGetEmptyTempstore() {
$section_storage = $this->prophesize(SectionStorageInterface::class);
@ -30,12 +31,15 @@ class LayoutTempstoreRepositoryTest extends UnitTestCase {
$repository = new LayoutTempstoreRepository($tempstore_factory->reveal());
$this->assertFalse($repository->has($section_storage->reveal()));
$result = $repository->get($section_storage->reveal());
$this->assertSame($section_storage->reveal(), $result);
}
/**
* @covers ::get
* @covers ::has
*/
public function testGetLoadedTempstore() {
$section_storage = $this->prophesize(SectionStorageInterface::class);
@ -50,6 +54,8 @@ class LayoutTempstoreRepositoryTest extends UnitTestCase {
$repository = new LayoutTempstoreRepository($tempstore_factory->reveal());
$this->assertTrue($repository->has($section_storage->reveal()));
$result = $repository->get($section_storage->reveal());
$this->assertSame($tempstore_section_storage->reveal(), $result);
$this->assertNotSame($section_storage->reveal(), $result);

View file

@ -112,13 +112,13 @@ class OverridesSectionStorageTest extends UnitTestCase {
$entity_storage = $this->prophesize(EntityStorageInterface::class);
$entity_without_layout = $this->prophesize(FieldableEntityInterface::class);
$entity_without_layout->hasField('layout_builder__layout')->willReturn(FALSE);
$entity_without_layout->get('layout_builder__layout')->shouldNotBeCalled();
$entity_without_layout->hasField(OverridesSectionStorage::FIELD_NAME)->willReturn(FALSE);
$entity_without_layout->get(OverridesSectionStorage::FIELD_NAME)->shouldNotBeCalled();
$entity_storage->load('entity_without_layout')->willReturn($entity_without_layout->reveal());
$entity_with_layout = $this->prophesize(FieldableEntityInterface::class);
$entity_with_layout->hasField('layout_builder__layout')->willReturn(TRUE);
$entity_with_layout->get('layout_builder__layout')->willReturn('the_return_value');
$entity_with_layout->hasField(OverridesSectionStorage::FIELD_NAME)->willReturn(TRUE);
$entity_with_layout->get(OverridesSectionStorage::FIELD_NAME)->willReturn('the_return_value');
$entity_storage->load('entity_with_layout')->willReturn($entity_with_layout->reveal());
$this->entityTypeManager->getStorage($expected_entity_type_id)->willReturn($entity_storage->reveal());

View file

@ -231,6 +231,7 @@ class SectionRenderTest extends UnitTestCase {
* @covers ::toRenderArray
*/
public function testContextAwareBlock() {
$block_content = ['#markup' => 'The block content.'];
$render_array = [
'#theme' => 'block',
'#weight' => 0,
@ -238,7 +239,7 @@ class SectionRenderTest extends UnitTestCase {
'#plugin_id' => 'block_plugin_id',
'#base_plugin_id' => 'block_plugin_id',
'#derivative_plugin_id' => NULL,
'content' => [],
'content' => $block_content,
'#cache' => [
'contexts' => [],
'tags' => [],
@ -251,7 +252,7 @@ class SectionRenderTest extends UnitTestCase {
$access_result = AccessResult::allowed();
$block->access($this->account->reveal(), TRUE)->willReturn($access_result);
$block->build()->willReturn([]);
$block->build()->willReturn($block_content);
$block->getCacheContexts()->willReturn([]);
$block->getCacheTags()->willReturn([]);
$block->getCacheMaxAge()->willReturn(Cache::PERMANENT);