Database: Fix a test failing on MySQL 5.7 and MariaDB 10.2.

On newer versions of MySQL, an error was being thrown when creating a table with an index that we wanted to be silently truncated.

To avoid this, the test now tries to use a newer InnoDB file format where available, and skips the test when that happens.

Props pento, danielbachhuber, straussd.
Fixes #41716.



git-svn-id: https://develop.svn.wordpress.org/trunk@41818 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Gary Pendergast 2017-10-10 23:45:35 +00:00
parent 77c6dc7fd8
commit 6411029d0d
1 changed files with 19 additions and 2 deletions

View File

@ -361,13 +361,30 @@ class Tests_dbDelta extends WP_UnitTestCase {
$this->markTestSkipped( 'This test requires utf8mb4 support in MySQL.' ); $this->markTestSkipped( 'This test requires utf8mb4 support in MySQL.' );
} }
$table_name = 'test_truncated_index'; // This table needs to be actually created
remove_filter( 'query', array( $this, '_create_temporary_tables' ) );
remove_filter( 'query', array( $this, '_drop_temporary_tables' ) );
$table_name = "{$wpdb->prefix}test_truncated_index";
$create = "
CREATE TABLE $table_name (
a varchar(255) COLLATE utf8mb4_unicode_ci,
KEY a_key (a)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC";
$create = "CREATE TABLE $table_name (\n a varchar(255) COLLATE utf8mb4_unicode_ci,\n KEY a (a)\n)";
$wpdb->query( $create ); $wpdb->query( $create );
$index = $wpdb->get_row( "SHOW INDEXES FROM $table_name WHERE Key_name='a_key';" );
$actual = dbDelta( $create, false ); $actual = dbDelta( $create, false );
$wpdb->query( "DROP TABLE IF EXISTS $table_name;" );
if ( 191 != $index->Sub_part ) {
$this->markTestSkipped( "This test requires the index to be truncated." );
}
$this->assertSame( array(), $actual ); $this->assertSame( array(), $actual );
} }