RegressionTest.php in Drupal 10
File
core/tests/Drupal/KernelTests/Core/Database/RegressionTest.php
View source
<?php
namespace Drupal\KernelTests\Core\Database;
class RegressionTest extends DatabaseTestBase {
protected static $modules = [
'node',
'user',
];
public function testRegression_310447() {
$job = str_repeat("é", 255);
$this->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.');
}
public function testDBTableExists() {
$this
->assertTrue($this->connection
->schema()
->tableExists('test'), 'Returns true for existent table.');
$this
->assertFalse($this->connection
->schema()
->tableExists('no_such_table'), 'Returns false for nonexistent table.');
}
public function testDBFieldExists() {
$schema = $this->connection
->schema();
$this
->assertTrue($schema
->fieldExists('test', 'name'), 'Returns true for existent column.');
$this
->assertFalse($schema
->fieldExists('test', 'no_such_column'), 'Returns false for nonexistent column.');
}
public function testDBIndexExists() {
$this
->assertTrue($this->connection
->schema()
->indexExists('test', 'ages'), 'Returns true for existent index.');
$this
->assertFalse($this->connection
->schema()
->indexExists('test', 'no_such_index'), 'Returns false for nonexistent index.');
}
}