Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
joemcgill committed Nov 10, 2023
1 parent d62a213 commit f823bcd
Show file tree
Hide file tree
Showing 7 changed files with 166 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tests/phpunit/data/themedir2/test-parent/functions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

// Dummy theme.

echo __DIR__ . '/' . basename(__FILE__);

?>
7 changes: 7 additions & 0 deletions tests/phpunit/data/themedir2/test-parent/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

// Dummy theme.

echo __DIR__ . '/' . basename(__FILE__);

?>
12 changes: 12 additions & 0 deletions tests/phpunit/data/themedir2/test-parent/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
Theme Name: Test Parent Theme
Theme URI: http://example.org/
Description: An example parent theme
Version: 1.3
Author: Minnie Bannister
Author URI: http://example.com/
Template: test-parent
*/



7 changes: 7 additions & 0 deletions tests/phpunit/data/themedir2/test/functions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

// Dummy theme.

echo __DIR__ . '/' . basename(__FILE__);

?>
7 changes: 7 additions & 0 deletions tests/phpunit/data/themedir2/test/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

// Dummy theme.

echo __DIR__ . '/' . basename(__FILE__);

?>
12 changes: 12 additions & 0 deletions tests/phpunit/data/themedir2/test/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
Theme Name: Test Theme
Theme URI: http://example.org/
Description: An example theme
Version: 1.3
Author: Minnie Bannister
Author URI: http://example.com/
Template: test-parent
*/



114 changes: 114 additions & 0 deletions tests/phpunit/tests/theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -1179,4 +1179,118 @@ private function helper_requires_block_theme() {
$this->markTestSkipped( "Could not switch to $block_theme." );
}
}

/**
* Make sure filters added after the initial call are fired.
*
* @ticket 59847
*/
public function test_get_stylesheet_directory_filters_apply() {
// Call the function prior to the filter being added.
get_stylesheet_directory();

$expected = 'test_root/dir';

// Add the filer.
add_filter(
'stylesheet_directory',
function () use ( $expected ) {
return $expected;
}
);

$this->assertSame( $expected, get_stylesheet_directory() );
}

/**
* Make sure filters added after the initial call are fired.
*
* @ticket 59847
*/
public function test_get_template_directory_filters_apply() {
// Call the function prior to the filter being added.
get_template_directory();

$expected = 'test_root/dir';

// Add the filer.
add_filter(
'template_directory',
function () use ( $expected ) {
return $expected;
}
);

$this->assertSame( $expected, get_template_directory() );
}

/**
* @ticket 59847
*/
public function test_get_stylesheet_directory_uses_registered_theme_dir() {
$old_theme = wp_get_theme();

switch_theme( 'test' );

$old_root = get_theme_root( 'test' );
$path1 = get_stylesheet_directory();

$new_root = DIR_TESTDATA . '/themedir2';
register_theme_directory( $new_root );

// Mock the stylesheet root option to mimic that the active root has changed.
add_filter(
'pre_option_stylesheet_root',
function () use ( $new_root ) {
return $new_root;
}
);

$path2 = get_stylesheet_directory();

// Cleanup.
switch_theme( $old_theme->get_stylesheet() );

$this->assertEquals( $old_root . '/test', $path1, 'The original stylesheet path is not correct' );
$this->assertEquals( $new_root . '/test', $path2, 'The new stylesheet path is not correct' );
}

/**
* @ticket 59847
*/
public function test_get_template_directory_uses_registered_theme_dir() {
$old_theme = wp_get_theme();

switch_theme( 'test' );

// Mock parent theme to be returned as the template.
add_filter(
'pre_option_template',
function () {
return 'test-parent';
}
);

$old_root = get_theme_root( 'test' );
$path1 = get_template_directory();

$new_root = DIR_TESTDATA . '/themedir2';
register_theme_directory( $new_root );

// Mock the template root option to mimic that the active root has changed.
add_filter(
'pre_option_template_root',
function () use ( $new_root ) {
return $new_root;
}
);

$path2 = get_template_directory();

// Cleanup.
switch_theme( $old_theme->get_stylesheet() );

$this->assertEquals( $old_root . '/test-parent', $path1, 'The original template path is not correct' );
$this->assertEquals( $new_root . '/test-parent', $path2, 'The new template path is not correct' );
}
}

0 comments on commit f823bcd

Please sign in to comment.