You are here

public function BlockContentCreationTest::testFailedBlockCreation in Drupal 9

Same name and namespace in other branches
  1. 8 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);
}