WordPress.org

Make WordPress Core

Opened 2 years ago

Closed 10 months ago

Last modified 6 months ago

#31550 closed defect (bug) (fixed)

Use an empty theme for WP_DEFAULT_THEME during unit tests

Reported by: westonruter Owned by: pento
Milestone: 4.7 Priority: normal
Severity: normal Version:
Component: Build/Test Tools Keywords:
Focuses: Cc:

Description (last modified by westonruter)

Assertions for unit tests in Core should not have any interference from the current default theme, but this is not currently the case.

In the customize/widgets unit test, I had to add:

<?php
remove_action( 'after_setup_theme', 'twentyfifteen_setup' );

This was needed because Twenty Fifteen's actions modified what the unit test was expecting. This will be a recurring problem every time a new default theme is introduced, where the unit tests will have to be update their assertions to take into account the new default theme.

The default theme loaded when unit testing should be empty, without any filter/action additions.

I suggest that the PHPUnit bootstrap perhaps copy (symlink?) the tests/phpunit/data/themedir1/default theme directory into the wp-content/themes directory (or filter the theme_root), and then let the wp-tests-config.php include:

<?php
define( 'WP_DEFAULT_THEME', 'default' );

Or the WP_DEFAULT_THEME constant could be set as thus in default-constants.php when WP detects the unit tests are being run:

<?php
define( 'WP_DEFAULT_THEME', defined( 'WP_RUN_CORE_TESTS' ) ? 'default' : 'twentyfifteen' );

Change History (15)

#1 @westonruter
2 years ago

  • Description modified (diff)

#2 @westonruter
21 months ago

  • Description modified (diff)

#3 @joemcgill
21 months ago

While I am in support of this change, it's possible that some tests will need to be modified if they were expecting interaction from the theme.

Related: #34790

#4 @wonderboymusic
21 months ago

In 35754:

Customize Unit Tests: also remove_action( 'after_setup_theme', 'twentysixteen_setup' ). TwentyFifteen is already removed.

See #31550.

This ticket was mentioned in Slack in #core by westonruter. View the logs.


10 months ago

#6 @pento
10 months ago

  • Owner set to pento
  • Status changed from new to assigned

#7 @pento
10 months ago

  • Milestone changed from Awaiting Review to 4.7

#8 @pento
10 months ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 38858:

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.

#9 @pento
10 months ago

In 38907:

Tests: Use a minimal theme for tests.

This functionality was originally added in [38858], using symlink() to put a link to the theme in WordPress' themes directory. Unfortunately, not all installs have write access to the themes directory, causing unit tests to fail.

The new method is to add the test theme directory to $wp_theme_directories, and fix the handful of tests that don't expect $wp_theme_directories to have multiple entries.

The test install/bootstrap routines now also check that WP_DEFAULT_THEME is defined, in case the tests are being run on a system that hasn't upgraded its' wp-tests-config.php.

See #31550.
Fixes #38457.

#10 @pento
10 months ago

In 38908:

Tests: Fix a PHP notice introduced in [38907].

WP_DEFAULT_THEME was being defined in the wrong location.

Also, if WordPress has the original "default" theme installed, ensure that our test theme overrides it.

Props swissspidy for daring to dive into Themes of WordPress Past.
See #31550, #38457.

#11 @dd32
10 months ago

In 39065:

Themes: Update the unit tests to handle [39064] and #31550.

test_default_theme_in_default_theme_list() was always being skipped after #31550, this causes it to once again check that the unit tests are up to date and include the latest default theme.
test_default_themes_have_textdomain() didn't play happy when a default theme wasn't installed on a site.

See #31550, #29925, #38551.

#12 @swissspidy
10 months ago

Still getting some _doing_it_wrong() notices (at least locally) when running multisite tests and https://wordpress.org/themes/default/ is installed in ⁠⁠⁠⁠wp-content/themes⁠⁠⁠⁠. Not sure how big of an issue this is, but I thought I'd mention it here.

Notice: register_sidebar was called <strong>incorrectly</strong>. No <code>id</code> was set in the arguments array for the "Sidebar 1" sidebar. Defaulting to "sidebar-1".

#14 @johnbillion
6 months ago

In 40235:

Build/Test Tools: Call wp_head() and wp_footer() in the theme used during tests.

See #31550
Fixes #39988

#15 @johnbillion
6 months ago

In 40236:

Build/Test Tools: Call wp_head() and wp_footer() in the theme used during tests.

See #31550
Fixes #39988

Merges [40235] to the 4.7 branch.

Note: See TracTickets for help on using tickets.