function BlockContentCreationTest::testFailedBlockCreation

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

Verifies that a transaction rolls back the failed creation.

File

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

Class

BlockContentCreationTest
Create a block and test saving it.

Namespace

Drupal\Tests\block_content\Functional

Code

public function testFailedBlockCreation() : void {
    // Create a block.
    try {
        $this->createBlockContent('fail_creation');
        $this->fail('Expected exception has not been thrown.');
    } catch (\Exception $e) {
        // Expected exception; just continue testing.
    }
    $connection = Database::getConnection();
    // Check that the block does not exist in the database.
    $id = $connection->select('block_content_field_data', 'b')
        ->fields('b', [
        'id',
    ])
        ->condition('info', 'fail_creation')
        ->execute()
        ->fetchField();
    $this->assertFalse($id);
}

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