first commit

This commit is contained in:
2024-07-15 12:33:27 +02:00
commit ce50ae282b
22084 changed files with 2623791 additions and 0 deletions

View File

@@ -0,0 +1,14 @@
<?php
declare(strict_types=1);
namespace Drupal\Tests\sqlite\Functional;
use Drupal\Tests\system\Functional\Module\GenericModuleTestBase;
/**
* Generic module test for sqlite.
*
* @group sqlite
*/
class GenericTest extends GenericModuleTestBase {}

View File

@@ -0,0 +1,26 @@
<?php
declare(strict_types=1);
namespace Drupal\Tests\sqlite\Kernel\sqlite;
use Drupal\KernelTests\Core\Database\DriverSpecificDatabaseTestBase;
/**
* SQLite-specific connection tests.
*
* @group Database
*/
class ConnectionTest extends DriverSpecificDatabaseTestBase {
/**
* Tests deprecation of ::makeSequenceName().
*
* @group legacy
*/
public function testMakeSequenceNameDeprecation(): void {
$this->expectDeprecation("Drupal\\Core\\Database\\Connection::makeSequenceName() is deprecated in drupal:10.2.0 and is removed from drupal:11.0.0. There is no replacement. See https://www.drupal.org/node/3377046");
$this->assertIsString($this->connection->makeSequenceName('foo', 'bar'));
}
}

View File

@@ -0,0 +1,25 @@
<?php
declare(strict_types=1);
namespace Drupal\Tests\sqlite\Kernel\sqlite;
use Drupal\KernelTests\Core\Database\DriverSpecificKernelTestBase;
/**
* Tests exceptions thrown by queries.
*
* @group Database
*/
class DatabaseExceptionWrapperTest extends DriverSpecificKernelTestBase {
/**
* Tests Connection::prepareStatement exception on execution.
*/
public function testPrepareStatementFailOnExecution(): void {
$this->expectException(\PDOException::class);
$stmt = $this->connection->prepareStatement('bananas', []);
$stmt->execute();
}
}

View File

@@ -0,0 +1,21 @@
<?php
declare(strict_types=1);
namespace Drupal\Tests\sqlite\Kernel\sqlite\Plugin\views;
use Drupal\Tests\views\Kernel\Plugin\CastedIntFieldJoinTestBase;
/**
* Tests SQLite specific cast handling.
*
* @group Database
*/
class SqliteCastedIntFieldJoinTest extends CastedIntFieldJoinTestBase {
/**
* The db type that should be used for casting fields as integers.
*/
protected string $castingType = 'INTEGER';
}

View File

@@ -0,0 +1,104 @@
<?php
declare(strict_types=1);
namespace Drupal\Tests\sqlite\Kernel\sqlite;
use Drupal\KernelTests\Core\Database\DriverSpecificSchemaTestBase;
/**
* Tests schema API for the SQLite driver.
*
* @group Database
*/
class SchemaTest extends DriverSpecificSchemaTestBase {
/**
* {@inheritdoc}
*/
public function checkSchemaComment(string $description, string $table, ?string $column = NULL): void {
// The sqlite driver schema does not support fetching table/column
// comments.
}
/**
* {@inheritdoc}
*/
protected function tryInsertExpectsIntegrityConstraintViolationException(string $tableName): void {
// Sqlite does not throw an IntegrityConstraintViolationException here.
}
/**
* {@inheritdoc}
*/
public function testTableWithSpecificDataType(): void {
$table_specification = [
'description' => 'Schema table description.',
'fields' => [
'timestamp' => [
'sqlite_type' => 'datetime',
'not null' => FALSE,
'default' => NULL,
],
],
];
$this->schema->createTable('test_timestamp', $table_specification);
$this->assertTrue($this->schema->tableExists('test_timestamp'));
}
/**
* @covers \Drupal\sqlite\Driver\Database\sqlite\Schema::introspectIndexSchema
*/
public function testIntrospectIndexSchema(): void {
$table_specification = [
'fields' => [
'id' => [
'type' => 'int',
'not null' => TRUE,
'default' => 0,
],
'test_field_1' => [
'type' => 'int',
'not null' => TRUE,
'default' => 0,
],
'test_field_2' => [
'type' => 'int',
'default' => 0,
],
'test_field_3' => [
'type' => 'int',
'default' => 0,
],
'test_field_4' => [
'type' => 'int',
'default' => 0,
],
'test_field_5' => [
'type' => 'int',
'default' => 0,
],
],
'primary key' => ['id', 'test_field_1'],
'unique keys' => [
'test_field_2' => ['test_field_2'],
'test_field_3_test_field_4' => ['test_field_3', 'test_field_4'],
],
'indexes' => [
'test_field_4' => ['test_field_4'],
'test_field_4_test_field_5' => ['test_field_4', 'test_field_5'],
],
];
$table_name = strtolower($this->getRandomGenerator()->name());
$this->schema->createTable($table_name, $table_specification);
unset($table_specification['fields']);
$introspect_index_schema = new \ReflectionMethod(get_class($this->schema), 'introspectIndexSchema');
$index_schema = $introspect_index_schema->invoke($this->schema, $table_name);
$this->assertEquals($table_specification, $index_schema);
}
}

