From 3ae18e68ffaac44ae69989ab7f42affed3998da5 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Thu, 12 Sep 2013 07:16:30 +0000 Subject: [PATCH] * Fill in undefined var in `Tests_Option_BlogOption` * Add `defined()` check for `BLOGSUPLOADDIR` * Suppress deprecated function notices for `is_blog_user()` and `get_dashboard_blog()` * Check existence of `$user` in `wpmu_log_new_registrations()` before arbitrarily making a database query Fixes all notices in multisite unit tests. See #25282. git-svn-id: https://develop.svn.wordpress.org/trunk@25397 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/ms-functions.php | 3 ++- tests/phpunit/tests/ms.php | 28 ++++++++++++++++++++--- tests/phpunit/tests/option/blogOption.php | 7 ++++++ 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/wp-includes/ms-functions.php b/src/wp-includes/ms-functions.php index eb44be0290..830bb5cc28 100644 --- a/src/wp-includes/ms-functions.php +++ b/src/wp-includes/ms-functions.php @@ -1476,7 +1476,8 @@ function update_posts_count( $deprecated = '' ) { function wpmu_log_new_registrations( $blog_id, $user_id ) { global $wpdb; $user = get_userdata( (int) $user_id ); - $wpdb->insert( $wpdb->registration_log, array('email' => $user->user_email, 'IP' => preg_replace( '/[^0-9., ]/', '', wp_unslash( $_SERVER['REMOTE_ADDR'] ) ), 'blog_id' => $blog_id, 'date_registered' => current_time('mysql')) ); + if ( $user ) + $wpdb->insert( $wpdb->registration_log, array('email' => $user->user_email, 'IP' => preg_replace( '/[^0-9., ]/', '', wp_unslash( $_SERVER['REMOTE_ADDR'] ) ), 'blog_id' => $blog_id, 'date_registered' => current_time('mysql')) ); } /** diff --git a/tests/phpunit/tests/ms.php b/tests/phpunit/tests/ms.php index 73bda9e55e..610c47ebfc 100644 --- a/tests/phpunit/tests/ms.php +++ b/tests/phpunit/tests/ms.php @@ -11,6 +11,28 @@ class Tests_MS extends WP_UnitTestCase { protected $plugin_hook_count = 0; + function setUp() { + parent::setUp(); + + $_SERVER['REMOTE_ADDR'] = ''; + add_action( 'deprecated_function_run', array( $this, 'deprecated_function_run_check' ) ); + } + + function tearDown() { + parent::tearDown(); + remove_action( 'deprecated_function_run', array( $this, 'deprecated_function_run_check' ) ); + } + + function deprecated_function_run_check( $function ) { + if ( in_array( $function, array( 'is_blog_user', 'get_dashboard_blog' ) ) ) + add_filter( 'deprecated_function_trigger_error', array( $this, 'filter_deprecated_function_trigger_error' ) ); + } + + function filter_deprecated_function_trigger_error() { + remove_filter( 'deprecated_function_trigger_error', array( $this, 'filter_deprecated_function_trigger_error' ) ); + return false; + } + function test_create_and_delete_blog() { global $wpdb; @@ -308,7 +330,7 @@ class Tests_MS extends WP_UnitTestCase { $this->assertFalse( upload_is_user_over_quota( $echo ) ); $this->assertTrue( is_upload_space_available() ); - if ( ! file_exists( BLOGSUPLOADDIR ) ) + if ( defined( 'BLOGSUPLOADDIR' ) && ! file_exists( BLOGSUPLOADDIR ) ) $this->markTestSkipped( 'This test is broken when blogs.dir does not exist. '); /* @@ -525,7 +547,7 @@ class Tests_MS extends WP_UnitTestCase { /** * Test fetching a blog that doesn't exist and again after it exists. - * + * * @ticket 23405 */ function test_get_blog_details_blog_does_not_exist() { @@ -1013,7 +1035,7 @@ class Tests_MS extends WP_UnitTestCase { 'user_login' => $spam_username, ) ); update_user_status( $spam_user_id, 'spam', '1' ); - + $this->assertTrue( is_user_spammy( $spam_username ) ); $this->assertFalse( is_user_spammy( 'testuser1' ) ); } diff --git a/tests/phpunit/tests/option/blogOption.php b/tests/phpunit/tests/option/blogOption.php index d769ba43d4..6a782780c4 100644 --- a/tests/phpunit/tests/option/blogOption.php +++ b/tests/phpunit/tests/option/blogOption.php @@ -5,6 +5,12 @@ if ( is_multisite() ) : * @group option */ class Tests_Option_BlogOption extends WP_UnitTestCase { + function setUp() { + parent::setUp(); + + $_SERVER['REMOTE_ADDR'] = null; + } + function test_from_same_site() { $key = rand_str(); $key2 = rand_str(); @@ -81,6 +87,7 @@ class Tests_Option_BlogOption extends WP_UnitTestCase { function test_with_another_site() { global $current_site, $base; + $title = 'Fooblog'; $domain = 'blogoptiontest'; if ( is_subdomain_install() ) {