In get_page_by_path(), values fetched from cache should obey $output param.

Introduced in [37479].

Props spacedmonkey.
Fixes #36711.

git-svn-id: https://develop.svn.wordpress.org/trunk@37481 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Boone Gorges 2016-05-22 16:18:22 +00:00
parent 56a3d4bb65
commit 3e3b09c8ea
2 changed files with 27 additions and 1 deletions

View File

@ -4245,7 +4245,7 @@ function get_page_by_path( $page_path, $output = OBJECT, $post_type = 'page' ) {
if ( '0' === $cached || 0 === $cached ) {
return;
} else {
return get_post( $cached );
return get_post( $cached, $output );
}
}

View File

@ -242,4 +242,30 @@ class Tests_Post_GetPageByPath extends WP_UnitTestCase {
$num_queries++;
$this->assertSame( $num_queries, $wpdb->num_queries );
}
/**
* @ticket 37611
*/
public function test_output_param_should_be_obeyed_for_cached_value() {
$page = self::factory()->post->create( array(
'post_type' => 'page',
'post_name' => 'foo',
) );
// Prime cache.
$found = get_page_by_path( 'foo' );
$this->assertSame( $page, $found->ID );
$object = get_page_by_path( 'foo', OBJECT );
$this->assertInternalType( 'object', $object );
$this->assertSame( $page, $object->ID );
$array_n = get_page_by_path( 'foo', ARRAY_N );
$this->assertInternalType( 'array', $array_n );
$this->assertSame( $page, $array_n[0] );
$array_a = get_page_by_path( 'foo', ARRAY_A );
$this->assertInternalType( 'array', $array_a );
$this->assertSame( $page, $array_a['ID'] );
}
}