You are here

protected function LayoutBuilderDependencyCalculatorTest::setUp in Dependency Calculation 8

Throws

\Drupal\Core\Entity\EntityStorageException

Overrides KernelTestBase::setUp

File

tests/src/Kernel/EventSubscriber/LayoutBuilderDependencyCalculatorTest.php, line 51

Class

LayoutBuilderDependencyCalculatorTest
Class LayoutBuilderDependencyCalculatorTest.

Namespace

Drupal\Tests\depcalc\Kernel

Code

protected function setUp() : void {
  parent::setUp();
  $this
    ->installSchema('system', [
    'sequences',
    'key_value_expire',
  ]);
  $this
    ->installSchema('file', [
    'file_usage',
  ]);
  $this
    ->installSchema('comment', [
    'comment_entity_statistics',
  ]);
  $this
    ->installSchema('layout_builder', [
    'inline_block_usage',
  ]);
  $this
    ->installEntitySchema('view');
  $this
    ->installEntitySchema('user');
  $this
    ->installEntitySchema('node');
  $this
    ->installEntitySchema('taxonomy_vocabulary');
  $this
    ->installEntitySchema('taxonomy_term');
  $this
    ->installEntitySchema('comment');
  $this
    ->installEntitySchema('block_content');
  $this
    ->installConfig('depcalc_test');
  $this
    ->installConfig('image');
  $this
    ->installConfig('user');
  $this->calculator = Drupal::service('entity.dependency.calculator');

  // Create test user.

  /** @var \Drupal\Core\Entity\EntityRepository $entity_repository */
  $entity_repository = Drupal::service('entity.repository');
  $admin_role = $entity_repository
    ->loadEntityByUuid('user_role', '27202596-169e-4835-b9d4-c51ded9a03b8');
  $test_user = User::create([
    'name' => 'Admin',
    'roles' => [
      $admin_role
        ->id(),
    ],
    'uuid' => '2d666602-74c0-4d83-a6ef-d181fd562291',
  ]);
  $test_user
    ->save();
  $block = BlockContent::create([
    'type' => 'basic',
    'info' => 'Test Block',
    'uuid' => 'f523731a-cb0a-44be-8f9d-a4fae4dd7015',
  ]);
  $block
    ->save();
  $block = BlockContent::create([
    'type' => 'basic',
    'info' => 'Non-Inline Block',
    'uuid' => '865b56c1-134c-401e-88bc-f37d36dbc885',
  ]);
  $block
    ->save();
  $node_type = NodeType::create([
    'name' => 'Landing Page',
    'type' => 'landing_page',
    'new_revision' => TRUE,
  ]);
  $node_type
    ->save();

  /** @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display */
  $display = \Drupal::entityTypeManager()
    ->getStorage('entity_view_display')
    ->create([
    'targetEntityType' => 'node',
    'bundle' => 'landing_page',
    'mode' => 'default',
    'status' => TRUE,
  ]);
  $display
    ->setThirdPartySetting('layout_builder', 'enabled', TRUE);
  $display
    ->setThirdPartySetting('layout_builder', 'allow_custom', TRUE);
  $section = new Section('layout_onecol', [
    'label' => '',
  ]);
  foreach ($this
    ->getSectionComponents() as $component) {
    $section
      ->appendComponent($component);
  }
  $display
    ->setThirdPartySetting('layout_builder', 'sections', [
    $section,
  ]);
  $display
    ->save();
  $node = Node::create([
    'title' => 'Landing Page 1',
    'type' => 'landing_page',
  ]);
  $node
    ->set(OverridesSectionStorage::FIELD_NAME, [
    $section,
  ]);
  $node
    ->save();
}