From c759a54b2cb30ea3c9ca4996d9209a558da18d3d Mon Sep 17 00:00:00 2001 From: Andrew Nacin Date: Mon, 27 Jan 2014 03:09:13 +0000 Subject: [PATCH] Test framework: Parse CREATE TABLE queries the same way we do DROP TABLE queries. props soulseekah. fixes #24800. git-svn-id: https://develop.svn.wordpress.org/trunk@27041 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/includes/testcase.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/tests/phpunit/includes/testcase.php b/tests/phpunit/includes/testcase.php index 50a3f5f4c1..f8a21cd31a 100644 --- a/tests/phpunit/includes/testcase.php +++ b/tests/phpunit/includes/testcase.php @@ -35,8 +35,8 @@ class WP_UnitTestCase extends PHPUnit_Framework_TestCase { global $wpdb; $this->expectedDeprecated(); $wpdb->query( 'ROLLBACK' ); - remove_filter( 'dbdelta_create_queries', array( $this, '_create_temporary_tables' ) ); - remove_filter( 'query', array( $this, '_drop_temporary_tables' ) ); + remove_filter( 'query', array( $this, '_create_temporary_table' ) ); + remove_filter( 'query', array( $this, '_drop_temporary_table' ) ); remove_filter( 'wp_die_handler', array( $this, 'get_wp_die_handler' ) ); } @@ -64,17 +64,19 @@ class WP_UnitTestCase extends PHPUnit_Framework_TestCase { global $wpdb; $wpdb->query( 'SET autocommit = 0;' ); $wpdb->query( 'START TRANSACTION;' ); - add_filter( 'dbdelta_create_queries', array( $this, '_create_temporary_tables' ) ); - add_filter( 'query', array( $this, '_drop_temporary_tables' ) ); + add_filter( 'query', array( $this, '_create_temporary_table' ) ); + add_filter( 'query', array( $this, '_drop_temporary_table' ) ); } - function _create_temporary_tables( $queries ) { - return str_replace( 'CREATE TABLE', 'CREATE TEMPORARY TABLE', $queries ); + function _create_temporary_table( $query ) { + if ( 'CREATE TABLE' === substr( $query, 0, 12 ) ) + return substr_replace( $query, 'CREATE TEMPORARY TABLE', 0, 12 ); + return $query; } - function _drop_temporary_tables( $query ) { + function _drop_temporary_table( $query ) { if ( 'DROP TABLE' === substr( $query, 0, 10 ) ) - return 'DROP TEMPORARY TABLE ' . substr( $query, 10 ); + return substr_replace( $query, 'DROP TEMPORARY TABLE', 0, 10 ); return $query; }