Make WordPress Core


Ignore:
Timestamp:
03/04/2014 03:08:54 AM (12 years ago)
Author:
nacin
Message:

Don't default to current user for capability checks when dealing with a post without an author (post_author = 0).

Undoes [12053]. While it risks breakage, this is a far safer and saner default for these situations.

props danielbachhuber.
fixes #27020.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/user/capabilities.php

    r25409 r27390  
    523523            $this->assertFalse( $admin->has_cap('delete_post_meta',  $post, 'not_protected') );
    524524        }
     525    }
     526
     527    function authorless_post_statuses() {
     528        return array( array( 'draft' ), array( 'private' ), array( 'publish' ) );
     529    }
     530
     531    /**
     532     * @ticket 27020
     533     * @dataProvider authorless_post_statuses
     534     */
     535    function test_authorless_post( $status ) {
     536        // Make a post without an author
     537        $post = $this->factory->post->create( array( 'post_author' => 0, 'post_type' => 'post', 'post_status' => $status ) );
     538
     539        // Add an editor and contributor
     540        $editor = $this->factory->user->create_and_get( array( 'role' => 'editor' ) );
     541        $contributor = $this->factory->user->create_and_get( array( 'role' => 'contributor' ) );
     542
     543        // editor can edit, view, and trash
     544        $this->assertTrue( $editor->has_cap( 'edit_post', $post ) );
     545        $this->assertTrue( $editor->has_cap( 'delete_post', $post ) );
     546        $this->assertTrue( $editor->has_cap( 'read_post', $post ) );
     547
     548        // a contributor cannot (except read a published post)
     549        $this->assertFalse( $contributor->has_cap( 'edit_post', $post ) );
     550        $this->assertFalse( $contributor->has_cap( 'delete_post', $post ) );
     551        $this->assertEquals( $status === 'publish', $contributor->has_cap( 'read_post', $post ) );
    525552    }
    526553
Note: See TracChangeset for help on using the changeset viewer.