wordpress-develop/tests/phpunit/tests/xmlrpc/wp/restoreRevision.php
Sergey Biryukov cfc3b57488 Docs: Improve inline comments per the documentation standards.
Includes minor code layout fixes for better readability.

See #48303.

git-svn-id: https://develop.svn.wordpress.org/trunk@47122 602fd350-edb4-49c9-b593-d223f7449a82
2020-01-29 00:43:23 +00:00

59 lines
1.9 KiB
PHP

<?php
/**
* @group xmlrpc
*/
class Tests_XMLRPC_wp_restoreRevision extends WP_XMLRPC_UnitTestCase {
var $post_id;
var $revision_id;
function setUp() {
parent::setUp();
$this->post_id = self::factory()->post->create( array( 'post_content' => 'edit1' ) ); // Not saved as a revision.
// First saved revision on update, see https://core.trac.wordpress.org/changeset/24650
wp_insert_post(
array(
'ID' => $this->post_id,
'post_content' => 'edit2',
)
);
$revisions = wp_get_post_revisions( $this->post_id );
// First revision is empty, see https://core.trac.wordpress.org/changeset/23842
// $revision = array_shift( $revisions );
// First revision is NOT empty, see https://core.trac.wordpress.org/changeset/24650
$revision = array_shift( $revisions );
$this->revision_id = $revision->ID;
}
function test_invalid_username_password() {
$result = $this->myxmlrpcserver->wp_restoreRevision( array( 1, 'username', 'password', $this->revision_id ) );
$this->assertIXRError( $result );
$this->assertEquals( 403, $result->code );
}
function test_incapable_user() {
$this->make_user_by_role( 'subscriber' );
$result = $this->myxmlrpcserver->wp_restoreRevision( array( 1, 'subscriber', 'subscriber', $this->revision_id ) );
$this->assertIXRError( $result );
$this->assertEquals( 401, $result->code );
}
function test_capable_user() {
$this->make_user_by_role( 'editor' );
$result = $this->myxmlrpcserver->wp_restoreRevision( array( 1, 'editor', 'editor', $this->revision_id ) );
$this->assertNotIXRError( $result );
}
function test_revision_restored() {
$this->make_user_by_role( 'editor' );
$result = $this->myxmlrpcserver->wp_restoreRevision( array( 1, 'editor', 'editor', $this->revision_id ) );
$this->assertTrue( $result );
$this->assertEquals( 'edit2', get_post( $this->post_id )->post_content );
}
}