class RegressionTest
Same name and namespace in other branches
- 11.x core/tests/Drupal/KernelTests/Core/Database/RegressionTest.php \Drupal\KernelTests\Core\Database\RegressionTest
Regression tests cases for the database layer.
@group Database
Hierarchy
- class \Drupal\KernelTests\KernelTestBase extends \Drupal\Core\DependencyInjection\ServiceProviderInterface uses \Drupal\KernelTests\AssertLegacyTrait, \Drupal\KernelTests\AssertContentTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\ExtensionListTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait implements \PHPUnit\Framework\TestCase
- class \Drupal\KernelTests\Core\Database\DatabaseTestBase uses \Drupal\KernelTests\Core\Database\DatabaseTestSchemaDataTrait, \Drupal\KernelTests\Core\Database\DatabaseTestSchemaInstallTrait implements \Drupal\KernelTests\KernelTestBase
- class \Drupal\KernelTests\Core\Database\RegressionTest implements \Drupal\KernelTests\Core\Database\DatabaseTestBase
- class \Drupal\KernelTests\Core\Database\DatabaseTestBase uses \Drupal\KernelTests\Core\Database\DatabaseTestSchemaDataTrait, \Drupal\KernelTests\Core\Database\DatabaseTestSchemaInstallTrait implements \Drupal\KernelTests\KernelTestBase
Expanded class hierarchy of RegressionTest
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Database/ RegressionTest.php, line 10
Namespace
Drupal\KernelTests\Core\DatabaseView source
class RegressionTest extends DatabaseTestBase {
/**
* Modules to enable.
*
* @var array
*/
protected static $modules = [
'node',
'user',
];
/**
* Ensures that non-ASCII UTF-8 data is stored in the database properly.
*/
public function testRegression_310447() {
// That's a 255 character UTF-8 string.
$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.');
}
/**
* 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('no_such_table'), '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', 'no_such_column'), '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', 'no_such_index'), 'Returns false for nonexistent index.');
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.