Skip to content

Commit

Permalink
Better coverage for all use cases
Browse files Browse the repository at this point in the history
  • Loading branch information
oandregal committed Oct 26, 2022
1 parent 78a4d41 commit 9ae7287
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -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
*/
8 changes: 8 additions & 0 deletions phpunit/data/themedir1/default-child-no-theme-json/style.css
Original file line number Diff line number Diff line change
@@ -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
*/
65 changes: 57 additions & 8 deletions phpunit/wp-theme-json-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() );
}

/**
Expand All @@ -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 );
}
}

0 comments on commit 9ae7287

Please sign in to comment.