connection ->insert('test') ->fields([ 'name' => $this->randomMachineName(), 'age' => 20, 'job' => $job, ])->execute(); $from_database = $this->connection->query('SELECT [job] FROM {test} WHERE [job] = :job', [':job' => $job])->fetchField(); $this->assertSame($job, $from_database, 'The database handles UTF-8 characters cleanly.'); } /** * Tests the Schema::tableExists() method. */ public function testDBTableExists() { $this->assertTrue($this->connection->schema()->tableExists('test'), 'Returns true for existent table.'); $this->assertFalse($this->connection->schema()->tableExists('nosuchtable'), 'Returns false for nonexistent table.'); } /** * Tests the \Drupal\Core\Database\Schema::fieldExists() method. */ public function testDBFieldExists() { $schema = $this->connection->schema(); $this->assertTrue($schema->fieldExists('test', 'name'), 'Returns true for existent column.'); $this->assertFalse($schema->fieldExists('test', 'nosuchcolumn'), 'Returns false for nonexistent column.'); } /** * Tests the Schema::indexExists() method. */ public function testDBIndexExists() { $this->assertTrue($this->connection->schema()->indexExists('test', 'ages'), 'Returns true for existent index.'); $this->assertFalse($this->connection->schema()->indexExists('test', 'nosuchindex'), 'Returns false for nonexistent index.'); } }