From 404fd85586032b22dc2683b723e445407095da60 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Thu, 12 Sep 2013 17:30:01 +0000 Subject: [PATCH] Fix the failing `Tests_Link::test_wp_get_shortlink()` assertion: * `wp_get_shortlink()` was firing a notice when reading `$post->ID` while `$post` was null in some cases * Before the assertions that assume `$GLOBALS['post']` is not set, call `unset( $GLOBALS['post'] );` - there was global spillage from other tests See #25282. git-svn-id: https://develop.svn.wordpress.org/trunk@25404 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/link-template.php | 3 ++- tests/phpunit/tests/link.php | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/link-template.php b/src/wp-includes/link-template.php index 4264d784ef..9ba51f4e1d 100644 --- a/src/wp-includes/link-template.php +++ b/src/wp-includes/link-template.php @@ -2417,7 +2417,8 @@ function wp_get_shortlink($id = 0, $context = 'post', $allow_slugs = true) { $post = get_post( $post_id ); } elseif ( 'post' == $context ) { $post = get_post( $id ); - $post_id = $post->ID; + if ( ! empty( $post->ID ) ) + $post_id = $post->ID; } $shortlink = ''; diff --git a/tests/phpunit/tests/link.php b/tests/phpunit/tests/link.php index 13ab21f176..42ebc3f4b6 100644 --- a/tests/phpunit/tests/link.php +++ b/tests/phpunit/tests/link.php @@ -35,6 +35,8 @@ class Tests_Link extends WP_UnitTestCase { // Basic case $this->assertEquals( get_permalink( $post_id ), wp_get_shortlink( $post_id, 'post' ) ); + unset( $GLOBALS['post'] ); + // Global post is not set $this->assertEquals( '', wp_get_shortlink( 0, 'post' ) ); $this->assertEquals( '', wp_get_shortlink( 0 ) );