Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Aljullu committed Sep 13, 2022
1 parent 97c3b73 commit 442ff41
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<!-- wp:paragraph -->
<p>Custom Single Post template</p>
<!-- /wp:paragraph -->
5 changes: 5 additions & 0 deletions tests/phpunit/data/themedir1/block-theme/theme.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@
{
"name": "page-home",
"title": "Homepage template"
},
{
"name": "custom-single-post-template",
"title": "Custom Single Post template",
"postTypes": ["post"]
}
],
"templateParts": [
Expand Down
39 changes: 39 additions & 0 deletions tests/phpunit/tests/block-template-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/
class Tests_Block_Template_Utils extends WP_UnitTestCase {
private static $post;
private static $custom_single_post_template_post;
private static $template_part_post;
private static $test_theme = 'block-theme';

Expand Down Expand Up @@ -50,6 +51,22 @@ public static function wpSetUpBeforeClass() {
self::$post = self::factory()->post->create_and_get( $args );
wp_set_post_terms( self::$post->ID, self::$test_theme, 'wp_theme' );

// Set up template post.
$args = array(
'post_type' => 'wp_template',
'post_name' => 'custom-single-post-template',
'post_title' => 'Custom Single Post template (modified)',
'post_content' => 'Content',
'post_excerpt' => 'Description of custom single post template',
'tax_input' => array(
'wp_theme' => array(
self::$test_theme,
),
),
);
self::$custom_single_post_template_post = self::factory()->post->create_and_get( $args );
wp_set_post_terms( self::$custom_single_post_template_post->ID, self::$test_theme, 'wp_theme' );

// Set up template part post.
$template_part_args = array(
'post_type' => 'wp_template_part',
Expand Down Expand Up @@ -78,6 +95,7 @@ public function set_up() {

public static function wpTearDownAfterClass() {
wp_delete_post( self::$post->ID );
wp_delete_post( self::$custom_single_post_template_post->ID );
}

public function test_build_block_template_result_from_post() {
Expand Down Expand Up @@ -319,6 +337,27 @@ static function( $template ) {
$template_ids
);
*/

// Filter by post type.
$templates = get_block_templates( array( 'post_type' => 'post' ), 'wp_template' );
$template_ids = get_template_ids( $templates );
$this->assertSame(
array(
get_stylesheet() . '//' . 'my_template',
get_stylesheet() . '//' . 'custom-single-post-template',
),
$template_ids
);

$templates = get_block_templates( array( 'post_type' => 'page' ), 'wp_template' );
$template_ids = get_template_ids( $templates );
$this->assertSame(
array(
get_stylesheet() . '//' . 'my_template',
get_stylesheet() . '//' . 'page-home',
),
$template_ids
);
}

/**
Expand Down
21 changes: 13 additions & 8 deletions tests/phpunit/tests/theme/wpThemeJsonResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,15 @@ public function test_translations_are_applied() {
),
$theme_data->get_settings()
);
$this->assertSameSets(

$custom_templates = $theme_data->get_custom_templates();
$this->assertArrayHasKey( 'page-home', $custom_templates );
$this->assertSame(
$custom_templates['page-home'],
array(
'page-home' => array(
'title' => 'Szablon strony głównej',
'postTypes' => array( 'page' ),
),
),
$theme_data->get_custom_templates()
'title' => 'Szablon strony głównej',
'postTypes' => array( 'page' ),
)
);
$this->assertSameSets(
array(
Expand Down Expand Up @@ -340,10 +341,14 @@ function test_merges_child_theme_json_into_parent_theme_json() {
$this->assertSame(
WP_Theme_JSON_Resolver::get_theme_data()->get_custom_templates(),
array(
'page-home' => array(
'page-home' => array(
'title' => 'Homepage',
'postTypes' => array( 'page' ),
),
'custom-single-post-template' => array(
'title' => 'Custom Single Post template',
'postTypes' => array( 'post' ),
),
)
);
}
Expand Down

0 comments on commit 442ff41

Please sign in to comment.