You are here

protected function BlockPlacementCategoryRestrictionTest::blockTestSetup in Layout Builder Restrictions 8.2

Helper function to set up block restriction-related tests.

1 call to BlockPlacementCategoryRestrictionTest::blockTestSetup()
BlockPlacementCategoryRestrictionTest::testBlockRestriction in modules/layout_builder_restrictions_by_region/tests/src/FunctionalJavascript/BlockPlacementCategoryRestrictionTest.php
Verify that the UI can restrict blocks in Layout Builder settings tray.

File

modules/layout_builder_restrictions_by_region/tests/src/FunctionalJavascript/BlockPlacementCategoryRestrictionTest.php, line 190

Class

BlockPlacementCategoryRestrictionTest
Demonstrate that blocks can be restricted by category.

Namespace

Drupal\Tests\layout_builder_restrictions_by_region\FunctionalJavascript

Code

protected function blockTestSetup() {

  // Create 2 custom block types, with 3 block instances.
  $bundle = BlockContentType::create([
    'id' => 'basic',
    'label' => 'Basic',
  ]);
  $bundle
    ->save();
  $bundle = BlockContentType::create([
    'id' => 'alternate',
    'label' => 'Alternate',
  ]);
  $bundle
    ->save();
  block_content_add_body_field($bundle
    ->id());
  $blocks = [
    'Basic Block 1' => 'basic',
    'Basic Block 2' => 'basic',
    'Alternate Block 1' => 'alternate',
  ];
  foreach ($blocks as $info => $type) {
    $block = BlockContent::create([
      'info' => $info,
      'type' => $type,
      'body' => [
        [
          'value' => 'This is the block content',
          'format' => filter_default_format(),
        ],
      ],
    ]);
    $block
      ->save();
    $blocks[$info] = $block
      ->uuid();
  }
  $this->blocks = $blocks;
}