#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 )
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)
This ticket was mentioned in Slack in #core by westonruter. View the logs.
8 years ago
#12
@
8 years 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".
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