public function EntityUsageLayoutBuilderTest::testLayoutBuilderInlineBlockUsage in Entity Usage 8.2
Same name in this branch
- 8.2 tests/src/Functional/EntityUsageLayoutBuilderTest.php \Drupal\Tests\entity_usage\Functional\EntityUsageLayoutBuilderTest::testLayoutBuilderInlineBlockUsage()
- 8.2 tests/src/Kernel/EntityUsageLayoutBuilderTest.php \Drupal\Tests\entity_usage\Kernel\EntityUsageLayoutBuilderTest::testLayoutBuilderInlineBlockUsage()
Same name and namespace in other branches
- 8.4 tests/src/Kernel/EntityUsageLayoutBuilderTest.php \Drupal\Tests\entity_usage\Kernel\EntityUsageLayoutBuilderTest::testLayoutBuilderInlineBlockUsage()
Tests blocks referenced by inline blocks in layouts are recorded.
File
- tests/
src/ Kernel/ EntityUsageLayoutBuilderTest.php, line 65
Class
- EntityUsageLayoutBuilderTest
- Tests layout builder usage plugin records usage.
Namespace
Drupal\Tests\entity_usage\KernelCode
public function testLayoutBuilderInlineBlockUsage() {
$type = BlockContentType::create([
'id' => 'foo',
'label' => 'Foo',
]);
$type
->save();
$block = BlockContent::create([
'type' => $type
->id(),
]);
$block
->save();
$test_entity = EntityTest::create();
$test_entity
->save();
$sectionData = [
new Section('layout_onecol', [], [
'first-uuid' => new SectionComponent('first-uuid', 'content', [
'id' => 'inline_block:' . $type
->id(),
'block_revision_id' => $block
->getRevisionId(),
]),
// Ensure plugins that don't exist don't throw errors.
'second-uuid' => new SectionComponent('second-uuid', 'content', [
'id' => 'foo_block:plugin_not_found',
]),
// Add a block that has a content dependency on the block.
'third-uuid' => new SectionComponent('third-uuid', 'content', [
'id' => 'entity_usage_test_dependencies',
'dependencies' => [
'content' => [
$test_entity
->getConfigDependencyName(),
],
],
]),
]),
];
$entity = EntityTest::create([
OverridesSectionStorage::FIELD_NAME => $sectionData,
]);
$entity
->save();
/** @var \Drupal\entity_usage\EntityUsageInterface $entityUsage */
$entityUsage = \Drupal::service('entity_usage.usage');
$usage = $entityUsage
->listSources($block);
$expected = [
$entity
->getEntityTypeId() => [
$entity
->id() => [
[
'source_langcode' => 'en',
'source_vid' => '0',
'method' => 'layout_builder',
'field_name' => 'layout_builder__layout',
'count' => '1',
],
],
],
];
$this
->assertEquals($expected, $usage);
$usage = $entityUsage
->listSources($test_entity);
$expected = [
$entity
->getEntityTypeId() => [
$entity
->id() => [
[
'source_langcode' => 'en',
'source_vid' => '0',
'method' => 'layout_builder',
'field_name' => 'layout_builder__layout',
'count' => '1',
],
],
],
];
$this
->assertEquals($expected, $usage);
}