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.

git-svn-id: https://develop.svn.wordpress.org/trunk@33614 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Dominik Schilling (ocean90)
2015-08-13 22:30:26 +00:00
parent ce531d8723
commit 23eaa36145
3 changed files with 62 additions and 5 deletions

View File

@@ -74,6 +74,52 @@ class Tests_Ajax_EditComment extends WP_Ajax_UnitTestCase {
$this->assertEmpty( (string) $xml->response[0]->edit_comment[0]->supplemental );
}
/**
* @ticket 33154
*/
function test_editor_can_edit_orphan_comments() {
global $wpdb;
// Become an editor
$this->_setRole( 'editor' );
// Get a comment
$comments = get_comments( array(
'post_id' => $this->_comment_post->ID
) );
$comment = array_pop( $comments );
// Manually update the comment_post_ID, because wp_update_comment() will prevent it.
$wpdb->query( "UPDATE {$wpdb->comments} SET comment_post_ID=0 WHERE comment_ID={$comment->comment_ID}" );
clean_comment_cache( $comment->comment_ID );
// Set up a default request
$_POST['_ajax_nonce-replyto-comment'] = wp_create_nonce( 'replyto-comment' );
$_POST['comment_ID'] = $comment->comment_ID;
$_POST['content'] = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.';
// Make the request
try {
$this->_handleAjax( 'edit-comment' );
} catch ( WPAjaxDieContinueException $e ) {
unset( $e );
}
// Get the response
$xml = simplexml_load_string( $this->_last_response, 'SimpleXMLElement', LIBXML_NOCDATA );
// Check the meta data
$this->assertEquals( -1, (string) $xml->response[0]->edit_comment['position'] );
$this->assertEquals( $comment->comment_ID, (string) $xml->response[0]->edit_comment['id'] );
$this->assertEquals( 'edit-comment_' . $comment->comment_ID, (string) $xml->response['action'] );
// Check the payload
$this->assertNotEmpty( (string) $xml->response[0]->edit_comment[0]->response_data );
// And supplemental is empty
$this->assertEmpty( (string) $xml->response[0]->edit_comment[0]->supplemental );
}
/**
* Get comments as a non-privileged user (subscriber)
* Expects test to fail