WordPress.org

Make WordPress Core

Changeset 27041


Ignore:
Timestamp:
01/27/2014 03:09:13 AM (4 years ago)
Author:
nacin
Message:

Test framework: Parse CREATE TABLE queries the same way we do DROP TABLE queries.

props soulseekah.
fixes #24800.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/includes/testcase.php

    r26909 r27041  
    3636        $this->expectedDeprecated();
    3737        $wpdb->query( 'ROLLBACK' );
    38         remove_filter( 'dbdelta_create_queries', array( $this, '_create_temporary_tables' ) );
    39         remove_filter( 'query', array( $this, '_drop_temporary_tables' ) );
     38        remove_filter( 'query', array( $this, '_create_temporary_table' ) );
     39        remove_filter( 'query', array( $this, '_drop_temporary_table' ) );
    4040        remove_filter( 'wp_die_handler', array( $this, 'get_wp_die_handler' ) );
    4141    }
     
    6565        $wpdb->query( 'SET autocommit = 0;' );
    6666        $wpdb->query( 'START TRANSACTION;' );
    67         add_filter( 'dbdelta_create_queries', array( $this, '_create_temporary_tables' ) );
    68         add_filter( 'query', array( $this, '_drop_temporary_tables' ) );
    69     }
    70 
    71     function _create_temporary_tables( $queries ) {
    72         return str_replace( 'CREATE TABLE', 'CREATE TEMPORARY TABLE', $queries );
    73     }
    74 
    75     function _drop_temporary_tables( $query ) {
     67        add_filter( 'query', array( $this, '_create_temporary_table' ) );
     68        add_filter( 'query', array( $this, '_drop_temporary_table' ) );
     69    }
     70
     71    function _create_temporary_table( $query ) {
     72        if ( 'CREATE TABLE' === substr( $query, 0, 12 ) )
     73            return substr_replace( $query, 'CREATE TEMPORARY TABLE', 0, 12 );
     74        return $query;
     75    }
     76
     77    function _drop_temporary_table( $query ) {
    7678        if ( 'DROP TABLE' === substr( $query, 0, 10 ) )
    77             return 'DROP TEMPORARY TABLE ' . substr( $query, 10 );
     79            return substr_replace( $query, 'DROP TEMPORARY TABLE', 0, 10 );
    7880        return $query;
    7981    }
Note: See TracChangeset for help on using the changeset viewer.