Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
JanJakes committed Dec 19, 2024
1 parent 0025f57 commit 04d7c17
Show file tree
Hide file tree
Showing 3 changed files with 1,277 additions and 277 deletions.
143 changes: 75 additions & 68 deletions tests/WP_SQLite_Driver_Tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require_once __DIR__ . '/WP_SQLite_Translator_Tests.php';
require_once __DIR__ . '/../wp-includes/sqlite-ast/class-wp-sqlite-driver.php';
require_once __DIR__ . '/../wp-includes/sqlite-ast/class-wp-sqlite-information-schema-builder.php';
require_once __DIR__ . '/../wp-includes/sqlite-ast/class-wp-sqlite-expression.php';
require_once __DIR__ . '/../wp-includes/sqlite-ast/class-wp-sqlite-token-factory.php';
require_once __DIR__ . '/../wp-includes/sqlite-ast/class-wp-sqlite-token.php';
Expand Down Expand Up @@ -39,7 +40,7 @@ public static function setUpBeforeClass(): void {
public function setUp(): void {
$this->sqlite = new PDO( 'sqlite::memory:' );

$this->engine = new WP_SQLite_Driver( $this->sqlite );
$this->engine = new WP_SQLite_Driver( 'wp', $this->sqlite );
$this->engine->query(
"CREATE TABLE _options (
ID INTEGER PRIMARY KEY AUTO_INCREMENT NOT NULL,
Expand Down Expand Up @@ -287,13 +288,13 @@ public function testShowCreateTable1() {
# TODO: Should we fix mismatch with original `option_value` text NOT NULL,` without default?
$this->assertEquals(
"CREATE TABLE `_tmp_table` (
`ID` bigint NOT NULL AUTO_INCREMENT,
`option_name` varchar(255) DEFAULT '',
`option_value` text NOT NULL DEFAULT '',
PRIMARY KEY (`ID`),
KEY `composite` (`option_name`, `option_value`),
UNIQUE KEY `option_name` (`option_name`)
);",
`ID` bigint NOT NULL AUTO_INCREMENT,
`option_name` varchar(255) DEFAULT '',
`option_value` text NOT NULL,
PRIMARY KEY (`ID`),
UNIQUE KEY `option_name` (`option_name`),
KEY `composite` (`option_name`, `option_value`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci",
$results[0]->{'Create Table'}
);
}
Expand All @@ -316,13 +317,13 @@ public function testShowCreateTableQuoted() {
# TODO: Should we fix mismatch with original `option_value` text NOT NULL,` without default?
$this->assertEquals(
"CREATE TABLE `_tmp_table` (
`ID` bigint NOT NULL AUTO_INCREMENT,
`option_name` varchar(255) DEFAULT '',
`option_value` text NOT NULL DEFAULT '',
PRIMARY KEY (`ID`),
KEY `composite` (`option_name`, `option_value`),
UNIQUE KEY `option_name` (`option_name`)
);",
`ID` bigint NOT NULL AUTO_INCREMENT,
`option_name` varchar(255) DEFAULT '',
`option_value` text NOT NULL,
PRIMARY KEY (`ID`),
UNIQUE KEY `option_name` (`option_name`),
KEY `composite` (`option_name`, `option_value`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci",
$results[0]->{'Create Table'}
);
}
Expand All @@ -340,8 +341,8 @@ public function testShowCreateTableSimpleTable() {
$results = $this->engine->get_query_results();
$this->assertEquals(
'CREATE TABLE `_tmp_table` (
`ID` bigint NOT NULL DEFAULT 0
);',
`ID` bigint NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci',
$results[0]->{'Create Table'}
);
}
Expand Down Expand Up @@ -369,12 +370,12 @@ public function testShowCreateTableWithAlterAndCreateIndex() {
$results = $this->engine->get_query_results();
$this->assertEquals(
'CREATE TABLE `_tmp_table` (
`ID` bigint NOT NULL AUTO_INCREMENT,
`option_name` smallint NOT NULL DEFAULT 14,
`option_value` text NOT NULL DEFAULT \'\',
PRIMARY KEY (`ID`),
KEY `option_name` (`option_name`)
);',
`ID` bigint NOT NULL AUTO_INCREMENT,
`option_name` smallint NOT NULL DEFAULT \'14\',
`option_value` text NOT NULL,
PRIMARY KEY (`ID`),
KEY `option_name` (`option_name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci',
$results[0]->{'Create Table'}
);
}
Expand Down Expand Up @@ -418,13 +419,13 @@ public function testShowCreateTablePreservesDoubleUnderscoreKeyNames() {
$results = $this->engine->get_query_results();
$this->assertEquals(
'CREATE TABLE `_tmp__table` (
`ID` bigint NOT NULL AUTO_INCREMENT,
`option_name` varchar(255) DEFAULT \'\',
`option_value` text NOT NULL DEFAULT \'\',
PRIMARY KEY (`ID`),
KEY `double__underscores` (`option_name`, `ID`),
KEY `option_name` (`option_name`)
);',
`ID` bigint NOT NULL AUTO_INCREMENT,
`option_name` varchar(255) DEFAULT \'\',
`option_value` text NOT NULL,
PRIMARY KEY (`ID`),
KEY `option_name` (`option_name`),
KEY `double__underscores` (`option_name`, `ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci',
$results[0]->{'Create Table'}
);
}
Expand All @@ -445,11 +446,11 @@ public function testShowCreateTableWithPrimaryKeyColumnsReverseOrdered() {
$results = $this->engine->get_query_results();
$this->assertEquals(
'CREATE TABLE `_tmp_table` (
`ID_A` bigint NOT NULL DEFAULT 0,
`ID_B` bigint NOT NULL DEFAULT 0,
`ID_C` bigint NOT NULL DEFAULT 0,
PRIMARY KEY (`ID_B`, `ID_A`, `ID_C`)
);',
`ID_A` bigint NOT NULL,
`ID_B` bigint NOT NULL,
`ID_C` bigint NOT NULL,
PRIMARY KEY (`ID_B`, `ID_A`, `ID_C`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci',
$results[0]->{'Create Table'}
);
}
Expand Down Expand Up @@ -480,11 +481,11 @@ public function testShowCreateTableWithCorrectDefaultValues() {
$results = $this->engine->get_query_results();
$this->assertEquals(
'CREATE TABLE `_tmp__table` (
`ID` bigint NOT NULL AUTO_INCREMENT,
`default_empty_string` varchar(255) DEFAULT \'\',
`null_no_default` varchar(255),
PRIMARY KEY (`ID`)
);',
`ID` bigint NOT NULL AUTO_INCREMENT,
`default_empty_string` varchar(255) DEFAULT \'\',
`null_no_default` varchar(255),
PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci',
$results[0]->{'Create Table'}
);
}
Expand Down Expand Up @@ -847,8 +848,8 @@ enum_column ENUM('a', 'b', 'c') NOT NULL DEFAULT 'a',
'Type' => 'bigint(20) unsigned',
'Null' => 'NO',
'Key' => 'PRI',
'Default' => '0',
'Extra' => '',
'Default' => null,
'Extra' => 'auto_increment',
),
(object) array(
'Field' => 'decimal_column',
Expand Down Expand Up @@ -1051,7 +1052,7 @@ public function testColumnWithOnUpdate() {
'Type' => 'int(11)',
'Null' => 'NO',
'Key' => '',
'Default' => '0',
'Default' => null,
'Extra' => '',
),
(object) array(
Expand All @@ -1060,7 +1061,7 @@ public function testColumnWithOnUpdate() {
'Null' => 'YES',
'Key' => '',
'Default' => null,
'Extra' => '',
'Extra' => 'on update CURRENT_TIMESTAMP',
),
),
$results
Expand All @@ -1078,7 +1079,7 @@ public function testColumnWithOnUpdate() {
'Type' => 'int(11)',
'Null' => 'NO',
'Key' => '',
'Default' => '0',
'Default' => null,
'Extra' => '',
),
(object) array(
Expand All @@ -1087,15 +1088,15 @@ public function testColumnWithOnUpdate() {
'Null' => 'YES',
'Key' => '',
'Default' => null,
'Extra' => '',
'Extra' => 'on update CURRENT_TIMESTAMP',
),
(object) array(
'Field' => 'updated_at',
'Type' => 'timestamp',
'Null' => 'YES',
'Key' => '',
'Default' => null,
'Extra' => '',
'Extra' => 'on update CURRENT_TIMESTAMP',
),
),
$results
Expand Down Expand Up @@ -1220,7 +1221,7 @@ public function testChangeColumnWithOnUpdate() {
'Type' => 'int(11)',
'Null' => 'NO',
'Key' => '',
'Default' => '0',
'Default' => null,
'Extra' => '',
),
(object) array(
Expand Down Expand Up @@ -1253,7 +1254,7 @@ public function testChangeColumnWithOnUpdate() {
'Type' => 'int(11)',
'Null' => 'NO',
'Key' => '',
'Default' => '0',
'Default' => null,
'Extra' => '',
),
(object) array(
Expand All @@ -1262,7 +1263,7 @@ public function testChangeColumnWithOnUpdate() {
'Null' => 'YES',
'Key' => '',
'Default' => null,
'Extra' => '',
'Extra' => 'on update CURRENT_TIMESTAMP',
),
),
$results
Expand All @@ -1285,7 +1286,7 @@ public function testChangeColumnWithOnUpdate() {
'Type' => 'int(11)',
'Null' => 'NO',
'Key' => '',
'Default' => '0',
'Default' => null,
'Extra' => '',
),
(object) array(
Expand Down Expand Up @@ -1327,15 +1328,15 @@ public function testAlterTableWithColumnFirstAndAfter() {
'Type' => 'int(11)',
'Null' => 'NO',
'Key' => '',
'Default' => '0',
'Default' => null,
'Extra' => '',
),
(object) array(
'Field' => 'name',
'Type' => 'varchar(20)',
'Null' => 'NO',
'Key' => '',
'Default' => null,
'Default' => '',
'Extra' => '',
),
(object) array(
Expand All @@ -1362,7 +1363,7 @@ public function testAlterTableWithColumnFirstAndAfter() {
'Type' => 'int(11)',
'Null' => 'NO',
'Key' => '',
'Default' => '0',
'Default' => null,
'Extra' => '',
),
(object) array(
Expand Down Expand Up @@ -1456,7 +1457,7 @@ public function testAlterTableWithColumnFirstAndAfter() {
'Type' => 'varchar(20)',
'Null' => 'NO',
'Key' => '',
'Default' => null,
'Default' => '',
'Extra' => '',
),
(object) array(
Expand Down Expand Up @@ -1502,7 +1503,7 @@ public function testAlterTableWithMultiColumnFirstAndAfter() {
'Type' => 'int(11)',
'Null' => 'NO',
'Key' => '',
'Default' => '0',
'Default' => null,
'Extra' => '',
),
(object) array(
Expand Down Expand Up @@ -1548,7 +1549,7 @@ public function testAlterTableWithMultiColumnFirstAndAfter() {
'Type' => 'int(11)',
'Null' => 'NO',
'Key' => '',
'Default' => '0',
'Default' => null,
'Extra' => '',
),
(object) array(
Expand Down Expand Up @@ -1599,7 +1600,7 @@ public function testAlterTableAddIndex() {
'Table' => '_tmp_table',
'Non_unique' => '1',
'Key_name' => 'name',
'Seq_in_index' => '0',
'Seq_in_index' => '1',
'Column_name' => 'name',
'Collation' => 'A',
'Cardinality' => '0',
Expand All @@ -1609,6 +1610,8 @@ public function testAlterTableAddIndex() {
'Index_type' => 'BTREE',
'Comment' => '',
'Index_comment' => '',
'Visible' => 'YES',
'Expression' => null,
),
),
$results
Expand All @@ -1634,16 +1637,18 @@ public function testAlterTableAddUniqueIndex() {
'Table' => '_tmp_table',
'Non_unique' => '0',
'Key_name' => 'name',
'Seq_in_index' => '0',
'Seq_in_index' => '1',
'Column_name' => 'name',
'Collation' => 'A',
'Cardinality' => '0',
'Sub_part' => null,
'Sub_part' => '20',
'Packed' => null,
'Null' => '',
'Index_type' => 'BTREE',
'Comment' => '',
'Index_comment' => '',
'Visible' => 'YES',
'Expression' => null,
),
),
$results
Expand All @@ -1669,16 +1674,18 @@ public function testAlterTableAddFulltextIndex() {
'Table' => '_tmp_table',
'Non_unique' => '1',
'Key_name' => 'name',
'Seq_in_index' => '0',
'Seq_in_index' => '1',
'Column_name' => 'name',
'Collation' => 'A',
'Collation' => null,
'Cardinality' => '0',
'Sub_part' => null,
'Packed' => null,
'Null' => '',
'Index_type' => 'FULLTEXT',
'Comment' => '',
'Index_comment' => '',
'Visible' => 'YES',
'Expression' => null,
),
),
$results
Expand Down Expand Up @@ -2166,15 +2173,14 @@ public function testNestedTransactionWorkComplexModify() {
$fields = $this->engine->get_query_results();

$this->assertEquals(
$fields,
array(
(object) array(
'Field' => 'ID',
'Type' => 'integer',
'Type' => 'int',
'Null' => 'NO',
'Key' => 'PRI',
'Default' => '0',
'Extra' => '',
'Default' => null,
'Extra' => 'auto_increment',
),
(object) array(
'Field' => 'option_name',
Expand All @@ -2192,7 +2198,8 @@ public function testNestedTransactionWorkComplexModify() {
'Default' => '',
'Extra' => '',
),
)
),
$fields
);
}

Expand Down Expand Up @@ -2425,7 +2432,7 @@ public function testDescribeAccurate() {
'Field' => 'term_name',
'Type' => 'varchar(11)',
'Null' => 'NO',
'Key' => '',
'Key' => 'MUL',
'Default' => '0',
'Extra' => '',
),
Expand Down
Loading

0 comments on commit 04d7c17

Please sign in to comment.