public function EntityUsageLayoutBuilderTest::testLayoutBuilderInlineBlockUsage in Entity Usage 8.4
Same name in this branch
- 8.4 tests/src/Functional/EntityUsageLayoutBuilderTest.php \Drupal\Tests\entity_usage\Functional\EntityUsageLayoutBuilderTest::testLayoutBuilderInlineBlockUsage()
- 8.4 tests/src/Kernel/EntityUsageLayoutBuilderTest.php \Drupal\Tests\entity_usage\Kernel\EntityUsageLayoutBuilderTest::testLayoutBuilderInlineBlockUsage()
Same name and namespace in other branches
- 8.2 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();
$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',
]),
]),
];
$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);
}