You are here

protected static function NodeCreationTest::getWatchdogIdsForTestExceptionRollback in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/node/tests/src/Functional/NodeCreationTest.php \Drupal\Tests\node\Functional\NodeCreationTest::getWatchdogIdsForTestExceptionRollback()

Gets the watchdog IDs of the records with the rollback exception message.

Return value

int[] Array containing the IDs of the log records with the rollback exception message.

1 call to NodeCreationTest::getWatchdogIdsForTestExceptionRollback()
NodeCreationTest::testFailedPageCreation in core/modules/node/tests/src/Functional/NodeCreationTest.php
Verifies that a transaction rolls back the failed creation.

File

core/modules/node/tests/src/Functional/NodeCreationTest.php, line 307

Class

NodeCreationTest
Create a node and test saving it.

Namespace

Drupal\Tests\node\Functional

Code

protected static function getWatchdogIdsForTestExceptionRollback() {

  // PostgreSQL doesn't support bytea LIKE queries, so we need to unserialize
  // first to check for the rollback exception message.
  $matches = [];
  $query = Database::getConnection()
    ->select('watchdog', 'w')
    ->fields('w', [
    'wid',
    'variables',
  ])
    ->execute();
  foreach ($query as $row) {
    $variables = (array) unserialize($row->variables);
    if (isset($variables['@message']) && $variables['@message'] === 'Test exception for rollback.') {
      $matches[] = $row->wid;
    }
  }
  return $matches;
}