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
This commit is contained in:
parent
e7d639345f
commit
9d7e8fec8c
4
tests/phpunit/data/themedir1/default/comments.php
Normal file
4
tests/phpunit/data/themedir1/default/comments.php
Normal file
@ -0,0 +1,4 @@
|
||||
<?php
|
||||
|
||||
// Minimal comment template
|
||||
wp_list_comments();
|
@ -1,7 +1,18 @@
|
||||
<?php
|
||||
|
||||
// dummy theme
|
||||
// Minimum functions.php to pass unit tests
|
||||
|
||||
echo dirname(__FILE__).'/'.basename(__FILE__);
|
||||
function default_widgets_init() {
|
||||
register_sidebar( array( 'id' => 'sidebar-1' ) );
|
||||
}
|
||||
add_action( 'widgets_init', 'default_widgets_init' );
|
||||
|
||||
?>
|
||||
function default_after_setup_theme() {
|
||||
add_theme_support( 'post-thumbnails' );
|
||||
|
||||
// Don't call it after wp_loaded has happened, for tests that manually re-run load actions.
|
||||
if( ! did_action( 'wp_loaded' ) ) {
|
||||
add_theme_support( 'title-tag' );
|
||||
}
|
||||
}
|
||||
add_action( 'after_setup_theme', 'default_after_setup_theme' );
|
||||
|
@ -1,7 +1,3 @@
|
||||
<?php
|
||||
|
||||
// dummy theme
|
||||
|
||||
echo dirname(__FILE__).'/'.basename(__FILE__);
|
||||
|
||||
?>
|
||||
// Empty theme
|
||||
|
@ -53,6 +53,9 @@ $multisite = $multisite || ( defined( 'MULTISITE' ) && MULTISITE );
|
||||
require_once( dirname( __FILE__ ) . '/mock-mailer.php' );
|
||||
$phpmailer = new MockPHPMailer();
|
||||
|
||||
// Add a symlink to the empty default theme to the themes directory, so it can be used for the tests.
|
||||
_symlink_default_theme();
|
||||
|
||||
system( WP_PHP_BINARY . ' ' . escapeshellarg( dirname( __FILE__ ) . '/install.php' ) . ' ' . escapeshellarg( $config_file_path ) . ' ' . $multisite );
|
||||
|
||||
if ( $multisite ) {
|
||||
|
@ -161,3 +161,21 @@ function _upload_dir_https( $uploads ) {
|
||||
|
||||
return $uploads;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper functions to link and unlink the empty default theme into the WordPress install
|
||||
*/
|
||||
function _symlink_default_theme() {
|
||||
_unlink_default_theme();
|
||||
symlink( DIR_TESTDATA . '/themedir1/default', ABSPATH . '/wp-content/themes/default' );
|
||||
}
|
||||
|
||||
function _unlink_default_theme() {
|
||||
if ( file_exists( ABSPATH . '/wp-content/themes/default' ) ) {
|
||||
unlink( ABSPATH . '/wp-content/themes/default' );
|
||||
}
|
||||
}
|
||||
// Only unlink when we're in the main process.
|
||||
if ( 'phpunit' === substr( $GLOBALS['argv'][0], -7 ) ) {
|
||||
register_shutdown_function( '_unlink_default_theme' );
|
||||
}
|
||||
|
@ -31,9 +31,6 @@ class Test_WP_Customize_Control extends WP_UnitTestCase {
|
||||
$GLOBALS['wp_customize'] = new WP_Customize_Manager();
|
||||
// @codingStandardsIgnoreEnd
|
||||
$this->wp_customize = $GLOBALS['wp_customize'];
|
||||
|
||||
// Remove default theme actions that interfere with tests
|
||||
remove_action( 'customize_register', 'twentyseventeen_customize_register' );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -36,9 +36,6 @@ class Test_WP_Customize_Custom_CSS_Setting extends WP_UnitTestCase {
|
||||
$this->wp_customize = new WP_Customize_Manager();
|
||||
$wp_customize = $this->wp_customize;
|
||||
|
||||
// Remove default theme actions that interfere with tests
|
||||
remove_action( 'customize_register', 'twentyseventeen_customize_register' );
|
||||
|
||||
do_action( 'customize_register', $this->wp_customize );
|
||||
$this->setting = new WP_Customize_Custom_CSS_Setting( $this->wp_customize, 'custom_css[twentysixteen]' );
|
||||
$this->wp_customize->add_setting( $this->setting );
|
||||
|
@ -58,9 +58,6 @@ class Tests_WP_Customize_Manager extends WP_UnitTestCase {
|
||||
require_once( ABSPATH . WPINC . '/class-wp-customize-manager.php' );
|
||||
$this->manager = $this->instantiate();
|
||||
$this->undefined = new stdClass();
|
||||
|
||||
// Remove default theme actions that interfere with tests
|
||||
remove_action( 'customize_register', 'twentyseventeen_customize_register' );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -26,9 +26,6 @@ class Test_WP_Customize_Nav_Menu_Item_Setting extends WP_UnitTestCase {
|
||||
global $wp_customize;
|
||||
$this->wp_customize = new WP_Customize_Manager();
|
||||
$wp_customize = $this->wp_customize;
|
||||
|
||||
// Remove default theme actions that interfere with tests
|
||||
remove_action( 'customize_register', 'twentyseventeen_customize_register' );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -27,9 +27,6 @@ class Test_WP_Customize_Nav_Menu_Setting extends WP_UnitTestCase {
|
||||
global $wp_customize;
|
||||
$this->wp_customize = new WP_Customize_Manager();
|
||||
$wp_customize = $this->wp_customize;
|
||||
|
||||
// Remove default theme actions that interfere with tests
|
||||
remove_action( 'customize_register', 'twentyseventeen_customize_register' );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -26,9 +26,6 @@ class Test_WP_Customize_Nav_Menus extends WP_UnitTestCase {
|
||||
global $wp_customize;
|
||||
$this->wp_customize = new WP_Customize_Manager();
|
||||
$wp_customize = $this->wp_customize;
|
||||
|
||||
// Remove default theme actions that interfere with tests
|
||||
remove_action( 'customize_register', 'twentyseventeen_customize_register' );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -39,9 +39,6 @@ class Test_WP_Customize_Partial extends WP_UnitTestCase {
|
||||
if ( isset( $this->wp_customize->selective_refresh ) ) {
|
||||
$this->selective_refresh = $this->wp_customize->selective_refresh;
|
||||
}
|
||||
|
||||
// Remove default theme actions that interfere with tests
|
||||
remove_action( 'customize_register', 'twentyseventeen_customize_register' );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -51,20 +51,12 @@ class Test_WP_Customize_Selective_Refresh_Ajax extends WP_UnitTestCase {
|
||||
if ( isset( $this->wp_customize->selective_refresh ) ) {
|
||||
$this->selective_refresh = $this->wp_customize->selective_refresh;
|
||||
}
|
||||
|
||||
// Remove default theme actions that interfere with tests
|
||||
remove_action( 'customize_register', 'twentyseventeen_customize_register' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Do Customizer boot actions.
|
||||
*/
|
||||
function do_customize_boot_actions() {
|
||||
// Remove actions that call add_theme_support( 'title-tag' ).
|
||||
remove_action( 'after_setup_theme', 'twentyfifteen_setup' );
|
||||
remove_action( 'after_setup_theme', 'twentysixteen_setup' );
|
||||
remove_action( 'after_setup_theme', 'twentyseventeen_setup' );
|
||||
|
||||
$_SERVER['REQUEST_METHOD'] = 'POST';
|
||||
do_action( 'setup_theme' );
|
||||
do_action( 'after_setup_theme' );
|
||||
|
@ -39,9 +39,6 @@ class Test_WP_Customize_Selective_Refresh extends WP_UnitTestCase {
|
||||
if ( isset( $this->wp_customize->selective_refresh ) ) {
|
||||
$this->selective_refresh = $this->wp_customize->selective_refresh;
|
||||
}
|
||||
|
||||
// Remove default theme actions that interfere with tests
|
||||
remove_action( 'customize_register', 'twentyseventeen_customize_register' );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -40,13 +40,6 @@ class Tests_WP_Customize_Widgets extends WP_UnitTestCase {
|
||||
$this->assertArrayHasKey( 2, $widget_categories );
|
||||
$this->assertEquals( '', $widget_categories[2]['title'] );
|
||||
|
||||
// @todo We should not be including a theme anyway
|
||||
remove_action( 'after_setup_theme', 'twentyfifteen_setup' );
|
||||
remove_action( 'after_setup_theme', 'twentysixteen_setup' );
|
||||
remove_action( 'customize_register', 'twentysixteen_customize_register', 11 );
|
||||
remove_action( 'after_setup_theme', 'twentyseventeen_setup' );
|
||||
remove_action( 'customize_register', 'twentyseventeen_customize_register' );
|
||||
|
||||
$this->backup_registered_sidebars = $GLOBALS['wp_registered_sidebars'];
|
||||
|
||||
// Reset protected static var on class.
|
||||
|
@ -33,18 +33,6 @@ CAP;
|
||||
$this->img_url = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . $this->img_name;
|
||||
$this->img_html = '<img src="' . $this->img_url . '"/>';
|
||||
$this->img_meta = array( 'width' => 100, 'height' => 100, 'sizes' => '' );
|
||||
|
||||
// Disable Twenty Seventeen changes to the image size attribute
|
||||
remove_filter( 'wp_calculate_image_sizes', 'twentyseventeen_content_image_sizes_attr' );
|
||||
remove_filter( 'wp_get_attachment_image_attributes', 'twentyseventeen_post_thumbnail_sizes_attr' );
|
||||
}
|
||||
|
||||
function tearDown() {
|
||||
parent::tearDown();
|
||||
|
||||
// Reset Twenty Seventeen behaviour
|
||||
add_filter( 'wp_calculate_image_sizes', 'twentyseventeen_content_image_sizes_attr', 10, 2 );
|
||||
add_filter( 'wp_get_attachment_image_attributes', 'twentyseventeen_post_thumbnail_sizes_attr', 10, 3 );
|
||||
}
|
||||
|
||||
function test_img_caption_shortcode_added() {
|
||||
|
@ -3,6 +3,14 @@
|
||||
/* Path to the WordPress codebase you'd like to test. Add a forward slash in the end. */
|
||||
define( 'ABSPATH', dirname( __FILE__ ) . '/src/' );
|
||||
|
||||
/*
|
||||
* Path to the theme to test with.
|
||||
*
|
||||
* The 'default' theme is symlinked from test/phpunit/data/themedir1/default into
|
||||
* the themes directory of the WordPress install defined above.
|
||||
*/
|
||||
define( 'WP_DEFAULT_THEME', 'default' );
|
||||
|
||||
// Test with multisite enabled.
|
||||
// Alternatively, use the tests/phpunit/multisite.xml configuration file.
|
||||
// define( 'WP_TESTS_MULTISITE', true );
|
||||
|
Loading…
Reference in New Issue
Block a user