You are here

public function MigrateBlockTest::assertEntity in Drupal 8

Same name in this branch
  1. 8 core/modules/block/tests/src/Kernel/Migrate/d6/MigrateBlockTest.php \Drupal\Tests\block\Kernel\Migrate\d6\MigrateBlockTest::assertEntity()
  2. 8 core/modules/block/tests/src/Kernel/Migrate/d7/MigrateBlockTest.php \Drupal\Tests\block\Kernel\Migrate\d7\MigrateBlockTest::assertEntity()
Same name and namespace in other branches
  1. 9 core/modules/block/tests/src/Kernel/Migrate/d7/MigrateBlockTest.php \Drupal\Tests\block\Kernel\Migrate\d7\MigrateBlockTest::assertEntity()
  2. 10 core/modules/block/tests/src/Kernel/Migrate/d7/MigrateBlockTest.php \Drupal\Tests\block\Kernel\Migrate\d7\MigrateBlockTest::assertEntity()

Asserts various aspects of a block.

Parameters

string $id: The block ID.

string $plugin_id: The block's plugin ID.

array $roles: Role IDs the block is expected to have.

string $pages: The list of pages on which the block should appear.

string $region: The display region.

string $theme: The theme.

string $weight: The block weight.

string $label: The block label.

string $label_display: The block label display setting.

bool $status: Whether the block is expected to be enabled or disabled.

1 call to MigrateBlockTest::assertEntity()
MigrateBlockTest::testBlockMigration in core/modules/block/tests/src/Kernel/Migrate/d7/MigrateBlockTest.php
Tests the block migration.

File

core/modules/block/tests/src/Kernel/Migrate/d7/MigrateBlockTest.php, line 85

Class

MigrateBlockTest
Tests migration of blocks to configuration entities.

Namespace

Drupal\Tests\block\Kernel\Migrate\d7

Code

public function assertEntity($id, $plugin_id, array $roles, $pages, $region, $theme, $weight, $label, $label_display, $status = TRUE) {
  $block = Block::load($id);
  $this
    ->assertInstanceOf(Block::class, $block);

  /** @var \Drupal\block\BlockInterface $block */
  $this
    ->assertSame($plugin_id, $block
    ->getPluginId());
  $visibility = $block
    ->getVisibility();
  if ($roles) {
    $this
      ->assertSame($roles, array_values($visibility['user_role']['roles']));
    $this
      ->assertSame('@user.current_user_context:current_user', $visibility['user_role']['context_mapping']['user']);
  }
  if ($pages) {
    $this
      ->assertSame($pages, $visibility['request_path']['pages']);
  }
  $this
    ->assertSame($region, $block
    ->getRegion());
  $this
    ->assertSame($theme, $block
    ->getTheme());
  $this
    ->assertSame($weight, $block
    ->getWeight());
  $this
    ->assertSame($status, $block
    ->status());
  $config = $this
    ->config('block.block.' . $id);
  $this
    ->assertSame($label, $config
    ->get('settings.label'));
  $this
    ->assertSame($label_display, $config
    ->get('settings.label_display'));
}