Changeset 42635
- Timestamp:
- 02/01/2018 04:02:26 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/post/wpGetPostParentId.php
r42397 r42635 5 5 */ 6 6 class Tests_Post_WpGetPostParentId extends WP_UnitTestCase { 7 /** 8 * Parent post ID. 9 * 10 * @var int 11 */ 12 public static $parent_post_id; 13 14 /** 15 * Post ID. 16 * 17 * @var int 18 */ 19 public static $post_id; 20 21 public static function wpSetUpBeforeClass() { 22 self::$parent_post_id = self::factory()->post->create(); 23 self::$post_id = self::factory()->post->create( array( 'post_parent' => self::$parent_post_id ) ); 24 } 7 25 8 26 public function test_wp_get_post_parent_id_with_post_object() { 9 $p1 = self::factory()->post->create(); 10 $p2 = self::factory()->post->create( array( 'post_parent' => $p1 ) ); 11 $post = get_post( $p2 ); 12 $this->assertTrue( $post instanceof WP_Post ); 13 $this->assertEquals( $p1, wp_get_post_parent_id( $post ) ); 27 $post = get_post( self::$post_id ); 28 $this->assertInstanceOf( 'WP_Post', $post ); 29 $this->assertSame( self::$parent_post_id, wp_get_post_parent_id( $post ) ); 14 30 } 15 31 16 32 public function test_wp_get_post_parent_id_with_post_id() { 17 $p1 = self::factory()->post->create(); 18 $p2 = self::factory()->post->create( array( 'post_parent' => $p1 ) ); 19 $this->assertEquals( $p1, wp_get_post_parent_id( $p2 ) ); 33 $this->assertSame( self::$parent_post_id, wp_get_post_parent_id( self::$post_id ) ); 20 34 } 21 35 22 36 public function test_wp_get_post_parent_id_with_non_existing_id_default_to_global_post_id() { 23 $p1 = self::factory()->post->create(); 24 $GLOBALS['post'] = self::factory()->post->create( array( 'post_parent' => $p1 ) ); 25 $this->assertEquals( $p1, wp_get_post_parent_id( 0 ) ); 26 unset( $GLOBALS['post'] ); 37 $GLOBALS['post'] = get_post( self::$post_id ); 38 $this->assertSame( self::$parent_post_id, wp_get_post_parent_id( 0 ) ); 27 39 } 28 40 29 41 public function test_wp_get_post_parent_id_with_boolean_default_to_global_post_id() { 30 $p1 = self::factory()->post->create(); 31 $GLOBALS['post'] = self::factory()->post->create( array( 'post_parent' => $p1 ) ); 32 $this->assertEquals( $p1, wp_get_post_parent_id( false ) ); 33 unset( $GLOBALS['post'] ); 42 $GLOBALS['post'] = get_post( self::$post_id ); 43 $this->assertSame( self::$parent_post_id, wp_get_post_parent_id( false ) ); 34 44 } 35 45 36 46 public function test_wp_get_post_parent_id_with_string_default_to_false() { 37 $p1 = self::factory()->post->create(); 38 $GLOBALS['post'] = self::factory()->post->create( array( 'post_parent' => $p1 ) ); 47 $GLOBALS['post'] = get_post( self::$post_id ); 39 48 $this->assertFalse( wp_get_post_parent_id( 'string' ) ); 40 unset( $GLOBALS['post'] );41 49 } 42 50 }
Note: See TracChangeset
for help on using the changeset viewer.