function BlockContentCreationTest::testFailedBlockCreation

Same name in other branches
  1. 8.9.x core/modules/block_content/tests/src/Functional/BlockContentCreationTest.php \Drupal\Tests\block_content\Functional\BlockContentCreationTest::testFailedBlockCreation()
  2. 10 core/modules/block_content/tests/src/Functional/BlockContentCreationTest.php \Drupal\Tests\block_content\Functional\BlockContentCreationTest::testFailedBlockCreation()
  3. 11.x 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 193

Class

BlockContentCreationTest
Create a block and test saving it.

Namespace

Drupal\Tests\block_content\Functional

Code

public function testFailedBlockCreation() {
    // 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.