From 2b78c9579a36a37523362c80b8c17658396c0a26 Mon Sep 17 00:00:00 2001 From: Gary Pendergast Date: Mon, 28 Sep 2015 01:16:29 +0000 Subject: [PATCH] WPDB: Make sure we don't run sanity checks on DB dropins. Previously, we'd run the sanity checks if `is_mysql` was not set to `false`. This caused problems for DB drop-ins that didn't define `is_mysql` at all. Instead, we can just check if `is_mysql` is `empty()`. Also fix some unit tests that accidently ran correctly because of the strict `false ===` comparison. Fixes #33501. git-svn-id: https://develop.svn.wordpress.org/trunk@34655 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/wp-db.php | 4 ++-- tests/phpunit/includes/utils.php | 1 + tests/phpunit/tests/db/charset.php | 26 ++++++++++++++++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/wp-db.php b/src/wp-includes/wp-db.php index 02d852683e..e52d6fd2f4 100644 --- a/src/wp-includes/wp-db.php +++ b/src/wp-includes/wp-db.php @@ -2414,7 +2414,7 @@ class wpdb { } // Skip this entirely if this isn't a MySQL database. - if ( false === $this->is_mysql ) { + if ( empty( $this->is_mysql ) ) { return false; } @@ -2463,7 +2463,7 @@ class wpdb { $columnkey = strtolower( $column ); // Skip this entirely if this isn't a MySQL database. - if ( false === $this->is_mysql ) { + if ( empty( $this->is_mysql ) ) { return false; } diff --git a/tests/phpunit/includes/utils.php b/tests/phpunit/includes/utils.php index a7aec495f9..baebfe0303 100644 --- a/tests/phpunit/includes/utils.php +++ b/tests/phpunit/includes/utils.php @@ -380,6 +380,7 @@ class wpdb_exposed_methods_for_testing extends wpdb { global $wpdb; $this->dbh = $wpdb->dbh; $this->use_mysqli = $wpdb->use_mysqli; + $this->is_mysql = $wpdb->is_mysql; $this->ready = true; $this->field_types = $wpdb->field_types; $this->charset = $wpdb->charset; diff --git a/tests/phpunit/tests/db/charset.php b/tests/phpunit/tests/db/charset.php index 45c7978419..c1692921da 100644 --- a/tests/phpunit/tests/db/charset.php +++ b/tests/phpunit/tests/db/charset.php @@ -637,6 +637,32 @@ class Tests_DB_Charset extends WP_UnitTestCase { self::$_wpdb->is_mysql = true; } + /** + * @dataProvider data_test_get_column_charset + * @ticket 33501 + */ + function test_get_column_charset_is_mysql_undefined( $drop, $create, $table, $columns ) { + self::$_wpdb->query( $drop ); + + if ( ! self::$_wpdb->has_cap( 'utf8mb4' ) && preg_match( '/utf8mb[34]/i', $create ) ) { + $this->markTestSkipped( "This version of MySQL doesn't support utf8mb4." ); + return; + } + + unset( self::$_wpdb->is_mysql ); + + self::$_wpdb->query( $create ); + + $columns = array_keys( $columns ); + foreach ( $columns as $column => $charset ) { + $this->assertEquals( false, self::$_wpdb->get_col_charset( $table, $column ) ); + } + + self::$_wpdb->query( $drop ); + + self::$_wpdb->is_mysql = true; + } + /** * @ticket 21212 */