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
This commit is contained in:
Sergey Biryukov 2022-09-05 14:31:05 +00:00
parent b087346757
commit c7af86080d

View File

@ -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(