Same name in other branches
  1. 8.x-1.x tests/src/Functional/EntityCloneBlockTest.php \Drupal\Tests\entity_clone\Functional\EntityCloneBlockTest::testBlockEntityClone()

Test block entity clone.

File

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

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->drupalGet('entity_clone/block/' . $block->id());
    $this->submitForm($edit, $this->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.');
}