You are here

public function SchemaTestExtended::testInsertBadCharsIntoNonExistingTable in Drupal driver for SQL Server and SQL Azure 8.2

Tests that inserting non UTF8 strings on a table that does not exists triggers the proper error and not a string conversion error.

File

tests/src/Kernel/SchemaTestExtended.php, line 454

Class

SchemaTestExtended
Tests table creation and modification via the schema API.

Namespace

Drupal\Tests\sqlsrv\Kernel

Code

public function testInsertBadCharsIntoNonExistingTable() {
  $schema = $this->connection
    ->schema();
  try {
    $query = $this->connection
      ->insert('GHOST_TABLE');
    $query
      ->fields(array(
      'FIELD' => gzcompress('compresing this string into zip!'),
    ));
    $query
      ->execute();
  } catch (\Exception $e) {
    if (!$e instanceof \Drupal\Core\Database\SchemaObjectDoesNotExistException) {
      $this
        ->fail('Inserting into a non existent table does not trigger the right type of Exception.');
    }
    else {
      $this
        ->pass('Proper exception type thrown.');
    }
  }
  try {
    $query = $this->connection
      ->update('GHOST_TABLE');
    $query
      ->fields(array(
      'FIELD' => gzcompress('compresing this string into zip!'),
    ));
    $query
      ->execute();
  } catch (\Exception $e) {
    if (!$e instanceof \Drupal\Core\Database\SchemaObjectDoesNotExistException) {
      $this
        ->fail('Updating into a non existent table does not trigger the right type of Exception.');
    }
    else {
      $this
        ->pass('Proper exception type thrown.');
    }
  }
}