Skip to content
This repository was archived by the owner on Jun 2, 2025. It is now read-only.

New driver fixes from manual testing #51

Merged
merged 9 commits into from
May 30, 2025
1 change: 1 addition & 0 deletions .github/workflows/wp-tests-phpunit-run.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const expectedFailures = [
'Tests_Menu_Walker_Nav_Menu::test_start_el_with_empty_attributes with data set #6',
'Tests_Menu_Walker_Nav_Menu::test_start_el_with_empty_attributes with data set #7',
'Tests_Menu_wpNavMenu::test_wp_nav_menu_should_not_have_has_children_class_with_custom_depth',
'WP_Test_REST_Posts_Controller::test_get_items_orderby_modified_query',
];

console.log( 'Running WordPress PHPUnit tests with expected failures tracking...' );
Expand Down
188 changes: 188 additions & 0 deletions tests/WP_SQLite_Driver_Tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -3787,6 +3787,53 @@ public function testColumnDefaults(): void {
"
);

$result = $this->assertQuery( 'DESCRIBE t' );
$this->assertEquals(
array(
(object) array(
'Field' => 'name',
'Type' => 'varchar(255)',
'Null' => 'YES',
'Key' => '',
'Default' => 'CURRENT_TIMESTAMP',
'Extra' => '',
),
(object) array(
'Field' => 'type',
'Type' => 'varchar(255)',
'Null' => 'NO',
'Key' => '',
'Default' => 'DEFAULT',
'Extra' => '',
),
(object) array(
'Field' => 'description',
'Type' => 'varchar(250)',
'Null' => 'NO',
'Key' => '',
'Default' => '',
'Extra' => '',
),
(object) array(
'Field' => 'created_at',
'Type' => 'timestamp',
'Null' => 'YES',
'Key' => '',
'Default' => 'CURRENT_TIMESTAMP',
'Extra' => 'DEFAULT_GENERATED',
),
(object) array(
'Field' => 'updated_at',
'Type' => 'timestamp',
'Null' => 'NO',
'Key' => '',
'Default' => 'CURRENT_TIMESTAMP',
'Extra' => 'DEFAULT_GENERATED on update CURRENT_TIMESTAMP',
),
),
$result
);

