Make WordPress Core


Ignore:
Timestamp:
08/13/2015 10:30:26 PM (9 years ago)
Author:
ocean90
Message:

Capabilities: Fall back to the edit_posts capability for orphaned comments.

Also avoid PHP notices because of orphaned comments in the comments list table.
Includes unit test.

props pento, dd32.
fixes #33154.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/ajax/EditComment.php

    r25002 r33614  
    4747        ) );
    4848        $comment = array_pop( $comments );
     49
     50        // Set up a default request
     51        $_POST['_ajax_nonce-replyto-comment'] = wp_create_nonce( 'replyto-comment' );
     52        $_POST['comment_ID']                  = $comment->comment_ID;
     53        $_POST['content']                     = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.';
     54
     55        // Make the request
     56        try {
     57            $this->_handleAjax( 'edit-comment' );
     58        } catch ( WPAjaxDieContinueException $e ) {
     59            unset( $e );
     60        }
     61
     62        // Get the response
     63        $xml = simplexml_load_string( $this->_last_response, 'SimpleXMLElement', LIBXML_NOCDATA );
     64
     65        // Check the meta data
     66        $this->assertEquals( -1, (string) $xml->response[0]->edit_comment['position'] );
     67        $this->assertEquals( $comment->comment_ID, (string) $xml->response[0]->edit_comment['id'] );
     68        $this->assertEquals( 'edit-comment_' . $comment->comment_ID, (string) $xml->response['action'] );
     69
     70        // Check the payload
     71        $this->assertNotEmpty( (string) $xml->response[0]->edit_comment[0]->response_data );
     72
     73        // And supplemental is empty
     74        $this->assertEmpty( (string) $xml->response[0]->edit_comment[0]->supplemental );
     75    }
     76
     77    /**
     78     * @ticket 33154
     79     */
     80    function test_editor_can_edit_orphan_comments() {
     81        global $wpdb;
     82
     83        // Become an editor
     84        $this->_setRole( 'editor' );
     85
     86        // Get a comment
     87        $comments = get_comments( array(
     88            'post_id' => $this->_comment_post->ID
     89        ) );
     90        $comment = array_pop( $comments );
     91
     92        // Manually update the comment_post_ID, because wp_update_comment() will prevent it.
     93        $wpdb->query( "UPDATE {$wpdb->comments} SET comment_post_ID=0 WHERE comment_ID={$comment->comment_ID}" );
     94        clean_comment_cache( $comment->comment_ID );
    4995
    5096        // Set up a default request
Note: See TracChangeset for help on using the changeset viewer.