mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2025-10-16 12:05:38 +00:00
* Make the descriptions for `update_post_author_caches()` and `update_post_caches()` more specific. * Move the unit test into its own file, for consistency with `update_post_cache()` tests. This also allows for using shared fixtures in case more tests are added in the future. Follow-up to [53482]. See #55716. git-svn-id: https://develop.svn.wordpress.org/trunk@53483 602fd350-edb4-49c9-b593-d223f7449a82
142 lines
2.9 KiB
PHP
142 lines
2.9 KiB
PHP
<?php
|
|
/**
|
|
* Test `update_post_cache()`.
|
|
*
|
|
* @package WordPress
|
|
*/
|
|
|
|
/**
|
|
* Test class for `update_post_cache()`.
|
|
*
|
|
* @group post
|
|
* @group query
|
|
*
|
|
* @covers ::update_post_cache
|
|
*/
|
|
class Tests_Post_UpdatePostCache extends WP_UnitTestCase {
|
|
|
|
/**
|
|
* Post IDs from the shared fixture.
|
|
*
|
|
* @var int[]
|
|
*/
|
|
public static $post_ids;
|
|
|
|
/**
|
|
* Set up test resources before the class.
|
|
*
|
|
* @param WP_UnitTest_Factory $factory The unit test factory.
|
|
*/
|
|
public static function wpSetupBeforeClass( WP_UnitTest_Factory $factory ) {
|
|
self::$post_ids = $factory->post->create_many( 1 );
|
|
}
|
|
|
|
/**
|
|
* Ensure that `update_post_cache()` returns `null` when
|
|
* `$posts` is empty.
|
|
*
|
|
* @ticket 50567
|
|
*/
|
|
public function test_should_return_null_with_an_empty_array() {
|
|
$posts = array();
|
|
$this->assertNull( update_post_cache( $posts ) );
|
|
}
|
|
|
|
/**
|
|
* Ensure filter = raw is always set via Query.
|
|
*
|
|
* @ticket 50567
|
|
*/
|
|
public function test_query_caches_post_filter() {
|
|
$post_id = self::$post_ids[0];
|
|
$this->go_to( '/' );
|
|
|
|
$cached_post = wp_cache_get( $post_id, 'posts' );
|
|
$this->assertIsObject(
|
|
$cached_post,
|
|
'The cached post is not an object'
|
|
);
|
|
|
|
$this->assertObjectHasAttribute(
|
|
'filter',
|
|
$cached_post,
|
|
'The cached post does not have a "filter" property'
|
|
);
|
|
|
|
$this->assertSame(
|
|
'raw',
|
|
$cached_post->filter,
|
|
'The filter is not set to "raw"'
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Ensure filter = raw is always set via get_post.
|
|
*
|
|
* @ticket 50567
|
|
*/
|
|
public function test_get_post_caches_post_filter() {
|
|
$post_id = self::$post_ids[0];
|
|
get_post( $post_id );
|
|
|
|
$cached_post = wp_cache_get( $post_id, 'posts' );
|
|
$this->assertSame( 'raw', $cached_post->filter );
|
|
}
|
|
|
|
/**
|
|
* Ensure filter = raw is always set via get_post called with a different filter setting.
|
|
*
|
|
* @ticket 50567
|
|
*/
|
|
public function test_get_post_caches_post_filter_is_always_raw() {
|
|
$post_id = self::$post_ids[0];
|
|
get_post( $post_id, OBJECT, 'display' );
|
|
|
|
$cached_post = wp_cache_get( $post_id, 'posts' );
|
|
$this->assertIsObject(
|
|
$cached_post,
|
|
'The cached post is not an object'
|
|
);
|
|
|
|
$this->assertObjectHasAttribute(
|
|
'filter',
|
|
$cached_post,
|
|
'The cached post does not have a "filter" property'
|
|
);
|
|
|
|
$this->assertSame(
|
|
'raw',
|
|
$cached_post->filter,
|
|
'The filter is not set to "raw"'
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Ensure filter = raw is always set via get_posts.
|
|
*
|
|
* @ticket 50567
|
|
*/
|
|
public function test_get_posts_caches_post_filter_is_always_raw() {
|
|
$post_id = self::$post_ids[0];
|
|
get_posts( array( 'includes' => $post_id ) );
|
|
|
|
$cached_post = wp_cache_get( $post_id, 'posts' );
|
|
$this->assertIsObject(
|
|
$cached_post,
|
|
'The cached post is not an object'
|
|
);
|
|
|
|
$this->assertObjectHasAttribute(
|
|
'filter',
|
|
$cached_post,
|
|
'The cached post does not have a "filter" property'
|
|
);
|
|
|
|
$this->assertSame(
|
|
'raw',
|
|
$cached_post->filter,
|
|
'The filter is not set to "raw"'
|
|
);
|
|
}
|
|
}
|