You are here

public function BlockContentEntityReferenceSelectionTest::setUp in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/block_content/tests/src/Kernel/BlockContentEntityReferenceSelectionTest.php \Drupal\Tests\block_content\Kernel\BlockContentEntityReferenceSelectionTest::setUp()

Overrides KernelTestBase::setUp

File

core/modules/block_content/tests/src/Kernel/BlockContentEntityReferenceSelectionTest.php, line 68

Class

BlockContentEntityReferenceSelectionTest
Tests EntityReference selection handlers don't return non-reusable blocks.

Namespace

Drupal\Tests\block_content\Kernel

Code

public function setUp() {
  parent::setUp();
  $this
    ->installSchema('system', [
    'sequences',
  ]);
  $this
    ->installEntitySchema('user');
  $this
    ->installEntitySchema('block_content');

  // Create a block content type.
  $block_content_type = BlockContentType::create([
    'id' => 'spiffy',
    'label' => 'Mucho spiffy',
    'description' => "Provides a block type that increases your site's spiffiness by up to 11%",
  ]);
  $block_content_type
    ->save();
  $this->entityTypeManager = $this->container
    ->get('entity_type.manager');

  // And reusable block content entities.
  $this->blockReusable = BlockContent::create([
    'info' => 'Reusable Block',
    'type' => 'spiffy',
  ]);
  $this->blockReusable
    ->save();
  $this->blockNonReusable = BlockContent::create([
    'info' => 'Non-reusable Block',
    'type' => 'spiffy',
    'reusable' => FALSE,
  ]);
  $this->blockNonReusable
    ->save();
  $configuration = [
    'target_type' => 'block_content',
    'target_bundles' => [
      'spiffy' => 'spiffy',
    ],
    'sort' => [
      'field' => '_none',
    ],
  ];
  $this->selectionHandler = new TestSelection($configuration, '', '', $this->container
    ->get('entity_type.manager'), $this->container
    ->get('module_handler'), \Drupal::currentUser(), \Drupal::service('entity_field.manager'), \Drupal::service('entity_type.bundle.info'), \Drupal::service('entity.repository'));

  // Setup the 3 expectation cases.
  $this->expectations = [
    'both_blocks' => [
      'spiffy' => [
        $this->blockReusable
          ->id() => $this->blockReusable
          ->label(),
        $this->blockNonReusable
          ->id() => $this->blockNonReusable
          ->label(),
      ],
    ],
    'block_reusable' => [
      'spiffy' => [
        $this->blockReusable
          ->id() => $this->blockReusable
          ->label(),
      ],
    ],
    'block_non_reusable' => [
      'spiffy' => [
        $this->blockNonReusable
          ->id() => $this->blockNonReusable
          ->label(),
      ],
    ],
  ];
}