Skip to content

Commit 023d3c4

Browse files
committed
Tests/Build Tools: Improve tests for bundled themes.
Introduce two new tests relating to bundled themes: 1. Ensure the list of tested themes matches the list of themes defined in `WP_Theme` 2. Ensure the run time value of `WP_DEFAULT_THEME` is included in the list of themes defined in `WP_Theme` See #61530. git-svn-id: https://develop.svn.wordpress.org/trunk@59186 602fd350-edb4-49c9-b593-d223f7449a82
1 parent ce9c8d2 commit 023d3c4

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

tests/phpunit/tests/theme.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,44 @@ public function test_default_theme_in_default_theme_list() {
212212
$this->assertContains( $latest_default_theme->get_stylesheet(), $this->default_themes );
213213
}
214214

215+
/**
216+
* Tests the default themes list in the test suite matches the runtime default themes.
217+
*/
218+
public function test_default_default_theme_list_match_in_test_suite_and_at_runtime() {
219+
// Use a reflection to make WP_THEME::$default_themes accessible.
220+
$reflection = new ReflectionClass( 'WP_Theme' );
221+
$property = $reflection->getProperty( 'default_themes' );
222+
$property->setAccessible( true );
223+
224+
/*
225+
* `default` and `classic` are included in `WP_Theme::$default_themes` but not included
226+
* in the test suite default themes list. These are excluded from the comparison.
227+
*/
228+
$default_themes = array_keys( $property->getValue() );
229+
$default_themes = array_diff( $default_themes, array( 'default', 'classic' ) );
230+
231+
$this->assertSameSets( $default_themes, $this->default_themes, 'Test suite default themes should match the runtime default themes.' );
232+
}
233+
234+
/**
235+
* Test the default theme in WP_Theme matches the WP_DEFAULT_THEME constant.
236+
*/
237+
public function test_default_theme_matches_constant() {
238+
$latest_default_theme = WP_Theme::get_core_default_theme();
239+
240+
/*
241+
* The test suite sets the constant to `default` while this is intended to
242+
* test the value defined in default-constants.php.
243+
*
244+
* Therefore this reads the file in via file_get_contents to extract the value.
245+
*/
246+
$default_constants = file_get_contents( ABSPATH . WPINC . '/default-constants.php' );
247+
preg_match( '/define\( \'WP_DEFAULT_THEME\', \'(.*)\' \);/', $default_constants, $matches );
248+
$wp_default_theme_constant = $matches[1];
249+
250+
$this->assertSame( $wp_default_theme_constant, $latest_default_theme->get_stylesheet(), 'WP_DEFAULT_THEME should match the latest default theme.' );
251+
}
252+
215253
public function test_default_themes_have_textdomain() {
216254
foreach ( $this->default_themes as $theme ) {
217255
if ( wp_get_theme( $theme )->exists() ) {

0 commit comments

Comments
 (0)