WordPress.org

Make WordPress Core

Ticket #48358: 48358.1.diff

File 48358.1.diff, 1.6 KB (added by danielpost, 11 months ago)

Adds test

  • src/wp-includes/post.php

    diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php
    index deb215e17d..f621f456ba 100644
    a b function _publish_post_hook( $post_id ) { 
    68216821 *
    68226822 * @since 3.1.0
    68236823 *
    6824  * @param int|WP_Post $post Post ID or post object. Defaults to global $post.
     6824 * @param int|WP_Post|null $post Optional. Post ID or post object. Defaults to global $post.
    68256825 * @return int|false Post parent ID (which can be 0 if there is no parent), or false if the post does not exist.
    68266826 */
    6827 function wp_get_post_parent_id( $post ) {
     6827function wp_get_post_parent_id( $post = null ) {
    68286828        $post = get_post( $post );
    68296829        if ( ! $post || is_wp_error( $post ) ) {
    68306830                return false;
  • tests/phpunit/tests/post/wpGetPostParentId.php

    diff --git a/tests/phpunit/tests/post/wpGetPostParentId.php b/tests/phpunit/tests/post/wpGetPostParentId.php
    index fe6eacde38..6906eddcd9 100644
    a b class Tests_Post_WpGetPostParentId extends WP_UnitTestCase { 
    3333                $this->assertSame( self::$parent_post_id, wp_get_post_parent_id( self::$post_id ) );
    3434        }
    3535
     36        public function test_wp_get_post_parent_id_with_no_post_argument_default_to_global_post_id() {
     37                $GLOBALS['post'] = get_post( self::$post_id );
     38                $this->assertSame( self::$parent_post_id, wp_get_post_parent_id() );
     39        }
     40
    3641        public function test_wp_get_post_parent_id_with_non_existing_id_default_to_global_post_id() {
    3742                $GLOBALS['post'] = get_post( self::$post_id );
    3843                $this->assertSame( self::$parent_post_id, wp_get_post_parent_id( 0 ) );