You are here

public function DeleteTruncateTest::testTruncate in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Database/DeleteTruncateTest.php \Drupal\KernelTests\Core\Database\DeleteTruncateTest::testTruncate()

Confirms that we can truncate a whole table successfully.

File

core/tests/Drupal/KernelTests/Core/Database/DeleteTruncateTest.php, line 59

Class

DeleteTruncateTest
Tests delete and truncate queries.

Namespace

Drupal\KernelTests\Core\Database

Code

public function testTruncate() {
  $num_records_before = $this->connection
    ->query("SELECT COUNT(*) FROM {test}")
    ->fetchField();
  $this
    ->assertTrue($num_records_before > 0, 'The table is not empty.');
  $this->connection
    ->truncate('test')
    ->execute();
  $num_records_after = $this->connection
    ->query("SELECT COUNT(*) FROM {test}")
    ->fetchField();
  $this
    ->assertEqual(0, $num_records_after, 'Truncate really deletes everything.');
}