Skip to content

Commit 9d7e8fe

Browse files
committed
Tests: Use a minimal theme for tests.
New default themes require workarounds being added to several unit tests, as they often alter default WordPress behaviour. To avoid ongoing maintenance issues, this change switches to a minimal theme when running tests. This change also removes the old workarounds for default themes. Fixes #31550. git-svn-id: https://develop.svn.wordpress.org/trunk@38858 602fd350-edb4-49c9-b593-d223f7449a82
1 parent e7d6393 commit 9d7e8fe

17 files changed

Lines changed: 48 additions & 59 deletions
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?php
2+
3+
// Minimal comment template
4+
wp_list_comments();
Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
<?php
22

3-
// dummy theme
3+
// Minimum functions.php to pass unit tests
44

5-
echo dirname(__FILE__).'/'.basename(__FILE__);
5+
function default_widgets_init() {
6+
register_sidebar( array( 'id' => 'sidebar-1' ) );
7+
}
8+
add_action( 'widgets_init', 'default_widgets_init' );
69

7-
?>
10+
function default_after_setup_theme() {
11+
add_theme_support( 'post-thumbnails' );
12+
13+
// Don't call it after wp_loaded has happened, for tests that manually re-run load actions.
14+
if( ! did_action( 'wp_loaded' ) ) {
15+
add_theme_support( 'title-tag' );
16+
}
17+
}
18+
add_action( 'after_setup_theme', 'default_after_setup_theme' );
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
11
<?php
22

3-
// dummy theme
4-
5-
echo dirname(__FILE__).'/'.basename(__FILE__);
6-
7-
?>
3+
// Empty theme

‎tests/phpunit/includes/bootstrap.php‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@
5353
require_once( dirname( __FILE__ ) . '/mock-mailer.php' );
5454
$phpmailer = new MockPHPMailer();
5555

56+
// Add a symlink to the empty default theme to the themes directory, so it can be used for the tests.
57+
_symlink_default_theme();
58+
5659
system( WP_PHP_BINARY . ' ' . escapeshellarg( dirname( __FILE__ ) . '/install.php' ) . ' ' . escapeshellarg( $config_file_path ) . ' ' . $multisite );
5760

5861
if ( $multisite ) {

‎tests/phpunit/includes/functions.php‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,21 @@ function _upload_dir_https( $uploads ) {
161161

162162
return $uploads;
163163
}
164+
165+
/**
166+
* Helper functions to link and unlink the empty default theme into the WordPress install
167+
*/
168+
function _symlink_default_theme() {
169+
_unlink_default_theme();
170+
symlink( DIR_TESTDATA . '/themedir1/default', ABSPATH . '/wp-content/themes/default' );
171+
}
172+
173+
function _unlink_default_theme() {
174+
if ( file_exists( ABSPATH . '/wp-content/themes/default' ) ) {
175+
unlink( ABSPATH . '/wp-content/themes/default' );
176+
}
177+
}
178+
// Only unlink when we're in the main process.
179+
if ( 'phpunit' === substr( $GLOBALS['argv'][0], -7 ) ) {
180+
register_shutdown_function( '_unlink_default_theme' );
181+
}

‎tests/phpunit/tests/customize/control.php‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@ function setUp() {
3131
$GLOBALS['wp_customize'] = new WP_Customize_Manager();
3232
// @codingStandardsIgnoreEnd
3333
$this->wp_customize = $GLOBALS['wp_customize'];
34-
35-
// Remove default theme actions that interfere with tests
36-
remove_action( 'customize_register', 'twentyseventeen_customize_register' );
3734
}
3835

3936
/**

‎tests/phpunit/tests/customize/custom-css-setting.php‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@ function setUp() {
3636
$this->wp_customize = new WP_Customize_Manager();
3737
$wp_customize = $this->wp_customize;
3838

39-
// Remove default theme actions that interfere with tests
40-
remove_action( 'customize_register', 'twentyseventeen_customize_register' );
41-
4239
do_action( 'customize_register', $this->wp_customize );
4340
$this->setting = new WP_Customize_Custom_CSS_Setting( $this->wp_customize, 'custom_css[twentysixteen]' );
4441
$this->wp_customize->add_setting( $this->setting );

‎tests/phpunit/tests/customize/manager.php‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,6 @@ function setUp() {
5858
require_once( ABSPATH . WPINC . '/class-wp-customize-manager.php' );
5959
$this->manager = $this->instantiate();
6060
$this->undefined = new stdClass();
61-
62-
// Remove default theme actions that interfere with tests
63-
remove_action( 'customize_register', 'twentyseventeen_customize_register' );
6461
}
6562

6663
/**

‎tests/phpunit/tests/customize/nav-menu-item-setting.php‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ function setUp() {
2626
global $wp_customize;
2727
$this->wp_customize = new WP_Customize_Manager();
2828
$wp_customize = $this->wp_customize;
29-
30-
// Remove default theme actions that interfere with tests
31-
remove_action( 'customize_register', 'twentyseventeen_customize_register' );
3229
}
3330

3431
/**

‎tests/phpunit/tests/customize/nav-menu-setting.php‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ function setUp() {
2727
global $wp_customize;
2828
$this->wp_customize = new WP_Customize_Manager();
2929
$wp_customize = $this->wp_customize;
30-
31-
// Remove default theme actions that interfere with tests
32-
remove_action( 'customize_register', 'twentyseventeen_customize_register' );
3330
}
3431

3532
/**

0 commit comments

Comments
 (0)