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.


git-svn-id: https://develop.svn.wordpress.org/trunk@26252 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Scott Taylor
2013-11-18 20:44:34 +00:00
parent d42e8eee3d
commit ff4f1bb170
5 changed files with 35 additions and 11 deletions

View File

@@ -9,13 +9,22 @@ if ( is_multisite() ) :
*/
class Tests_MS extends WP_UnitTestCase {
protected $plugin_hook_count = 0;
protected $suppress = false;
function setUp() {
global $wpdb;
parent::setUp();
$this->suppress = $wpdb->suppress_errors();
$_SERVER['REMOTE_ADDR'] = '';
}
function tearDown() {
global $wpdb;
parent::tearDown();
$wpdb->suppress_errors( $this->suppress );
}
/**
* @ticket 22917
*/
@@ -105,9 +114,9 @@ class Tests_MS extends WP_UnitTestCase {
$this->assertEquals( $details, wp_cache_get( $key, 'blog-lookup' ) );
foreach ( $wpdb->tables( 'blog', false ) as $table ) {
$wpdb->suppress_errors();
$suppress = $wpdb->suppress_errors();
$table_fields = $wpdb->get_results( "DESCRIBE $prefix$table;" );
$wpdb->suppress_errors( false );
$wpdb->suppress_errors( $suppress );
$this->assertNotEmpty( $table_fields );
$result = $wpdb->get_results( "SELECT * FROM $prefix$table LIMIT 1" );
if ( 'commentmeta' == $table || 'links' == $table )
@@ -139,9 +148,9 @@ class Tests_MS extends WP_UnitTestCase {
$prefix = $wpdb->get_blog_prefix( $blog_id );
foreach ( $wpdb->tables( 'blog', false ) as $table ) {
$wpdb->suppress_errors();
$suppress = $wpdb->suppress_errors();
$table_fields = $wpdb->get_results( "DESCRIBE $prefix$table;" );
$wpdb->suppress_errors( false );
$wpdb->suppress_errors( $suppress );
if ( $drop_tables )
$this->assertEmpty( $table_fields );
else