You are here

public function EntityCloneBlockTest::testBlockEntityClone in Entity Clone 8

Test block entity clone.

File

tests/src/Functional/EntityCloneBlockTest.php, line 58

Class

EntityCloneBlockTest
Create an block and test a clone.

Namespace

Drupal\Tests\entity_clone\Functional

Code

public function testBlockEntityClone() {
  $config = \Drupal::configFactory();
  $block = Block::create([
    'plugin' => 'test_block',
    'region' => 'sidebar_first',
    'id' => 'test_block',
    'theme' => $config
      ->get('system.theme')
      ->get('default'),
    'label' => $this
      ->randomMachineName(8),
    'visibility' => [],
    'weight' => 0,
  ]);
  $block
    ->save();
  $edit = [
    'id' => 'test_block_cloned',
  ];
  $this
    ->drupalPostForm('entity_clone/block/' . $block
    ->id(), $edit, t('Clone'));
  $blocks = \Drupal::entityTypeManager()
    ->getStorage('block')
    ->loadByProperties([
    'id' => $edit['id'],
  ]);
  $block = reset($blocks);
  $this
    ->assertInstanceOf(Block::class, $block, 'Test block cloned found in database.');
}