From 9ae7287702f78182a49da88b8a920817d82798cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9?= <583546+oandregal@users.noreply.github.com> Date: Wed, 26 Oct 2022 17:14:10 +0200 Subject: [PATCH] Better coverage for all use cases --- .../block-theme-child-no-theme-json/style.css | 8 +++ .../default-child-no-theme-json/style.css | 8 +++ phpunit/wp-theme-json-test.php | 65 ++++++++++++++++--- 3 files changed, 73 insertions(+), 8 deletions(-) create mode 100644 phpunit/data/themedir1/block-theme-child-no-theme-json/style.css create mode 100644 phpunit/data/themedir1/default-child-no-theme-json/style.css diff --git a/phpunit/data/themedir1/block-theme-child-no-theme-json/style.css b/phpunit/data/themedir1/block-theme-child-no-theme-json/style.css new file mode 100644 index 00000000000000..344441288258ec --- /dev/null +++ b/phpunit/data/themedir1/block-theme-child-no-theme-json/style.css @@ -0,0 +1,8 @@ +/* +Theme Name: Block Theme Child with no theme.json +Theme URI: https://wordpress.org/ +Description: For testing purposes only. +Template: block-theme +Version: 1.0.0 +Text Domain: block-theme-child-no-theme-json +*/ diff --git a/phpunit/data/themedir1/default-child-no-theme-json/style.css b/phpunit/data/themedir1/default-child-no-theme-json/style.css new file mode 100644 index 00000000000000..8f971990d9fec0 --- /dev/null +++ b/phpunit/data/themedir1/default-child-no-theme-json/style.css @@ -0,0 +1,8 @@ +/* +Theme Name: Default Child Theme with no theme.json +Theme URI: https://wordpress.org/ +Description: For testing purposes only. +Template: default +Version: 1.0.0 +Text Domain: default-child-no-theme-json +*/ diff --git a/phpunit/wp-theme-json-test.php b/phpunit/wp-theme-json-test.php index c654e930d710a6..dbbe8a18841457 100644 --- a/phpunit/wp-theme-json-test.php +++ b/phpunit/wp-theme-json-test.php @@ -7,16 +7,66 @@ class WP_Theme_Json_Test extends WP_UnitTestCase { + /** + * Test that it reports correctly themes that have a theme.json. + * + * @group theme_json + * + * @covers wp_theme_has_theme_json + */ public function test_theme_has_theme_json() { - $this->assertSame( true, false ); + switch_theme( 'block-theme' ); + $this->assertTrue( wp_theme_has_theme_json() ); + } + + /** + * Test that it reports correctly themes that do not have a theme.json. + * + * @group theme_json + * + * @covers wp_theme_has_theme_json + */ + public function test_theme_has_no_theme_json() { + switch_theme( 'default' ); + $this->assertFalse( wp_theme_has_theme_json() ); + } + + /** + * Test it reports correctly child themes that have a theme.json. + * + * @group theme_json + * + * @covers wp_theme_has_theme_json + */ + public function test_child_theme_has_theme_json() { + switch_theme( 'block-theme-child' ); + $this->assertTrue( wp_theme_has_theme_json() ); } - public function test_theme_and_parent_do_not_have_theme_json() { - $this->assertSame( true, false ); + /** + * Test that it reports correctly child themes that do not have a theme.json + * and the parent does. + * + * @group theme_json + * + * @covers wp_theme_has_theme_json + */ + public function test_child_theme_has_not_theme_json_but_parent_has() { + switch_theme( 'block-theme-child-no-theme-json' ); + $this->assertTrue( wp_theme_has_theme_json() ); } - public function test_theme_has_not_theme_json_but_parent_has() { - $this->assertSame( true, false ); + /** + * Test that it reports correctly child themes that do not have a theme.json + * and the parent does not either. + * + * @group theme_json + * + * @covers wp_theme_has_theme_json + */ + public function test_neither_child_or_parent_themes_have_theme_json() { + switch_theme( 'default-child-no-theme-json' ); + $this->assertFalse( wp_theme_has_theme_json() ); } /** @@ -33,10 +83,9 @@ public function test_switching_themes_recalculates_support() { // Switch to a theme that does have support. switch_theme( 'block-theme' ); - $has_theme_json_support = wp_theme_has_theme_json(); + $block_theme = wp_theme_has_theme_json(); - $this->assertSame( true, false ); $this->assertFalse( $default ); - $this->assertTrue( $has_theme_json_support ); + $this->assertTrue( $block_theme ); } }