Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Aljullu committed Sep 9, 2022
1 parent 551eeaf commit b86a12f
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 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 @@ -59,6 +59,11 @@
{
"name": "page-home",
"title": "Homepage template"
},
{
"name": "custom-single-post-template",
"title": "Custom Single Post template",
"postTypes": ["post"]
}
],
"templateParts": [
Expand Down
38 changes: 38 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 @@ -319,6 +336,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
8 changes: 8 additions & 0 deletions tests/phpunit/tests/theme/wpThemeJsonResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ public function test_translations_are_applied() {
'title' => 'Szablon strony głównej',
'postTypes' => array( 'page' ),
),
'custom-single-post-template' => array(
'title' => 'Custom Single Post template',
'postTypes' => array( 'post' ),
),
)
);
$this->assertSame(
Expand Down Expand Up @@ -338,6 +342,10 @@ function test_merges_child_theme_json_into_parent_theme_json() {
'title' => 'Homepage',
'postTypes' => array( 'page' ),
),
'custom-single-post-template' => array(
'title' => 'Custom Single Post template',
'postTypes' => array( 'post' ),
),
)
);
}
Expand Down

0 comments on commit b86a12f

Please sign in to comment.