From f4ac65db2d6c242a53e33d91ed26ad8cc6655b68 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Thu, 12 Sep 2013 05:48:58 +0000 Subject: [PATCH] * Suppress deprecated function notices in `tests/theme/themeDir.php` * Set `$theme['Template Files']` and `$theme['Stylesheet Files']` to a variable before calling array methods upon them - avoids `Indirect modification of overloaded element has no effect` notice * Clean up setUp/tearDown in `tests/theme.php` See #25282. git-svn-id: https://develop.svn.wordpress.org/trunk@25388 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/theme.php | 24 +++++++++++++----------- tests/phpunit/tests/theme/themeDir.php | 23 ++++++++++++++++++++--- 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/tests/phpunit/tests/theme.php b/tests/phpunit/tests/theme.php index 8618f58766..601f87fdd6 100644 --- a/tests/phpunit/tests/theme.php +++ b/tests/phpunit/tests/theme.php @@ -16,17 +16,7 @@ class Tests_Theme extends WP_UnitTestCase { wp_clean_themes_cache(); unset( $GLOBALS['wp_themes'] ); - add_action( 'deprecated_function_run', array( $this, 'deprecated_function_run_check' ) ); - } - - function deprecated_function_run_check( $function ) { - if ( in_array( $function, array( 'get_theme', 'get_themes', 'get_theme_data', 'get_current_theme' ) ) ) - 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; + add_action( 'deprecated_function_run', array( $this, 'deprecated_function_run' ) ); } function tearDown() { @@ -34,6 +24,18 @@ class Tests_Theme extends WP_UnitTestCase { wp_clean_themes_cache(); unset( $GLOBALS['wp_themes'] ); parent::tearDown(); + + remove_action( 'deprecated_function_run', array( $this, 'deprecated_function_run' ) ); + } + + function deprecated_function_run( $function ) { + if ( in_array( $function, array( 'get_theme', 'get_themes', 'get_theme_data', 'get_current_theme' ) ) ) + add_filter( 'deprecated_function_trigger_error', array( $this, 'deprecated_function_trigger_error' ) ); + } + + function deprecated_function_trigger_error() { + remove_filter( 'deprecated_function_trigger_error', array( $this, 'deprecated_function_trigger_error' ) ); + return false; } function test_wp_get_themes_default() { diff --git a/tests/phpunit/tests/theme/themeDir.php b/tests/phpunit/tests/theme/themeDir.php index bf4f19d9f8..f62f165ee7 100644 --- a/tests/phpunit/tests/theme/themeDir.php +++ b/tests/phpunit/tests/theme/themeDir.php @@ -21,6 +21,7 @@ class Tests_Theme_ThemeDir extends WP_UnitTestCase { // clear caches wp_clean_themes_cache(); unset( $GLOBALS['wp_themes'] ); + add_action( 'deprecated_function_run', array( $this, 'deprecated_function_run' ) ); } function tearDown() { @@ -31,6 +32,17 @@ class Tests_Theme_ThemeDir extends WP_UnitTestCase { wp_clean_themes_cache(); unset( $GLOBALS['wp_themes'] ); parent::tearDown(); + remove_action( 'deprecated_function_run', array( $this, 'deprecated_function_run' ) ); + } + + function deprecated_function_run( $function ) { + if ( in_array( $function, array( 'get_theme', 'get_themes', 'get_theme_data', 'get_current_theme', 'get_broken_themes' ) ) ) + add_filter( 'deprecated_function_trigger_error', array( $this, 'deprecated_function_trigger_error' ) ); + } + + function deprecated_function_trigger_error() { + remove_filter( 'deprecated_function_trigger_error', array( $this, 'deprecated_function_trigger_error' ) ); + return false; } // replace the normal theme root dir with our premade test dir @@ -79,10 +91,15 @@ class Tests_Theme_ThemeDir extends WP_UnitTestCase { $this->assertEquals( '0.6.1-wpcom', $theme['Version'] ); $this->assertEquals( 'sandbox', $theme['Template'] ); $this->assertEquals( 'sandbox', $theme['Stylesheet'] ); - $this->assertEquals( $this->theme_root.'/sandbox/functions.php', reset($theme['Template Files']) ); - $this->assertEquals( $this->theme_root.'/sandbox/index.php', next($theme['Template Files']) ); - $this->assertEquals( $this->theme_root.'/sandbox/style.css', reset($theme['Stylesheet Files']) ); + $template_files = $theme['Template Files']; + + $this->assertEquals( $this->theme_root.'/sandbox/functions.php', reset( $template_files ) ); + $this->assertEquals( $this->theme_root.'/sandbox/index.php', next( $template_files ) ); + + $stylesheet_files = $theme['Stylesheet Files']; + + $this->assertEquals( $this->theme_root.'/sandbox/style.css', reset( $stylesheet_files ) ); $this->assertEquals( $this->theme_root.'/sandbox', $theme['Template Dir'] ); $this->assertEquals( $this->theme_root.'/sandbox', $theme['Stylesheet Dir'] );