View File

@@ -0,0 +1,21 @@
<?php
declare(strict_types=1);
namespace Drupal\Tests\sqlite\Kernel\sqlite;
use Drupal\KernelTests\Core\Database\SchemaUniquePrefixedKeysIndexTestBase;
/**
* Tests adding UNIQUE keys to tables.
*
* @group Database
*/
class SchemaUniquePrefixedKeysIndexTest extends SchemaUniquePrefixedKeysIndexTestBase {
/**
* {@inheritdoc}
*/
protected string $columnValue = '1234567890 foo';
}

View File

@@ -0,0 +1,98 @@
<?php
declare(strict_types=1);
namespace Drupal\Tests\sqlite\Kernel\sqlite;
use Drupal\Core\Database\Driver\sqlite\Connection;
use Drupal\Core\Database\Driver\sqlite\Install\Tasks;
use Drupal\Core\Database\Driver\sqlite\Insert;
use Drupal\Core\Database\Driver\sqlite\Schema;
use Drupal\Core\Database\Driver\sqlite\Select;
use Drupal\Core\Database\Driver\sqlite\Statement;
use Drupal\Core\Database\Driver\sqlite\Truncate;
use Drupal\Core\Database\Driver\sqlite\Upsert;
use Drupal\KernelTests\Core\Database\DriverSpecificDatabaseTestBase;
use Drupal\Tests\Core\Database\Stub\StubPDO;
/**
* Tests the deprecations of the SQLite database driver classes in Core.
*
* @group legacy
* @group Database
*/
class SqliteDriverLegacyTest extends DriverSpecificDatabaseTestBase {
/**
* @covers Drupal\Core\Database\Driver\sqlite\Install\Tasks
*/
public function testDeprecationInstallTasks(): void {
$this->expectDeprecation('\Drupal\Core\Database\Driver\sqlite\Install\Tasks is deprecated in drupal:9.4.0 and is removed from drupal:11.0.0. The SQLite database driver has been moved to the sqlite module. See https://www.drupal.org/node/3129492');
$tasks = new Tasks();
$this->assertInstanceOf(Tasks::class, $tasks);
}
/**
* @covers Drupal\Core\Database\Driver\sqlite\Connection
*/
public function testDeprecationConnection(): void {
$this->expectDeprecation('\Drupal\Core\Database\Driver\sqlite\Connection is deprecated in drupal:9.4.0 and is removed from drupal:11.0.0. The SQLite database driver has been moved to the sqlite module. See https://www.drupal.org/node/3129492');
$connection = new Connection($this->createMock(StubPDO::class), []);
$this->assertInstanceOf(Connection::class, $connection);
}
/**
* @covers Drupal\Core\Database\Driver\sqlite\Insert
*/
public function testDeprecationInsert(): void {
$this->expectDeprecation('\Drupal\Core\Database\Driver\sqlite\Insert is deprecated in drupal:9.4.0 and is removed from drupal:11.0.0. The SQLite database driver has been moved to the sqlite module. See https://www.drupal.org/node/3129492');
$insert = new Insert($this->connection, 'test');
$this->assertInstanceOf(Insert::class, $insert);
}
/**
* @covers Drupal\Core\Database\Driver\sqlite\Schema
*/
public function testDeprecationSchema(): void {
$this->expectDeprecation('\Drupal\Core\Database\Driver\sqlite\Schema is deprecated in drupal:9.4.0 and is removed from drupal:11.0.0. The SQLite database driver has been moved to the sqlite module. See https://www.drupal.org/node/3129492');
$schema = new Schema($this->connection);
$this->assertInstanceOf(Schema::class, $schema);
}
/**
* @covers Drupal\Core\Database\Driver\sqlite\Select
*/
public function testDeprecationSelect(): void {
$this->expectDeprecation('\Drupal\Core\Database\Driver\sqlite\Select is deprecated in drupal:9.4.0 and is removed from drupal:11.0.0. The SQLite database driver has been moved to the sqlite module. See https://www.drupal.org/node/3129492');
$select = new Select($this->connection, 'test');
$this->assertInstanceOf(Select::class, $select);
}
/**
* @covers Drupal\Core\Database\Driver\sqlite\Statement
*/
public function testDeprecationStatement(): void {
$this->expectDeprecation('\Drupal\Core\Database\Driver\sqlite\Statement is deprecated in drupal:9.4.0 and is removed from drupal:11.0.0. The SQLite database driver has been moved to the sqlite module. See https://www.drupal.org/node/3129492');
$statement = new Statement($this->createMock(StubPDO::class), $this->connection, '', []);
$this->assertInstanceOf(Statement::class, $statement);
}
/**
* @covers Drupal\Core\Database\Driver\sqlite\Truncate
*/
public function testDeprecationTruncate(): void {
$this->expectDeprecation('\Drupal\Core\Database\Driver\sqlite\Truncate is deprecated in drupal:9.4.0 and is removed from drupal:11.0.0. The SQLite database driver has been moved to the sqlite module. See https://www.drupal.org/node/3129492');
$truncate = new Truncate($this->connection, 'test');
$this->assertInstanceOf(Truncate::class, $truncate);
}
/**
* @covers Drupal\Core\Database\Driver\sqlite\Upsert
*/
public function testDeprecationUpsert(): void {
$this->expectDeprecation('\Drupal\Core\Database\Driver\sqlite\Upsert is deprecated in drupal:9.4.0 and is removed from drupal:11.0.0. The SQLite database driver has been moved to the sqlite module. See https://www.drupal.org/node/3129492');
$upsert = new Upsert($this->connection, 'test');
$this->assertInstanceOf(Upsert::class, $upsert);
}
}

