From c7af86080d7ba781003a04da1f08bc05fc5ab694 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Mon, 5 Sep 2022 14:31:05 +0000 Subject: [PATCH] Tests: Consistently set the current user in the tests for retaining a sticky status. This affects: * `test_user_without_publish_posts_cannot_affect_sticky()` * `test_user_without_publish_posts_cannot_affect_sticky_with_edit_post()` In both tests, the user is now set after creating the post, not before. This aims to better match the intention of the tests, as they ensure that a sticky status is unaffected for a post that is ''edited'' by a user without the `publish_posts` capability, not necessarily ''created'' by that user. Includes minor documentation updates for consistency. Follow-up to [33096], [35183]. See #55652. git-svn-id: https://develop.svn.wordpress.org/trunk@54068 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/post.php | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/tests/phpunit/tests/post.php b/tests/phpunit/tests/post.php index 62fbd7bc81..5c46db1b0c 100644 --- a/tests/phpunit/tests/post.php +++ b/tests/phpunit/tests/post.php @@ -314,19 +314,12 @@ class Tests_Post extends WP_UnitTestCase { } /** - * If a post is sticky and is updated by a user that does not have the publish_post capability, - * it should _stay_ sticky. + * If a sticky post is updated via `wp_update_post()` by a user + * without the `publish_posts` capability, it should stay sticky. * * @ticket 24153 */ - public function test_user_without_publish_cannot_affect_sticky() { - wp_set_current_user( self::$grammarian_id ); - - // Sanity check. - $this->assertFalse( current_user_can( 'publish_posts' ) ); - $this->assertTrue( current_user_can( 'edit_others_posts' ) ); - $this->assertTrue( current_user_can( 'edit_published_posts' ) ); - + public function test_user_without_publish_posts_cannot_affect_sticky() { // Create a sticky post. $post = self::factory()->post->create_and_get( array( @@ -339,6 +332,13 @@ class Tests_Post extends WP_UnitTestCase { // Sanity check. $this->assertTrue( is_sticky( $post->ID ) ); + wp_set_current_user( self::$grammarian_id ); + + // Sanity check. + $this->assertFalse( current_user_can( 'publish_posts' ) ); + $this->assertTrue( current_user_can( 'edit_others_posts' ) ); + $this->assertTrue( current_user_can( 'edit_published_posts' ) ); + // Edit the post. $post->post_title = 'Updated'; $post->post_content = 'Updated'; @@ -352,12 +352,12 @@ class Tests_Post extends WP_UnitTestCase { } /** - * If the `edit_post()` method is invoked by a user without publish_posts permission, - * the sticky status of the post should not be changed. + * If a sticky post is updated via `edit_post()` by a user + * without the `publish_posts` capability, it should stay sticky. * * @ticket 24153 */ - public function test_user_without_publish_cannot_affect_sticky_with_edit_post() { + public function test_user_without_publish_posts_cannot_affect_sticky_with_edit_post() { // Create a sticky post. $post = self::factory()->post->create_and_get( array(