wordpress-develop/tests/phpunit/tests/post/getPageTemplateSlug.php
Sergey Biryukov 561287c861 Tests: Split the tests from post/template.php into individual test classes.
This aims to bring some consistency to the location of post template function tests, as well as to make the tests more discoverable and easier to expand.

Includes:
* Adding `@covers` tags.
* Renaming `get_post_parent()` and `has_post_parent()` tests to match the names of the functions.

Follow-up to [28398], [31522], [34654], [34950], [50127], [50396], [54717], [54726], [55590].

See #57841.

git-svn-id: https://develop.svn.wordpress.org/trunk@55591 602fd350-edb4-49c9-b593-d223f7449a82
2023-03-24 17:10:44 +00:00

76 lines
1.8 KiB
PHP

<?php
/**
* @group post
* @group template
*
* @covers ::get_page_template_slug
*/
class Tests_Post_GetPageTemplateSlug extends WP_UnitTestCase {
/**
* @ticket 31389
*/
public function test_get_page_template_slug_by_id() {
$page_id = self::factory()->post->create(
array(
'post_type' => 'page',
)
);
$this->assertSame( '', get_page_template_slug( $page_id ) );
update_post_meta( $page_id, '_wp_page_template', 'default' );
$this->assertSame( '', get_page_template_slug( $page_id ) );
update_post_meta( $page_id, '_wp_page_template', 'example.php' );
$this->assertSame( 'example.php', get_page_template_slug( $page_id ) );
}
/**
* @ticket 31389
*/
public function test_get_page_template_slug_from_loop() {
$page_id = self::factory()->post->create(
array(
'post_type' => 'page',
)
);
update_post_meta( $page_id, '_wp_page_template', 'example.php' );
$this->go_to( get_permalink( $page_id ) );
$this->assertSame( 'example.php', get_page_template_slug() );
}
/**
* @ticket 31389
* @ticket 18375
*/
public function test_get_page_template_slug_non_page() {
$post_id = self::factory()->post->create();
$this->assertSame( '', get_page_template_slug( $post_id ) );
update_post_meta( $post_id, '_wp_page_template', 'default' );
$this->assertSame( '', get_page_template_slug( $post_id ) );
update_post_meta( $post_id, '_wp_page_template', 'example.php' );
$this->assertSame( 'example.php', get_page_template_slug( $post_id ) );
}
/**
* @ticket 18375
*/
public function test_get_page_template_slug_non_page_from_loop() {
$post_id = self::factory()->post->create();
update_post_meta( $post_id, '_wp_page_template', 'example.php' );
$this->go_to( get_permalink( $post_id ) );
$this->assertSame( 'example.php', get_page_template_slug() );
}
}