You are here

public function WorkspaceTest::testBlockPlugins in Multiversion 8

Tests block plugins between workspaces.

File

tests/src/Kernel/WorkspaceTest.php, line 115

Class

WorkspaceTest
Tests workspace interactions.

Namespace

Drupal\Tests\multiversion\Kernel

Code

public function testBlockPlugins() {

  // Make sure live is the active workspace.
  \Drupal::service('workspace.manager')
    ->setActiveWorkspace($this->live);

  // Create a test block content type and block content, then place it.
  BlockContentType::create([
    'id' => 'test',
    'label' => 'Test',
  ])
    ->save();
  $block_content_1 = BlockContent::create([
    'type' => 'test',
  ]);
  $block_content_1
    ->save();
  $this
    ->placeBlock('block_content:' . $block_content_1
    ->uuid());

  // Test block 1 appears in the block definitions on live.

  /** @var \Drupal\Core\Block\BlockManagerInterface $block_manager */
  $block_manager = \Drupal::service('plugin.manager.block');
  $live_definitions = $block_manager
    ->getDefinitions();
  $this
    ->assertTrue(isset($live_definitions['block_content:' . $block_content_1
    ->uuid()]));

  // Test block 2 appears in the block definitions on stage.
  \Drupal::service('workspace.manager')
    ->setActiveWorkspace($this->stage);
  $block_content_2 = BlockContent::create([
    'type' => 'test',
  ]);
  $block_content_2
    ->save();
  $this
    ->placeBlock('block_content:' . $block_content_2
    ->uuid());
  $stage_definitions = $block_manager
    ->getDefinitions();
  $this
    ->assertTrue(isset($stage_definitions['block_content:' . $block_content_2
    ->uuid()]));

  // Test block 1 still appears in the block definitions on live.
  \Drupal::service('workspace.manager')
    ->setActiveWorkspace($this->live);
  $live_definitions = $block_manager
    ->getDefinitions();
  $this
    ->assertTrue(isset($live_definitions['block_content:' . $block_content_1
    ->uuid()]));
}