You are here

function DeleteTruncateTest::testTruncate in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/Database/DeleteTruncateTest.php \Drupal\system\Tests\Database\DeleteTruncateTest::testTruncate()

Confirms that we can truncate a whole table successfully.

File

core/modules/system/src/Tests/Database/DeleteTruncateTest.php, line 64
Contains \Drupal\system\Tests\Database\DeleteTruncateTest.

Class

DeleteTruncateTest
Tests delete and truncate queries.

Namespace

Drupal\system\Tests\Database

Code

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