Skip to content

Commit fa298df

Browse files
wojteknJanJakes
authored andcommitted
Add test that reproduces issue
1 parent 0484b2c commit fa298df

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

tests/WP_SQLite_Translator_Tests.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3520,4 +3520,41 @@ public static function mysqlVariablesToTest() {
35203520
array( '@@sEssIOn.sqL_moDe' ),
35213521
);
35223522
}
3523+
3524+
/**
3525+
* Test CREATE TABLE with DEFAULT (now()) - GitHub issue #300
3526+
* Tests that DEFAULT with function calls in parentheses works correctly.
3527+
*/
3528+
public function testCreateTableWithDefaultNowFunction() {
3529+
// Test the exact SQL from the issue
3530+
$this->assertQuery(
3531+
"CREATE TABLE `test_now_default` (
3532+
`id` int NOT NULL,
3533+
`updated` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP
3534+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;"
3535+
);
3536+
3537+
// Verify the table was created successfully
3538+
$results = $this->assertQuery( 'DESCRIBE test_now_default;' );
3539+
$this->assertCount( 2, $results );
3540+
3541+
// Verify the updated column has the correct properties
3542+
$updated_field = $results[1];
3543+
$this->assertEquals( 'updated', $updated_field->Field );
3544+
$this->assertEquals( 'timestamp', $updated_field->Type );
3545+
$this->assertEquals( 'NO', $updated_field->Null );
3546+
3547+
// Insert a row to verify the default value works
3548+
$this->assertQuery( 'INSERT INTO test_now_default (id) VALUES (1)' );
3549+
$result = $this->assertQuery( 'SELECT * FROM test_now_default WHERE id = 1' );
3550+
$this->assertCount( 1, $result );
3551+
3552+
// Verify the updated timestamp was set (should match YYYY-MM-DD HH:MM:SS format)
3553+
$this->assertRegExp( '/\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d/', $result[0]->updated );
3554+
3555+
// Test ON UPDATE trigger works
3556+
$this->assertQuery( 'UPDATE test_now_default SET id = 2 WHERE id = 1' );
3557+
$result = $this->assertQuery( 'SELECT * FROM test_now_default WHERE id = 2' );
3558+
$this->assertRegExp( '/\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d/', $result[0]->updated );
3559+
}
35233560
}

0 commit comments

Comments
 (0)