$result = $this->assertQuery( 'SHOW CREATE TABLE t' );
$this->assertEquals(
"CREATE TABLE `t` (\n"
Expand Down Expand Up @@ -4379,6 +4426,40 @@ public function testNonStrictSqlModeNotNullWithDefault(): void {
$this->assertSame( '', $result[0]->value );
}

public function testNonStrictModeWithDefaultCurrentTimestamp(): void {
$this->assertQuery( "SET SESSION sql_mode = ''" );
$this->assertQuery( 'CREATE TABLE t (id INT, value TIMESTAMP DEFAULT CURRENT_TIMESTAMP)' );

// INSERT without a value saves CURRENT_TIMESTAMP:
$this->assertQuery( 'INSERT INTO t (id) VALUES (1)' );
$result = $this->assertQuery( 'SELECT * FROM t' );
$this->assertCount( 1, $result );
$this->assertRegExp( '/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/', $result[0]->value );

// UPDATE with NULL saves NULL:
$this->assertQuery( 'UPDATE t SET value = NULL' );
$result = $this->assertQuery( 'SELECT * FROM t' );
$this->assertCount( 1, $result );
$this->assertNull( $result[0]->value );
}

public function testNonStrictModeWithDefaultCurrentTimestampNotNull(): void {
$this->assertQuery( "SET SESSION sql_mode = ''" );
$this->assertQuery( 'CREATE TABLE t (id INT, value TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP)' );

// INSERT without a value saves CURRENT_TIMESTAMP:
$this->assertQuery( 'INSERT INTO t (id) VALUES (1)' );
$result = $this->assertQuery( 'SELECT * FROM t' );
$this->assertCount( 1, $result );
$this->assertRegExp( '/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/', $result[0]->value );

// UPDATE with NULL saves IMPLICIT DEFAULT:
$this->assertQuery( 'UPDATE t SET value = NULL' );
$result = $this->assertQuery( 'SELECT * FROM t' );
$this->assertCount( 1, $result );
$this->assertSame( '0000-00-00 00:00:00', $result[0]->value );
}

public function testNonStrictSqlModeWithNoListedColumns(): void {
$this->assertQuery( "SET SESSION sql_mode = ''" );

Expand Down Expand Up @@ -4543,6 +4624,113 @@ public function testNonStrictModeWithReplaceStatement(): void {
$this->assertSame( 'blue', $result[0]->color );
}

public function testNonStrictModeTypeCasting(): void {
$this->assertQuery(
"CREATE TABLE t (
col_int INT,
col_float FLOAT,
col_double DOUBLE,
col_decimal DECIMAL,
col_char CHAR(255),
col_varchar VARCHAR(255),
col_text TEXT,
col_bool BOOL,
col_bit BIT,
col_binary BINARY(255),
col_varbinary VARBINARY(255),
col_blob BLOB,
col_date DATE,
col_time TIME,
col_datetime DATETIME,
col_timestamp TIMESTAMP,
col_year YEAR,
col_enum ENUM('a', 'b', 'c'),
col_set SET('a', 'b', 'c'),
col_json JSON
)"
);

// Set non-strict mode.
$this->assertQuery( "SET SESSION sql_mode = ''" );

// INSERT.
$this->assertQuery(
"INSERT INTO t VALUES ('', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '')"
);

$result = $this->assertQuery( 'SELECT * FROM t' );
$this->assertCount( 1, $result );
$this->assertSame( '0', $result[0]->col_int );
$this->assertSame( PHP_VERSION_ID < 80100 ? '0.0' : '0', $result[0]->col_float );
$this->assertSame( PHP_VERSION_ID < 80100 ? '0.0' : '0', $result[0]->col_double );
$this->assertSame( PHP_VERSION_ID < 80100 ? '0.0' : '0', $result[0]->col_decimal );
$this->assertSame( '', $result[0]->col_char );
$this->assertSame( '', $result[0]->col_varchar );
$this->assertSame( '', $result[0]->col_text );
$this->assertSame( '0', $result[0]->col_bool );
$this->assertSame( '0', $result[0]->col_bit );
$this->assertSame( PHP_VERSION_ID < 80100 ? null : '', $result[0]->col_binary );
$this->assertSame( PHP_VERSION_ID < 80100 ? null : '', $result[0]->col_varbinary );
$this->assertSame( PHP_VERSION_ID < 80100 ? null : '', $result[0]->col_blob );
$this->assertSame( '0000-00-00', $result[0]->col_date );
$this->assertSame( '00:00:00', $result[0]->col_time );
$this->assertSame( '0000-00-00 00:00:00', $result[0]->col_datetime );
$this->assertSame( '0000-00-00 00:00:00', $result[0]->col_timestamp );
$this->assertSame( '0000', $result[0]->col_year );
$this->assertSame( '', $result[0]->col_enum );
$this->assertSame( '', $result[0]->col_set );
$this->assertSame( '', $result[0]->col_json ); // TODO: This should not be allowed.

// UPDATE.
$this->assertQuery(
"UPDATE t SET
col_int = '',
col_float = '',
col_double = '',
col_decimal = '',
col_char = '',
col_varchar = '',
col_text = '',
col_bool = '',
col_bit = '',
col_binary = '',
col_varbinary = '',
col_blob = '',
col_date = '',
col_time = '',
col_datetime = '',
col_timestamp = '',
col_year = '',
col_enum = '',
col_set = '',
col_json = ''
"
);

$result = $this->assertQuery( 'SELECT * FROM t' );
$this->assertCount( 1, $result );
$this->assertSame( '0', $result[0]->col_int );
$this->assertSame( PHP_VERSION_ID < 80100 ? '0.0' : '0', $result[0]->col_float );
$this->assertSame( PHP_VERSION_ID < 80100 ? '0.0' : '0', $result[0]->col_double );
$this->assertSame( PHP_VERSION_ID < 80100 ? '0.0' : '0', $result[0]->col_decimal );
$this->assertSame( '', $result[0]->col_char );
$this->assertSame( '', $result[0]->col_varchar );
$this->assertSame( '', $result[0]->col_text );
$this->assertSame( '0', $result[0]->col_bool );
$this->assertSame( '0', $result[0]->col_bit );
$this->assertSame( PHP_VERSION_ID < 80100 ? null : '', $result[0]->col_binary );
$this->assertSame( PHP_VERSION_ID < 80100 ? null : '', $result[0]->col_varbinary );
$this->assertSame( PHP_VERSION_ID < 80100 ? null : '', $result[0]->col_blob );
$this->assertSame( '0000-00-00', $result[0]->col_date );
$this->assertSame( '00:00:00', $result[0]->col_time );
$this->assertSame( '0000-00-00 00:00:00', $result[0]->col_datetime );
$this->assertSame( '0000-00-00 00:00:00', $result[0]->col_timestamp );
$this->assertSame( '0000', $result[0]->col_year );
$this->assertSame( '', $result[0]->col_enum );
$this->assertSame( '', $result[0]->col_set );
$this->assertSame( '', $result[0]->col_json ); // TODO: This should not be allowed.
}

public function testSessionSqlModes(): void {
// Syntax: "sql_mode" ("@@sql_mode" for SELECT)
$this->assertQuery( 'SET sql_mode = "ERROR_FOR_DIVISION_BY_ZERO"' );
Expand Down
2 changes: 1 addition & 1 deletion tests/WP_SQLite_Driver_Translation_Tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -1110,7 +1110,7 @@ public function testDateAndTimeDataTypes(): void {

public function testBinaryDataTypes(): void {
$this->assertQuery(
'CREATE TABLE `t` ( `b` INTEGER, `v` BLOB ) STRICT',
'CREATE TABLE `t` ( `b` BLOB, `v` BLOB ) STRICT',
'CREATE TABLE t (b BINARY, v VARBINARY(255))'
);

Expand Down
Loading