* 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
This commit is contained in:
Scott Taylor 2013-09-12 05:48:58 +00:00
parent ee35baae6b
commit f4ac65db2d
2 changed files with 33 additions and 14 deletions

View File

@ -16,17 +16,7 @@ class Tests_Theme extends WP_UnitTestCase {
wp_clean_themes_cache(); wp_clean_themes_cache();
unset( $GLOBALS['wp_themes'] ); unset( $GLOBALS['wp_themes'] );
add_action( 'deprecated_function_run', array( $this, 'deprecated_function_run_check' ) ); add_action( 'deprecated_function_run', array( $this, 'deprecated_function_run' ) );
}
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;
} }
function tearDown() { function tearDown() {
@ -34,6 +24,18 @@ class Tests_Theme extends WP_UnitTestCase {
wp_clean_themes_cache(); wp_clean_themes_cache();
unset( $GLOBALS['wp_themes'] ); unset( $GLOBALS['wp_themes'] );
parent::tearDown(); 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() { function test_wp_get_themes_default() {

View File

@ -21,6 +21,7 @@ class Tests_Theme_ThemeDir extends WP_UnitTestCase {
// clear caches // clear caches
wp_clean_themes_cache(); wp_clean_themes_cache();
unset( $GLOBALS['wp_themes'] ); unset( $GLOBALS['wp_themes'] );
add_action( 'deprecated_function_run', array( $this, 'deprecated_function_run' ) );
} }
function tearDown() { function tearDown() {
@ -31,6 +32,17 @@ class Tests_Theme_ThemeDir extends WP_UnitTestCase {
wp_clean_themes_cache(); wp_clean_themes_cache();
unset( $GLOBALS['wp_themes'] ); unset( $GLOBALS['wp_themes'] );
parent::tearDown(); 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 // 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( '0.6.1-wpcom', $theme['Version'] );
$this->assertEquals( 'sandbox', $theme['Template'] ); $this->assertEquals( 'sandbox', $theme['Template'] );
$this->assertEquals( 'sandbox', $theme['Stylesheet'] ); $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['Template Dir'] );
$this->assertEquals( $this->theme_root.'/sandbox', $theme['Stylesheet Dir'] ); $this->assertEquals( $this->theme_root.'/sandbox', $theme['Stylesheet Dir'] );