public function DeleteTruncateTest::testSimpleDelete in Drupal 8
Same name and namespace in other branches
- 9 core/tests/Drupal/KernelTests/Core/Database/DeleteTruncateTest.php \Drupal\KernelTests\Core\Database\DeleteTruncateTest::testSimpleDelete()
 
Confirms that we can delete a single record successfully.
File
- core/
tests/ Drupal/ KernelTests/ Core/ Database/ DeleteTruncateTest.php, line 44  
Class
- DeleteTruncateTest
 - Tests delete and truncate queries.
 
Namespace
Drupal\KernelTests\Core\DatabaseCode
public function testSimpleDelete() {
  $num_records_before = $this->connection
    ->query('SELECT COUNT(*) FROM {test}')
    ->fetchField();
  $num_deleted = $this->connection
    ->delete('test')
    ->condition('id', 1)
    ->execute();
  $this
    ->assertIdentical($num_deleted, 1, 'Deleted 1 record.');
  $num_records_after = $this->connection
    ->query('SELECT COUNT(*) FROM {test}')
    ->fetchField();
  $this
    ->assertEqual($num_records_before, $num_records_after + $num_deleted, 'Deletion adds up.');
}