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

Create an block and test a clone.

@group entity_clone

Hierarchy

  • class \Drupal\Tests\entity_clone\Functional\EntityCloneBlockTest extends \Drupal\Tests\BrowserTestBase uses \Drupal\Core\StringTranslation\StringTranslationTrait

Expanded class hierarchy of EntityCloneBlockTest

File

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

Namespace

Drupal\Tests\entity_clone\Functional
View source
class EntityCloneBlockTest extends BrowserTestBase {
    use StringTranslationTrait;
    
    /**
     * Modules to enable.
     *
     * @var array
     */
    protected static $modules = [
        'entity_clone',
        'block',
    ];
    
    /**
     * Theme to enable by default.
     *
     * @var string
     */
    protected $defaultTheme = 'claro';
    
    /**
     * Permissions to grant admin user.
     *
     * @var array
     */
    protected $permissions = [
        'administer blocks',
        'clone block entity',
    ];
    
    /**
     * An administrative user with permission to configure blocks settings.
     *
     * @var \Drupal\user\UserInterface
     */
    protected $adminUser;
    
    /**
     * Sets the test up.
     */
    protected function setUp() : void {
        parent::setUp();
        $this->adminUser = $this->drupalCreateUser($this->permissions);
        $this->drupalLogin($this->adminUser);
    }
    
    /**
     * Test block entity clone.
     */
    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.');
    }

}

Members

Title Sort descending Modifiers Object type Summary
EntityCloneBlockTest::$adminUser protected property An administrative user with permission to configure blocks settings.
EntityCloneBlockTest::$defaultTheme protected property Theme to enable by default.
EntityCloneBlockTest::$modules protected static property Modules to enable.
EntityCloneBlockTest::$permissions protected property Permissions to grant admin user.
EntityCloneBlockTest::setUp protected function Sets the test up.
EntityCloneBlockTest::testBlockEntityClone public function Test block entity clone.