Skip to content

Commit

Permalink
Add basic test coverage for gutenberg_get_block_template_type_for_slug
Browse files Browse the repository at this point in the history
  • Loading branch information
ockham committed Jun 27, 2022
1 parent d1ee1f7 commit e0ff8b5
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions phpunit/compat/wordpress-6.1/block-template-utils-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,23 @@
* @group block-templates
*/
class Tests_Block_Template_Utils_6_1 extends WP_UnitTestCase {
private static $post;

public static function wpSetUpBeforeClass() {
$args = array(
'post_type' => 'post',
'post_name' => 'hello-world',
'post_title' => 'Hello World!',
'post_content' => 'Welcome to WordPress. This is your first post. Edit or delete it, then start writing!',
'post_excerpt' => 'Welcome to WordPress.',
);
self::$post = self::factory()->post->create_and_get( $args );
}

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

public function test_get_template_slugs() {
$templates = gutenberg_get_template_slugs( 'single-post-hello-world' );
$this->assertSame(
Expand All @@ -23,4 +40,16 @@ public function test_get_template_slugs() {
$templates
);
}

public function test_gutenberg_get_block_template_type_for_slug() {
$template_slug = 'single-' . self::$post->post_type . '-' . self::$post->post_name;
$template_info = gutenberg_get_block_template_type_for_slug( $template_slug );
$this->assertSame(
array(
'title' => 'Post: Hello World!',
'description' => 'Template for Post: Hello World!',
),
$template_info
);
}
}

0 comments on commit e0ff8b5

Please sign in to comment.