mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-04-28 08:24:30 +00:00
This ensures that not only the return values match the expected results, but also that their type is the same. Going forward, stricter type checking by using `assertSame()` should generally be preferred to `assertEquals()` where appropriate, to make the tests more reliable. Props johnbillion, jrf, SergeyBiryukov. See #38266. git-svn-id: https://develop.svn.wordpress.org/trunk@48937 602fd350-edb4-49c9-b593-d223f7449a82
97 lines
2.4 KiB
PHP
97 lines
2.4 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @group xmlrpc
|
|
*/
|
|
class Tests_XMLRPC_wp_editComment extends WP_XMLRPC_UnitTestCase {
|
|
|
|
function test_author_can_edit_own_comment() {
|
|
$author_id = $this->make_user_by_role( 'author' );
|
|
$post_id = self::factory()->post->create(
|
|
array(
|
|
'post_title' => 'Post test by author',
|
|
'post_author' => $author_id,
|
|
)
|
|
);
|
|
|
|
$comment_id = wp_insert_comment(
|
|
array(
|
|
'comment_post_ID' => $post_id,
|
|
'comment_author' => 'Commenter 1',
|
|
'comment_author_url' => 'http://example.com/1/',
|
|
'comment_approved' => 1,
|
|
)
|
|
);
|
|
|
|
$result = $this->myxmlrpcserver->wp_editComment(
|
|
array(
|
|
1,
|
|
'author',
|
|
'author',
|
|
$comment_id,
|
|
array(
|
|
'status' => 'hold',
|
|
),
|
|
)
|
|
);
|
|
$this->assertNotIXRError( $result );
|
|
$this->assertTrue( $result );
|
|
}
|
|
|
|
function test_author_cannot_edit_others_comment() {
|
|
$this->make_user_by_role( 'author' );
|
|
$editor_id = $this->make_user_by_role( 'editor' );
|
|
$post_id = self::factory()->post->create(
|
|
array(
|
|
'post_title' => 'Post test by editor',
|
|
'post_author' => $editor_id,
|
|
)
|
|
);
|
|
|
|
$comment_id = wp_insert_comment(
|
|
array(
|
|
'comment_post_ID' => $post_id,
|
|
'comment_author' => 'Commenter 2',
|
|
'comment_author_url' => 'http://example.com/2/',
|
|
'comment_approved' => 0,
|
|
)
|
|
);
|
|
|
|
$result = $this->myxmlrpcserver->wp_editComment( array( 1, 'author', 'author', $comment_id, array( 'status' => 'hold' ) ) );
|
|
$this->assertIXRError( $result );
|
|
$this->assertSame( 403, $result->code );
|
|
$this->assertSame( __( 'Sorry, you are not allowed to moderate or edit this comment.' ), $result->message );
|
|
}
|
|
|
|
function test_trash_comment() {
|
|
$this->make_user_by_role( 'administrator' );
|
|
$post_id = self::factory()->post->create();
|
|
|
|
$comment_data = array(
|
|
'comment_post_ID' => $post_id,
|
|
'comment_author' => 'Test commenter',
|
|
'comment_author_url' => 'http://example.com/',
|
|
'comment_author_email' => 'example@example.com',
|
|
'comment_content' => 'Comment content',
|
|
'comment_approved' => '1',
|
|
);
|
|
$comment_id = wp_insert_comment( $comment_data );
|
|
|
|
$this->assertSame( '1', get_comment( $comment_id )->comment_approved );
|
|
|
|
$this->myxmlrpcserver->wp_editComment(
|
|
array(
|
|
1,
|
|
'administrator',
|
|
'administrator',
|
|
$comment_id,
|
|
array(
|
|
'status' => 'trash',
|
|
),
|
|
)
|
|
);
|
|
|
|
$this->assertSame( 'trash', get_comment( $comment_id )->comment_approved );
|
|
}
|
|
}
|