Make WordPress Core


Ignore:
Timestamp:
09/05/2022 02:31:05 PM (22 months ago)
Author:
SergeyBiryukov
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/post.php

    r54067 r54068  
    315315
    316316    /**
    317      * If a post is sticky and is updated by a user that does not have the publish_post capability,
    318      * it should _stay_ sticky.
     317     * If a sticky post is updated via `wp_update_post()` by a user
     318     * without the `publish_posts` capability, it should stay sticky.
    319319     *
    320320     * @ticket 24153
    321321     */
    322     public function test_user_without_publish_cannot_affect_sticky() {
     322    public function test_user_without_publish_posts_cannot_affect_sticky() {
     323        // Create a sticky post.
     324        $post = self::factory()->post->create_and_get(
     325            array(
     326                'post_title'   => 'Will be changed',
     327                'post_content' => 'Will be changed',
     328            )
     329        );
     330        stick_post( $post->ID );
     331
     332        // Sanity check.
     333        $this->assertTrue( is_sticky( $post->ID ) );
     334
    323335        wp_set_current_user( self::$grammarian_id );
    324336
     
    327339        $this->assertTrue( current_user_can( 'edit_others_posts' ) );
    328340        $this->assertTrue( current_user_can( 'edit_published_posts' ) );
    329 
    330         // Create a sticky post.
    331         $post = self::factory()->post->create_and_get(
    332             array(
    333                 'post_title'   => 'Will be changed',
    334                 'post_content' => 'Will be changed',
    335             )
    336         );
    337         stick_post( $post->ID );
    338 
    339         // Sanity check.
    340         $this->assertTrue( is_sticky( $post->ID ) );
    341341
    342342        // Edit the post.
     
    353353
    354354    /**
    355      * If the `edit_post()` method is invoked by a user without publish_posts permission,
    356      * the sticky status of the post should not be changed.
     355     * If a sticky post is updated via `edit_post()` by a user
     356     * without the `publish_posts` capability, it should stay sticky.
    357357     *
    358358     * @ticket 24153
    359359     */
    360     public function test_user_without_publish_cannot_affect_sticky_with_edit_post() {
     360    public function test_user_without_publish_posts_cannot_affect_sticky_with_edit_post() {
    361361        // Create a sticky post.
    362362        $post = self::factory()->post->create_and_get(
Note: See TracChangeset for help on using the changeset viewer.