From 6411029d0d99663c4259bfc3beedf0193dcdb13c Mon Sep 17 00:00:00 2001 From: Gary Pendergast Date: Tue, 10 Oct 2017 23:45:35 +0000 Subject: [PATCH] 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 --- tests/phpunit/tests/dbdelta.php | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/tests/phpunit/tests/dbdelta.php b/tests/phpunit/tests/dbdelta.php index ecf7c8a294..be6d2ce361 100644 --- a/tests/phpunit/tests/dbdelta.php +++ b/tests/phpunit/tests/dbdelta.php @@ -361,13 +361,30 @@ class Tests_dbDelta extends WP_UnitTestCase { $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 ); + $index = $wpdb->get_row( "SHOW INDEXES FROM $table_name WHERE Key_name='a_key';" ); + $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 ); }