Make WordPress Core


Ignore:
Timestamp:
09/26/2015 02:48:47 AM (11 years ago)
Author:
wonderboymusic
Message:

XML-RPC: wp.getComments should be allowed to return approved comments to those without the 'moderate_comments' cap.

Adds (rewrites) unit tests from 4 years ago that we never committed because....

Props wonderboymusic, koke, ericmann, nprasath002.
Fixes #17981.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/xmlrpc/wp/editComment.php

    r34524 r34570  
    55 */
    66class Tests_XMLRPC_wp_editComment extends WP_XMLRPC_UnitTestCase {
     7
     8    function test_author_can_edit_own_comment() {
     9        $author_id = $this->make_user_by_role( 'author' );
     10        $post_id = $this->factory->post->create( array(
     11            'post_title' => 'Post test by author',
     12            'post_author' => $author_id
     13        ) );
     14
     15        $comment_id = wp_insert_comment(array(
     16            'comment_post_ID' => $post_id,
     17            'comment_author' => 'Commenter 1',
     18            'comment_author_url' => "http://example.com/1/",
     19            'comment_approved' => 1,
     20        ));
     21
     22        $result = $this->myxmlrpcserver->wp_editComment( array( 1, 'author', 'author', $comment_id, array(
     23            'status' => 'hold'
     24        ) ) );
     25        $this->assertNotInstanceOf( 'IXR_Error', $result );
     26        $this->assertTrue( $result );
     27    }
     28
     29    function test_author_cannot_edit_others_comment() {
     30        $this->make_user_by_role( 'author' );
     31        $editor_id = $this->make_user_by_role( 'editor' );
     32        $post_id = $this->factory->post->create( array(
     33            'post_title' => 'Post test by editor',
     34            'post_author' => $editor_id
     35        ) );
     36
     37        $comment_id = wp_insert_comment( array(
     38            'comment_post_ID' => $post_id,
     39            'comment_author' => 'Commenter 2',
     40            'comment_author_url' => 'http://example.com/2/',
     41            'comment_approved' => 0,
     42        ) );
     43
     44        $result = $this->myxmlrpcserver->wp_editComment( array( 1, 'author', 'author', $comment_id, array( 'status' => 'hold' ) ) );
     45        $this->assertInstanceOf( 'IXR_Error', $result );
     46        $this->assertEquals( 403, $result->code );
     47        $this->assertEquals( __( 'You are not allowed to moderate or edit this comment.' ), $result->message );
     48    }
     49
    750    function test_trash_comment() {
    851        $this->make_user_by_role( 'administrator' );
Note: See TracChangeset for help on using the changeset viewer.