Make WordPress Core

Changeset 26252


Ignore:
Timestamp:
11/18/2013 08:44:34 PM (13 years ago)
Author:
wonderboymusic
Message:

For unit tests that call wpmu_create_blog(), Blog factory, or installation code that attempts to clear transients: suppress database errors on setUp and restore on tearDown.

There are a few places in core that were preventing this from working by explicity setting $wpdb->suppress_errors to false. Instead, they should inherit the value that existed before errors were suppressed.

This allows Multisite unit tests to run without explosive database errors, and allows $wpdb->suppress_errors to be overridden all the way down the chain.

Fixes #26102.

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/upgrade.php

    r26251 r26252  
    15541554
    15551555                // Fetch the table column structure from the database
    1556                 $wpdb->suppress_errors();
     1556                $suppress = $wpdb->suppress_errors();
    15571557                $tablefields = $wpdb->get_results("DESCRIBE {$table};");
    1558                 $wpdb->suppress_errors( false );
     1558                $wpdb->suppress_errors( $suppress );
    15591559
    15601560                if ( ! $tablefields )
  • trunk/src/wp-includes/ms-functions.php

    r26120 r26252  
    11301130        require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
    11311131
    1132         $wpdb->suppress_errors();
     1132        $suppress = $wpdb->suppress_errors();
    11331133        if ( $wpdb->get_results( "DESCRIBE {$wpdb->posts}" ) )
    11341134                die( '<h1>' . __( 'Already Installed' ) . '</h1><p>' . __( 'You appear to have already installed WordPress. To reinstall please clear your old database tables first.' ) . '</p></body></html>' );
    1135         $wpdb->suppress_errors( false );
     1135        $wpdb->suppress_errors( $suppress );
    11361136
    11371137        $url = get_blogaddress_by_id( $blog_id );
     
    11801180        require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
    11811181
    1182         $wpdb->suppress_errors();
     1182        $suppress = $wpdb->suppress_errors();
    11831183
    11841184        wp_install_defaults($user_id);
    11851185
    1186         $wpdb->suppress_errors( false );
     1186        $wpdb->suppress_errors( $suppress );
    11871187}
    11881188
  • trunk/tests/phpunit/includes/factory.php

    r25660 r26252  
    160160
    161161        function create_object( $args ) {
     162                global $wpdb;
    162163                $meta = isset( $args['meta'] ) ? $args['meta'] : array();
    163164                $user_id = isset( $args['user_id'] ) ? $args['user_id'] : get_current_user_id();
    164                 return wpmu_create_blog( $args['domain'], $args['path'], $args['title'], $user_id, $meta, $args['site_id'] );
     165                // temp tables will trigger db errors when we attempt to reference them as new temp tables
     166                $suppress = $wpdb->suppress_errors();
     167                $blog = wpmu_create_blog( $args['domain'], $args['path'], $args['title'], $user_id, $meta, $args['site_id'] );
     168                $wpdb->suppress_errors( $suppress );
     169                return $blog;
    165170        }
    166171
  • trunk/tests/phpunit/tests/ms.php

    r25621 r26252  
    1010class Tests_MS extends WP_UnitTestCase {
    1111        protected $plugin_hook_count = 0;
     12        protected $suppress = false;
    1213
    1314        function setUp() {
     15                global $wpdb;
    1416                parent::setUp();
     17                $this->suppress = $wpdb->suppress_errors();
    1518
    1619                $_SERVER['REMOTE_ADDR'] = '';
     20        }
     21
     22        function tearDown() {
     23                global $wpdb;
     24                parent::tearDown();
     25                $wpdb->suppress_errors( $this->suppress );
    1726        }
    1827
     
    106115
    107116                        foreach ( $wpdb->tables( 'blog', false ) as $table ) {
    108                                 $wpdb->suppress_errors();
     117                                $suppress = $wpdb->suppress_errors();
    109118                                $table_fields = $wpdb->get_results( "DESCRIBE $prefix$table;" );
    110                                 $wpdb->suppress_errors( false );
     119                                $wpdb->suppress_errors( $suppress );
    111120                                $this->assertNotEmpty( $table_fields );
    112121                                $result = $wpdb->get_results( "SELECT * FROM $prefix$table LIMIT 1" );
     
    140149                        $prefix = $wpdb->get_blog_prefix( $blog_id );
    141150                        foreach ( $wpdb->tables( 'blog', false ) as $table ) {
    142                                 $wpdb->suppress_errors();
     151                                $suppress = $wpdb->suppress_errors();
    143152                                $table_fields = $wpdb->get_results( "DESCRIBE $prefix$table;" );
    144                                 $wpdb->suppress_errors( false );
     153                                $wpdb->suppress_errors( $suppress );
    145154                                if ( $drop_tables )
    146155                                        $this->assertEmpty( $table_fields );
  • trunk/tests/phpunit/tests/option/blogOption.php

    r25397 r26252  
    66 */
    77class Tests_Option_BlogOption extends WP_UnitTestCase {
     8        protected $suppress = false;
     9
    810        function setUp() {
     11                global $wpdb;
    912                parent::setUp();
     13                $this->suppress = $wpdb->suppress_errors();
    1014
    1115                $_SERVER['REMOTE_ADDR'] = null;
     16        }
     17
     18        function tearDown() {
     19                global $wpdb;
     20                parent::tearDown();
     21                $wpdb->suppress_errors( $this->suppress );
    1222        }
    1323
Note: See TracChangeset for help on using the changeset viewer.