mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-07-02 00:00:15 +00:00
Query: Some documentation and test improvements for update_post_author_caches():
* 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
This commit is contained in:
75
tests/phpunit/tests/post/updatePostAuthorCaches.php
Normal file
75
tests/phpunit/tests/post/updatePostAuthorCaches.php
Normal file
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
/**
|
||||
* Test `update_post_author_caches()`.
|
||||
*
|
||||
* @package WordPress
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test class for `update_post_author_caches()`.
|
||||
*
|
||||
* @group post
|
||||
* @group query
|
||||
* @group user
|
||||
*
|
||||
* @covers ::update_post_author_caches
|
||||
*/
|
||||
class Tests_Post_UpdatePostAuthorCaches extends WP_UnitTestCase {
|
||||
|
||||
/**
|
||||
* User IDs from the shared fixture.
|
||||
*
|
||||
* @var int[]
|
||||
*/
|
||||
public static $user_ids;
|
||||
|
||||
/**
|
||||
* Post author count.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public static $post_author_count = 5;
|
||||
|
||||
/**
|
||||
* 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::$user_ids = array();
|
||||
|
||||
for ( $i = 0; $i < self::$post_author_count; $i++ ) {
|
||||
self::$user_ids[ $i ] = $factory->user->create();
|
||||
$factory->post->create(
|
||||
array(
|
||||
'post_type' => 'post',
|
||||
'post_author' => self::$user_ids[ $i ],
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 55716
|
||||
*/
|
||||
public function test_update_post_author_caches() {
|
||||
$action = new MockAction();
|
||||
add_filter( 'update_user_metadata_cache', array( $action, 'filter' ), 10, 2 );
|
||||
|
||||
$q = new WP_Query(
|
||||
array(
|
||||
'post_type' => 'post',
|
||||
'posts_per_page' => self::$post_author_count,
|
||||
)
|
||||
);
|
||||
|
||||
while ( $q->have_posts() ) {
|
||||
$q->the_post();
|
||||
}
|
||||
|
||||
$args = $action->get_args();
|
||||
$last_args = end( $args );
|
||||
|
||||
$this->assertSameSets( self::$user_ids, $last_args[1], 'Ensure that user IDs are primed' );
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
<?php
|
||||
/**
|
||||
* Test `wp_update_cache()`.
|
||||
* Test `update_post_cache()`.
|
||||
*
|
||||
* @package WordPress
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test class for `wp_update_cache()`.
|
||||
* Test class for `update_post_cache()`.
|
||||
*
|
||||
* @group post
|
||||
* @group query
|
||||
@@ -18,7 +18,7 @@ class Tests_Post_UpdatePostCache extends WP_UnitTestCase {
|
||||
/**
|
||||
* Post IDs from the shared fixture.
|
||||
*
|
||||
* @var array
|
||||
* @var int[]
|
||||
*/
|
||||
public static $post_ids;
|
||||
|
||||
|
||||
@@ -620,39 +620,6 @@ class Tests_Query extends WP_UnitTestCase {
|
||||
$this->assertSame( array( $p2 ), $q->posts );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 55716
|
||||
*/
|
||||
public function test_prime_user_cache() {
|
||||
$action = new MockAction();
|
||||
add_filter( 'update_user_metadata_cache', array( $action, 'filter' ), 10, 2 );
|
||||
$user_ids = array();
|
||||
$count = 5;
|
||||
for ( $i = 0; $i < $count; $i ++ ) {
|
||||
$user_ids[ $i ] = self::factory()->user->create();
|
||||
self::factory()->post->create(
|
||||
array(
|
||||
'post_type' => 'post',
|
||||
'post_author' => $user_ids[ $i ],
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$q = new WP_Query(
|
||||
array(
|
||||
'post_type' => 'post',
|
||||
'posts_per_page' => $count,
|
||||
)
|
||||
);
|
||||
while ( $q->have_posts() ) {
|
||||
$q->the_post();
|
||||
}
|
||||
|
||||
$args = $action->get_args();
|
||||
$last_args = end( $args );
|
||||
$this->assertSameSets( $user_ids, $last_args[1], 'Ensure that user ids are primed' );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 35601
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user