View File

@@ -0,0 +1,15 @@
<?php
declare(strict_types=1);
namespace Drupal\Tests\sqlite\Kernel\sqlite;
use Drupal\KernelTests\Core\Database\DriverSpecificSyntaxTestBase;
/**
* Tests SQLite syntax interpretation.
*
* @group Database
*/
class SyntaxTest extends DriverSpecificSyntaxTestBase {
}

View File

@@ -0,0 +1,40 @@
<?php
declare(strict_types=1);
namespace Drupal\Tests\sqlite\Kernel\sqlite;
use Drupal\KernelTests\Core\Database\TemporaryQueryTestBase;
/**
* Tests the temporary query functionality.
*
* @group Database
*/
class TemporaryQueryTest extends TemporaryQueryTestBase {
/**
* Confirms that temporary tables work.
*/
public function testTemporaryQuery(): void {
parent::testTemporaryQuery();
$connection = $this->getConnection();
$table_name_test = $connection->queryTemporary('SELECT [name] FROM {test}', []);
// Assert that the table is indeed a temporary one.
$this->assertStringContainsString("temp.", $table_name_test);
// Assert that both have the same field names.
$normal_table_fields = $connection->query("SELECT * FROM {test}")->fetch();
$temp_table_name = $connection->queryTemporary('SELECT * FROM {test}');
$temp_table_fields = $connection->query("SELECT * FROM $temp_table_name")->fetch();
$normal_table_fields = array_keys(get_object_vars($normal_table_fields));
$temp_table_fields = array_keys(get_object_vars($temp_table_fields));
$this->assertEmpty(array_diff($normal_table_fields, $temp_table_fields));
}
}

View File

@@ -0,0 +1,15 @@
<?php
declare(strict_types=1);
namespace Drupal\Tests\sqlite\Kernel\sqlite;
use Drupal\KernelTests\Core\Database\DriverSpecificTransactionTestBase;
/**
* Tests transaction for the SQLite driver.
*
* @group Database
*/
class TransactionTest extends DriverSpecificTransactionTestBase {
}

View File

@@ -0,0 +1,51 @@
<?php
declare(strict_types=1);
namespace Drupal\Tests\sqlite\Unit;
use Drupal\sqlite\Driver\Database\sqlite\Connection;
use Drupal\Tests\Core\Database\Stub\StubPDO;
use Drupal\Tests\UnitTestCase;
/**
* @coversDefaultClass \Drupal\sqlite\Driver\Database\sqlite\Connection
* @group Database
*/
class ConnectionTest extends UnitTestCase {
/**
* @covers ::createConnectionOptionsFromUrl
* @dataProvider providerCreateConnectionOptionsFromUrl
*
* @param string $url
* SQLite URL.
* @param string $expected
* Expected connection option.
*/
public function testCreateConnectionOptionsFromUrl(string $url, string $expected): void {
$root = dirname(__DIR__, 8);
$sqlite_connection = new Connection($this->createMock(StubPDO::class), []);
$database = $sqlite_connection->createConnectionOptionsFromUrl($url, $root);
$this->assertEquals('sqlite', $database['driver']);
$this->assertEquals($expected, $database['database']);
}
/**
* Data provider for testCreateConnectionOptionsFromUrl.
*
* @return string[][]
* Associative array of arrays with the following elements:
* - SQLite database URL
* - Expected database connection option
*/
public static function providerCreateConnectionOptionsFromUrl(): array {
$root = dirname(__DIR__, 8);
return [
'sqlite relative path' => ['sqlite://localhost/tmp/test', $root . '/tmp/test'],
'sqlite absolute path' => ['sqlite://localhost//tmp/test', '/tmp/test'],
'in memory sqlite path' => ['sqlite://localhost/:memory:', ':memory:'],
];
}
}