Make WordPress Core

Changeset 38858


Ignore:
Timestamp:
10/21/2016 11:02:37 AM (8 years ago)
Author:
pento
Message:

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.

Location:
trunk
Files:
1 added
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/data/themedir1/default/functions.php

    r25002 r38858  
    11<?php
    22
    3 // dummy theme
     3// Minimum functions.php to pass unit tests
    44
    5 echo dirname(__FILE__).'/'.basename(__FILE__);
     5function default_widgets_init() {
     6    register_sidebar( array( 'id' => 'sidebar-1' ) );
     7}
     8add_action( 'widgets_init', 'default_widgets_init' );
    69
    7 ?>
     10function 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}
     18add_action( 'after_setup_theme', 'default_after_setup_theme' );
  • trunk/tests/phpunit/data/themedir1/default/index.php

    r25002 r38858  
    11<?php
    22
    3 // dummy theme
    4 
    5 echo dirname(__FILE__).'/'.basename(__FILE__);
    6 
    7 ?>
     3// Empty theme
  • trunk/tests/phpunit/includes/bootstrap.php

    r38840 r38858  
    5353require_once( dirname( __FILE__ ) . '/mock-mailer.php' );
    5454$phpmailer = new MockPHPMailer();
     55
     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();
    5558
    5659system( WP_PHP_BINARY . ' ' . escapeshellarg( dirname( __FILE__ ) . '/install.php' ) . ' ' . escapeshellarg( $config_file_path ) . ' ' . $multisite );
  • trunk/tests/phpunit/includes/functions.php

    r38582 r38858  
    162162    return $uploads;
    163163}
     164
     165/**
     166 * Helper functions to link and unlink the empty default theme into the WordPress install
     167 */
     168function _symlink_default_theme() {
     169    _unlink_default_theme();
     170    symlink( DIR_TESTDATA . '/themedir1/default', ABSPATH . '/wp-content/themes/default' );
     171}
     172
     173function _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.
     179if ( 'phpunit' === substr( $GLOBALS['argv'][0], -7 ) ) {
     180    register_shutdown_function( '_unlink_default_theme' );
     181}
  • trunk/tests/phpunit/tests/customize/control.php

    r38850 r38858  
    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
  • trunk/tests/phpunit/tests/customize/custom-css-setting.php

    r38850 r38858  
    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]' );
  • trunk/tests/phpunit/tests/customize/manager.php

    r38850 r38858  
    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
  • trunk/tests/phpunit/tests/customize/nav-menu-item-setting.php

    r38850 r38858  
    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
  • trunk/tests/phpunit/tests/customize/nav-menu-setting.php

    r38850 r38858  
    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
  • trunk/tests/phpunit/tests/customize/nav-menus.php

    r38850 r38858  
    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
  • trunk/tests/phpunit/tests/customize/partial.php

    r38850 r38858  
    4040            $this->selective_refresh = $this->wp_customize->selective_refresh;
    4141        }
    42 
    43         // Remove default theme actions that interfere with tests
    44         remove_action( 'customize_register', 'twentyseventeen_customize_register' );
    4542    }
    4643
  • trunk/tests/phpunit/tests/customize/selective-refresh-ajax.php

    r38851 r38858  
    5252            $this->selective_refresh = $this->wp_customize->selective_refresh;
    5353        }
    54 
    55         // Remove default theme actions that interfere with tests
    56         remove_action( 'customize_register', 'twentyseventeen_customize_register' );
    5754    }
    5855
     
    6158     */
    6259    function do_customize_boot_actions() {
    63         // Remove actions that call add_theme_support( 'title-tag' ).
    64         remove_action( 'after_setup_theme', 'twentyfifteen_setup' );
    65         remove_action( 'after_setup_theme', 'twentysixteen_setup' );
    66         remove_action( 'after_setup_theme', 'twentyseventeen_setup' );
    67 
    6860        $_SERVER['REQUEST_METHOD'] = 'POST';
    6961        do_action( 'setup_theme' );
  • trunk/tests/phpunit/tests/customize/selective-refresh.php

    r38850 r38858  
    4040            $this->selective_refresh = $this->wp_customize->selective_refresh;
    4141        }
    42 
    43         // Remove default theme actions that interfere with tests
    44         remove_action( 'customize_register', 'twentyseventeen_customize_register' );
    4542    }
    4643
  • trunk/tests/phpunit/tests/customize/widgets.php

    r38850 r38858  
    4040        $this->assertArrayHasKey( 2, $widget_categories );
    4141        $this->assertEquals( '', $widget_categories[2]['title'] );
    42 
    43         // @todo We should not be including a theme anyway
    44         remove_action( 'after_setup_theme', 'twentyfifteen_setup' );
    45         remove_action( 'after_setup_theme', 'twentysixteen_setup' );
    46         remove_action( 'customize_register', 'twentysixteen_customize_register', 11 );
    47         remove_action( 'after_setup_theme', 'twentyseventeen_setup' );
    48         remove_action( 'customize_register', 'twentyseventeen_customize_register' );
    4942
    5043        $this->backup_registered_sidebars = $GLOBALS['wp_registered_sidebars'];
  • trunk/tests/phpunit/tests/media.php

    r38838 r38858  
    3434        $this->img_html = '<img src="' . $this->img_url . '"/>';
    3535        $this->img_meta = array( 'width' => 100, 'height' => 100, 'sizes' => '' );
    36 
    37         // Disable Twenty Seventeen changes to the image size attribute
    38         remove_filter( 'wp_calculate_image_sizes', 'twentyseventeen_content_image_sizes_attr' );
    39         remove_filter( 'wp_get_attachment_image_attributes', 'twentyseventeen_post_thumbnail_sizes_attr' );
    40     }
    41 
    42     function tearDown() {
    43         parent::tearDown();
    44 
    45         // Reset Twenty Seventeen behaviour
    46         add_filter( 'wp_calculate_image_sizes', 'twentyseventeen_content_image_sizes_attr', 10, 2 );
    47         add_filter( 'wp_get_attachment_image_attributes', 'twentyseventeen_post_thumbnail_sizes_attr', 10, 3 );
    4836    }
    4937
  • trunk/wp-tests-config-sample.php

    r36372 r38858  
    33/* Path to the WordPress codebase you'd like to test. Add a forward slash in the end. */
    44define( 'ABSPATH', dirname( __FILE__ ) . '/src/' );
     5
     6/*
     7 * Path to the theme to test with.
     8 *
     9 * The 'default' theme is symlinked from test/phpunit/data/themedir1/default into
     10 * the themes directory of the WordPress install defined above.
     11 */
     12define( 'WP_DEFAULT_THEME', 'default' );
    513
    614// Test with multisite enabled.
Note: See TracChangeset for help on using the changeset viewer.