Make WordPress Core

Changeset 837 in tests


Ignore:
Timestamp:
07/01/2012 09:40:48 PM (12 years ago)
Author:
nacin
Message:

Add the TEMPORARY keyword to CREATE TABLE and DROP TABLE to prevent implicit transaction commits. Use assertInstanceOf in assertWPError. see #82.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-testlib/testcase.php

    r807 r837  
    2020        global $wpdb;
    2121        $wpdb->query( 'ROLLBACK' );
     22        remove_filter( 'dbdelta_create_queries', array( $this, '_create_temporary_tables' ) );
     23        remove_filter( 'query', array( $this, '_drop_temporary_tables' ) );
    2224    }
    2325
     
    4446        $wpdb->query( 'SET autocommit = 0;' );
    4547        $wpdb->query( 'START TRANSACTION;' );
     48        add_filter( 'dbdelta_create_queries', array( $this, '_create_temporary_tables' ) );
     49        add_filter( 'query', array( $this, '_drop_temporary_tables' ) );
     50    }
     51
     52    function _create_temporary_tables( $queries ) {
     53        return str_replace( 'CREATE TABLE', 'CREATE TEMPORARY TABLE', $queries );
     54    }
     55
     56    function _drop_temporary_tables( $query ) {
     57        if ( 'DROP TABLE' === substr( $query, 0, 10 ) )
     58            return 'DROP TEMPORARY TABLE ' . substr( $query, 10 );
     59        return $query;
    4660    }
    4761
    4862    function assertWPError( $actual, $message = '' ) {
    49         $this->assertTrue( is_wp_error( $actual ), $message );
     63        $this->assertInstanceOf( 'WP_Error', $actual, $message );
    5064    }
    5165
Note: See TracChangeset for help on using the changeset viewer.