function BlockContentCreationTest::testBlockContentCreation

Same name in other branches
  1. 9 core/modules/block_content/tests/src/Functional/BlockContentCreationTest.php \Drupal\Tests\block_content\Functional\BlockContentCreationTest::testBlockContentCreation()
  2. 8.9.x core/modules/block_content/tests/src/Functional/BlockContentCreationTest.php \Drupal\Tests\block_content\Functional\BlockContentCreationTest::testBlockContentCreation()
  3. 10 core/modules/block_content/tests/src/Functional/BlockContentCreationTest.php \Drupal\Tests\block_content\Functional\BlockContentCreationTest::testBlockContentCreation()

Creates a "Basic block" block and verifies its consistency in the database.

File

core/modules/block_content/tests/src/Functional/BlockContentCreationTest.php, line 58

Class

BlockContentCreationTest
Create a block and test saving it.

Namespace

Drupal\Tests\block_content\Functional

Code

public function testBlockContentCreation() : void {
    $this->drupalLogin($this->adminUser);
    // Create a block.
    $edit = [];
    $edit['info[0][value]'] = 'Test Block';
    $edit['body[0][value]'] = $this->randomMachineName(16);
    $this->drupalGet('block/add/basic');
    $this->submitForm($edit, 'Save');
    // Check that the Basic block has been created.
    $this->assertSession()
        ->pageTextContains('basic ' . $edit['info[0][value]'] . ' has been created.');
    // Check that the view mode setting is hidden because only one exists.
    $this->assertSession()
        ->fieldNotExists('settings[view_mode]');
    // Check that the block exists in the database.
    $block = $this->getBlockByLabel($edit['info[0][value]']);
    $this->assertNotEmpty($block, 'Content Block found in database.');
    // Ensure a user with just the create permission can access the page.
    $this->drupalLogin($this->drupalCreateUser([
        'create basic block content',
    ]));
    $this->drupalGet('block/add/basic');
    $this->assertSession()
        ->statusCodeEquals(200);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.