Make WordPress Core


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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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 );
Note: See TracChangeset for help on using the changeset viewer.