Make WordPress Core

Ticket #21397: patch-core-21397-3-tests.diff

File patch-core-21397-3-tests.diff, 5.0 KB (added by koke, 12 years ago)
  • tests/xmlrpc/wp/editPost.php

     
    221221                $this->assertFalse( is_sticky( $post_id ) );
    222222        }
    223223
     224        function test_only_if_no_new_revision() {
     225                $editor_id = $this->make_user_by_role( 'editor' );
     226
     227                $post = array(
     228                        'post_title' => 'Post Revision Test',
     229                        'post_author' => $editor_id,
     230                        'post_status' => 'publish',
     231                        'post_date'  => strftime("%Y-%m-%d %H:%M:%S", strtotime( '-1 day' ) ),
     232                );
     233                $post_id = wp_insert_post( $post );
     234
     235                $revision_date = new IXR_Date( mysql2date( 'Ymd\TH:i:s', 'now', false ) );
     236                $post2 = array( 'post_content' => 'Edit #3', 'only_if_no_new_revision' => $revision_date );
     237                $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'editor', 'editor', $post_id, $post2 ) );
     238                $this->assertNotInstanceOf( 'IXR_Error', $result );
     239
     240                $revision_date = new IXR_Date( mysql2date( 'Ymd\TH:i:s', $post['post_date'], false ) );
     241                $post2 = array( 'post_content' => 'Edit #4', 'only_if_no_new_revision' => $revision_date );
     242                $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'editor', 'editor', $post_id, $post2 ) );
     243                $this->assertInstanceOf( 'IXR_Error', $result );
     244                $this->assertEquals( 409, $result->code );
     245        }
     246
    224247}
  • tests/xmlrpc/wp/restoreRevision.php

     
     1<?php
     2
     3/**
     4 * @group xmlrpc
     5 */
     6class Tests_XMLRPC_wp_restoreRevision extends WP_XMLRPC_UnitTestCase {
     7        var $post_id;
     8        var $revision_id;
     9
     10        function setUp() {
     11                parent::setUp();
     12
     13                $post_data = array(
     14                        'post_title' => rand_str(),
     15                        'post_content' => 'edit1'
     16                );
     17                $this->post_id = wp_insert_post( $post_data );
     18                $post_data = get_post( $this->post_id, ARRAY_A );
     19                $post_data['post_content'] = 'edit2';
     20                wp_update_post( $post_data );
     21                $revisions = wp_get_post_revisions( $this->post_id );
     22                $revision = array_shift( $revisions );
     23                $this->revision_id = $revision->ID;
     24
     25        }
     26
     27        function test_invalid_username_password() {
     28                $result = $this->myxmlrpcserver->wp_restoreRevision( array( 1, 'username', 'password', $this->revision_id ) );
     29                $this->assertInstanceOf( 'IXR_Error', $result );
     30                $this->assertEquals( 403, $result->code );
     31        }
     32
     33        function test_incapable_user() {
     34                $this->make_user_by_role( 'subscriber' );
     35
     36                $result = $this->myxmlrpcserver->wp_restoreRevision( array( 1, 'subscriber', 'subscriber', $this->revision_id ) );
     37                $this->assertInstanceOf( 'IXR_Error', $result );
     38                $this->assertEquals( 401, $result->code );
     39        }
     40
     41        function test_capable_user() {
     42                $this->make_user_by_role( 'editor' );
     43
     44                $result = $this->myxmlrpcserver->wp_restoreRevision( array( 1, 'editor', 'editor', $this->revision_id ) );
     45                $this->assertNotInstanceOf( 'IXR_Error', $result );
     46        }
     47
     48        function test_revision_restored() {
     49                $this->make_user_by_role( 'editor' );
     50
     51                $result = $this->myxmlrpcserver->wp_restoreRevision( array( 1, 'editor', 'editor', $this->revision_id ) );
     52                $post = get_post( $this->post_id, ARRAY_A );
     53                $this->assertEquals( true, $result );
     54                $this->assertEquals( 'edit1', $post['post_content'] );
     55        }
     56}
     57
     58
  • tests/xmlrpc/wp/getRevisions.php

     
     1<?php
     2
     3/**
     4 * @group xmlrpc
     5 */
     6class Tests_XMLRPC_wp_getRevisions extends WP_XMLRPC_UnitTestCase {
     7
     8        function test_invalid_username_password() {
     9                $result = $this->myxmlrpcserver->wp_getRevisions( array( 1, 'username', 'password', 0 ) );
     10                $this->assertInstanceOf( 'IXR_Error', $result );
     11                $this->assertEquals( 403, $result->code );
     12        }
     13
     14        function test_incapable_user() {
     15                $this->make_user_by_role( 'subscriber' );
     16
     17                $result = $this->myxmlrpcserver->wp_getRevisions( array( 1, 'subscriber', 'subscriber', 0 ) );
     18                $this->assertInstanceOf( 'IXR_Error', $result );
     19                $this->assertEquals( 401, $result->code );
     20        }
     21
     22        function test_capable_user() {
     23                $this->make_user_by_role( 'editor' );
     24
     25                $result = $this->myxmlrpcserver->wp_getRevisions( array( 1, 'editor', 'editor', 0 ) );
     26                $this->assertNotInstanceOf( 'IXR_Error', $result );
     27        }
     28
     29        function test_revision_count() {
     30                $this->make_user_by_role( 'editor' );
     31
     32                $post = array( 'post_title' => 'Post test' );
     33                $post_id = wp_insert_post( $post );
     34
     35                $result = $this->myxmlrpcserver->wp_getRevisions( array( 1, 'editor', 'editor', $post_id ) );
     36                $this->assertInternalType( 'array', $result );
     37                $this->assertEquals( 0, count( $result ) );
     38
     39                $post = get_post( $post_id, ARRAY_A );
     40                $post['post_content'] = 'Edit #1';
     41                wp_update_post( $post );
     42
     43                $result = $this->myxmlrpcserver->wp_getRevisions( array( 1, 'editor', 'editor', $post_id ) );
     44                $this->assertInternalType( 'array', $result );
     45                $this->assertEquals( 1, count( $result ) );
     46        }
     47}
     48