Tests: Improve tests for wp_get_post_parent_id()
added in [42397].
Props frank-klein. Fixes #42797. git-svn-id: https://develop.svn.wordpress.org/trunk@42635 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
534f096302
commit
07bff5d8bd
@ -4,39 +4,47 @@
|
|||||||
* @group post
|
* @group post
|
||||||
*/
|
*/
|
||||||
class Tests_Post_WpGetPostParentId extends WP_UnitTestCase {
|
class Tests_Post_WpGetPostParentId extends WP_UnitTestCase {
|
||||||
|
/**
|
||||||
|
* Parent post ID.
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
public static $parent_post_id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Post ID.
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
public static $post_id;
|
||||||
|
|
||||||
|
public static function wpSetUpBeforeClass() {
|
||||||
|
self::$parent_post_id = self::factory()->post->create();
|
||||||
|
self::$post_id = self::factory()->post->create( array( 'post_parent' => self::$parent_post_id ) );
|
||||||
|
}
|
||||||
|
|
||||||
public function test_wp_get_post_parent_id_with_post_object() {
|
public function test_wp_get_post_parent_id_with_post_object() {
|
||||||
$p1 = self::factory()->post->create();
|
$post = get_post( self::$post_id );
|
||||||
$p2 = self::factory()->post->create( array( 'post_parent' => $p1 ) );
|
$this->assertInstanceOf( 'WP_Post', $post );
|
||||||
$post = get_post( $p2 );
|
$this->assertSame( self::$parent_post_id, wp_get_post_parent_id( $post ) );
|
||||||
$this->assertTrue( $post instanceof WP_Post );
|
|
||||||
$this->assertEquals( $p1, wp_get_post_parent_id( $post ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_wp_get_post_parent_id_with_post_id() {
|
public function test_wp_get_post_parent_id_with_post_id() {
|
||||||
$p1 = self::factory()->post->create();
|
$this->assertSame( self::$parent_post_id, wp_get_post_parent_id( self::$post_id ) );
|
||||||
$p2 = self::factory()->post->create( array( 'post_parent' => $p1 ) );
|
|
||||||
$this->assertEquals( $p1, wp_get_post_parent_id( $p2 ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_wp_get_post_parent_id_with_non_existing_id_default_to_global_post_id() {
|
public function test_wp_get_post_parent_id_with_non_existing_id_default_to_global_post_id() {
|
||||||
$p1 = self::factory()->post->create();
|
$GLOBALS['post'] = get_post( self::$post_id );
|
||||||
$GLOBALS['post'] = self::factory()->post->create( array( 'post_parent' => $p1 ) );
|
$this->assertSame( self::$parent_post_id, wp_get_post_parent_id( 0 ) );
|
||||||
$this->assertEquals( $p1, wp_get_post_parent_id( 0 ) );
|
|
||||||
unset( $GLOBALS['post'] );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_wp_get_post_parent_id_with_boolean_default_to_global_post_id() {
|
public function test_wp_get_post_parent_id_with_boolean_default_to_global_post_id() {
|
||||||
$p1 = self::factory()->post->create();
|
$GLOBALS['post'] = get_post( self::$post_id );
|
||||||
$GLOBALS['post'] = self::factory()->post->create( array( 'post_parent' => $p1 ) );
|
$this->assertSame( self::$parent_post_id, wp_get_post_parent_id( false ) );
|
||||||
$this->assertEquals( $p1, wp_get_post_parent_id( false ) );
|
|
||||||
unset( $GLOBALS['post'] );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_wp_get_post_parent_id_with_string_default_to_false() {
|
public function test_wp_get_post_parent_id_with_string_default_to_false() {
|
||||||
$p1 = self::factory()->post->create();
|
$GLOBALS['post'] = get_post( self::$post_id );
|
||||||
$GLOBALS['post'] = self::factory()->post->create( array( 'post_parent' => $p1 ) );
|
|
||||||
$this->assertFalse( wp_get_post_parent_id( 'string' ) );
|
$this->assertFalse( wp_get_post_parent_id( 'string' ) );
|
||||||
unset( $GLOBALS['post'] );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user