Make WordPress Core

Changeset 768 in tests


Ignore:
Timestamp:
06/30/2012 05:48:18 PM (14 years ago)
Author:
maxcutler
Message:

Port the XML-RPC test suite.

Fixes #45.

Location:
trunk/wp-testcase/test-xmlrpc-api
Files:
27 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-testcase/test-xmlrpc-api/test_mt_getRecentPostTitles.php

    r644 r768  
    11<?php
    22
    3 include_once(ABSPATH . WPINC . '/post-thumbnail-template.php');
    4 
    5 class TestXMLRPCServer_mt_getRecentPostTitles extends WPXMLRPCServerTestCase {
    6         var $post_data;
    7         var $post_id;
    8         var $post_date_ts;
    9 
    10         function setUp() {
    11                 parent::setUp();
    12 
    13                 $this->post_date_ts = strtotime( '+1 day' );
    14                 $this->post_data = array(
    15                         'post_title' => rand_str(),
    16                         'post_content' => rand_str( 2000 ),
    17                         'post_excerpt' => rand_str( 100 ),
    18                         'post_author' => get_user_by( 'login', 'author' )->ID,
    19                         'post_date'  => strftime( "%Y-%m-%d %H:%M:%S", $this->post_date_ts ),
    20                 );
    21                 $this->post_id = wp_insert_post( $this->post_data );
    22         }
    23 
    24         function tearDown() {
    25                 parent::tearDown();
    26 
    27                 wp_delete_post( $this->post_id );
    28         }
    29 
     3class TestXMLRPCServer_mt_getRecentPostTitles extends WP_XMLRPC_UnitTestCase {
    304
    315        function test_invalid_username_password() {
     
    3711        function test_no_posts() {
    3812                $this->_delete_all_posts();
     13                $this->make_user_by_role( 'author' );
    3914
    4015                $result = $this->myxmlrpcserver->mt_getRecentPostTitles( array( 1, 'author', 'author' ) );
     
    4419
    4520        function test_no_editable_posts() {
    46                 wp_delete_post( $this->post_id );
    47 
    48                 $post_data_editor = array(
    49                         'post_title' => rand_str(),
    50                         'post_content' => rand_str( 2000 ),
    51                         'post_excerpt' => rand_str( 100 ),
    52                         'post_author' => get_user_by( 'login', 'editor' )->ID,
    53                 );
    54                 $post_id = wp_insert_post( $post_data_editor );
     21                $this->make_user_by_role( 'author' );
     22                $editor = $this->make_user_by_role( 'editor' );
     23                $this->factory->post->create( array( 'post_author' => $editor ) );
    5524
    5625                $result = $this->myxmlrpcserver->mt_getRecentPostTitles( array( 1, 'author', 'author' ) );
    5726                $this->assertNotInstanceOf( 'IXR_Error', $result );
    5827                $this->assertEquals( 0, count( $result ) );
    59 
    60                 wp_delete_post( $post_id );
    6128        }
    6229
    6330        function test_date() {
     31                $this->make_user_by_role( 'author' );
     32
    6433                $results = $this->myxmlrpcserver->mt_getRecentPostTitles( array( 1, 'author', 'author' ) );
    6534                $this->assertNotInstanceOf( 'IXR_Error', $results );
  • trunk/wp-testcase/test-xmlrpc-api/test_mw_editPost.php

    r707 r768  
    11<?php
    22
    3 class TestXMLRPCServer_mw_editPost extends WPXMLRPCServerTestCase {
     3class TestXMLRPCServer_mw_editPost extends WP_XMLRPC_UnitTestCase {
    44
    55        function test_invalid_username_password() {
     
    1111
    1212        function test_edit_own_post() {
    13                 $contributor_id = get_user_by( 'login', 'contributor' )->ID;
     13                $contributor_id = $this->make_user_by_role( 'contributor' );
    1414                $post = array( 'post_title' => 'Post test', 'post_author' => $contributor_id );
    1515                $post_id = wp_insert_post( $post );
     
    2626
    2727        function test_capable_edit_others_post() {
    28                 $contributor_id = get_user_by( 'login', 'contributor' )->ID;
     28                $this->make_user_by_role( 'editor' );
     29                $contributor_id = $this->make_user_by_role( 'contributor' );
     30
    2931                $post = array( 'post_title' => 'Post test', 'post_author' => $contributor_id );
    3032                $post_id = wp_insert_post( $post );
     
    4143
    4244        function test_incapable_edit_others_post() {
    43                 $author_id = get_user_by( 'login', 'author' )->ID;
     45                $this->make_user_by_role( 'contributor' );
     46                $author_id = $this->make_user_by_role( 'author' );
     47
    4448                $original_title = 'Post test';
    4549                $post = array( 'post_title' => $original_title, 'post_author' => $author_id );
     
    5761
    5862        function test_capable_reassign_author() {
    59                 $contributor_id = get_user_by( 'login', 'contributor' )->ID;
     63                $contributor_id = $this->make_user_by_role( 'contributor' );
     64                $author_id = $this->make_user_by_role( 'author' );
     65                $this->make_user_by_role( 'editor' );
     66
    6067                $post = array( 'post_title' => 'Post test', 'post_author' => $contributor_id );
    6168                $post_id = wp_insert_post( $post );
    6269
    63                 $author_id = get_user_by( 'login', 'author' )->ID;
    6470                $post2 = array( 'wp_author_id' => $author_id );
    6571                $result = $this->myxmlrpcserver->mw_editPost( array( $post_id, 'editor', 'editor', $post2 ) );
     
    7278
    7379        function test_incapable_reassign_author() {
    74                 $contributor_id = get_user_by( 'login', 'contributor' )->ID;
     80                $contributor_id = $this->make_user_by_role( 'contributor' );
     81                $author_id = $this->make_user_by_role( 'author' );
     82
    7583                $post = array( 'post_title' => 'Post test', 'post_author' => $contributor_id );
    7684                $post_id = wp_insert_post( $post );
    7785
    78                 $author_id = get_user_by( 'login', 'author' )->ID;
    7986                $post2 = array( 'wp_author_id' => $author_id );
    8087                $result = $this->myxmlrpcserver->mw_editPost( array( $post_id, 'contributor', 'contributor', $post2 ) );
     
    8996                add_theme_support( 'post-thumbnails' );
    9097
    91                 $author_id = get_user_by( 'login', 'author' )->ID;
     98                $author_id = $this->make_user_by_role( 'author' );
     99
    92100                $post = array( 'post_title' => 'Post Thumbnail Test', 'post_author' => $author_id );
    93101                $post_id = wp_insert_post( $post );
     
    141149
    142150        function test_edit_basic_post_info() {
    143                 $contributor_id = get_user_by( 'login', 'contributor' )->ID;
     151                $contributor_id = $this->make_user_by_role( 'contributor' );
     152
    144153                $post = array( 'post_title' => 'Title', 'post_content' => 'Content', 'post_excerpt' => 'Excerpt', 'post_author' => $contributor_id );
    145154                $post_id = wp_insert_post( $post );
     
    175184        // Not allowed since [19914]
    176185        function test_change_post_type() {
    177                 $contributor_id = get_user_by( 'login', 'contributor' )->ID;
     186                $contributor_id = $this->make_user_by_role( 'contributor' );
     187
    178188                $post = array( 'post_title' => 'Title', 'post_author' => $contributor_id );
    179189                $post_id = wp_insert_post( $post );
  • trunk/wp-testcase/test-xmlrpc-api/test_mw_getPost.php

    r699 r768  
    33include_once(ABSPATH . WPINC . '/post-thumbnail-template.php');
    44
    5 class TestXMLRPCServer_mw_getPost extends WPXMLRPCServerTestCase {
     5class TestXMLRPCServer_mw_getPost extends WP_XMLRPC_UnitTestCase {
    66        var $post_data;
    77        var $post_id;
     
    1111                parent::setUp();
    1212
     13                $author_id = $this->make_user_by_role( 'author' );
    1314                $this->post_date_ts = strtotime( '+1 day' );
    1415                $this->post_data = array(
     
    1617                        'post_content' => rand_str( 2000 ),
    1718                        'post_excerpt' => rand_str( 100 ),
    18                         'post_author' => get_user_by( 'login', 'author' )->ID,
     19                        'post_author' => $author_id,
    1920                        'post_date'  => strftime( "%Y-%m-%d %H:%M:%S", $this->post_date_ts ),
    2021                );
    2122                $this->post_id = wp_insert_post( $this->post_data );
    2223        }
    23 
    24         function tearDown() {
    25                 parent::tearDown();
    26 
    27                 wp_delete_post( $this->post_id );
    28         }
    29 
    3024
    3125        function test_invalid_username_password() {
     
    3630
    3731        function test_incapable_user() {
     32                $this->make_user_by_role( 'subscriber' );
     33
    3834                $result = $this->myxmlrpcserver->mw_getPost( array( $this->post_id, 'subscriber', 'subscriber' ) );
    3935                $this->assertInstanceOf( 'IXR_Error', $result );
     
    120116                $this->assertEquals( $attachment_id, $result['wp_post_thumbnail'] );
    121117
    122                 delete_post_thumbnail( $this->post_id );
    123118                remove_theme_support( 'post-thumbnails' );
    124119        }
  • trunk/wp-testcase/test-xmlrpc-api/test_mw_getRecentPosts.php

    r699 r768  
    33include_once(ABSPATH . WPINC . '/post-thumbnail-template.php');
    44
    5 class TestXMLRPCServer_mw_getRecentPosts extends WPXMLRPCServerTestCase {
     5class TestXMLRPCServer_mw_getRecentPosts extends WP_XMLRPC_UnitTestCase {
    66        var $post_data;
    77        var $post_id;
     
    1111                parent::setUp();
    1212
     13                $author_id = $this->make_user_by_role( 'author' );
    1314                $this->post_date_ts = strtotime( '+1 day' );
    1415                $this->post_data = array(
     
    1617                        'post_content' => rand_str( 2000 ),
    1718                        'post_excerpt' => rand_str( 100 ),
    18                         'post_author' => get_user_by( 'login', 'author' )->ID,
     19                        'post_author' => $author_id,
    1920                        'post_date'  => strftime( "%Y-%m-%d %H:%M:%S", $this->post_date_ts ),
    2021                );
    2122                $this->post_id = wp_insert_post( $this->post_data );
    2223        }
    23 
    24         function tearDown() {
    25                 parent::tearDown();
    26 
    27                 wp_delete_post( $this->post_id );
    28         }
    29 
    3024
    3125        function test_invalid_username_password() {
     
    122116                }
    123117
    124                 delete_post_thumbnail( $this->post_id );
    125118                remove_theme_support( 'post-thumbnails' );
    126119        }
    127120
    128121        function test_date() {
     122                $this->make_user_by_role( 'editor' );
     123
    129124                $results = $this->myxmlrpcserver->mw_getRecentPosts( array( 1, 'editor', 'editor' ) );
    130125                $this->assertNotInstanceOf( 'IXR_Error', $results );
  • trunk/wp-testcase/test-xmlrpc-api/test_mw_newPost.php

    r707 r768  
    11<?php
    22
    3 class TestXMLRPCServer_mw_newPost extends WPXMLRPCServerTestCase {
     3class TestXMLRPCServer_mw_newPost extends WP_XMLRPC_UnitTestCase {
    44
    55        function test_invalid_username_password() {
     
    1111
    1212        function test_incapable_user() {
     13                $this->make_user_by_role( 'subscriber' );
     14
    1315                $post = array();
    1416                $result = $this->myxmlrpcserver->mw_newPost( array( 1, 'subscriber', 'subscriber', $post ) );
     
    1820
    1921        function test_no_content() {
     22                $this->make_user_by_role( 'author' );
     23
    2024                $post = array();
    2125                $result = $this->myxmlrpcserver->mw_newPost( array( 1, 'author', 'author', $post ) );
     
    2630
    2731        function test_basic_content() {
     32                $this->make_user_by_role( 'author' );
     33
    2834                $post = array( 'title' => 'Test' );
    2935                $result = $this->myxmlrpcserver->mw_newPost( array( 1, 'author', 'author', $post ) );
     
    3339
    3440        function test_ignore_id() {
     41                $this->make_user_by_role( 'author' );
     42
    3543                $post = array( 'title' => 'Test', 'ID' => 103948 );
    3644                $result = $this->myxmlrpcserver->mw_newPost( array( 1, 'author', 'author', $post ) );
     
    4048
    4149        function test_capable_publish() {
     50                $this->make_user_by_role( 'author' );
     51
    4252                $post = array( 'title' => 'Test', 'post_status' => 'publish' );
    4353                $result = $this->myxmlrpcserver->mw_newPost( array( 1, 'author', 'author', $post ) );
     
    4656
    4757        function test_incapable_publish() {
     58                $this->make_user_by_role( 'contributor' );
     59
    4860                $post = array( 'title' => 'Test', 'post_status' => 'publish' );
    4961                $result = $this->myxmlrpcserver->mw_newPost( array( 1, 'contributor', 'contributor', $post ) );
     
    5365
    5466        function test_capable_other_author() {
    55                 $other_author_id = get_user_by( 'login', 'author' )->ID;
     67                $this->make_user_by_role( 'editor' );
     68                $other_author_id = $this->make_user_by_role( 'author' );
     69
    5670                $post = array( 'title' => 'Test', 'wp_author_id' => $other_author_id );
    5771                $result = $this->myxmlrpcserver->mw_newPost( array( 1, 'editor', 'editor', $post ) );
     
    6074
    6175        function test_incapable_other_author() {
    62                 $other_author_id = get_user_by( 'login', 'author' )->ID;
     76                $this->make_user_by_role( 'contributor' );
     77                $other_author_id = $this->make_user_by_role( 'author' );
     78
    6379                $post = array( 'title' => 'Test', 'wp_author_id' => $other_author_id );
    6480                $result = $this->myxmlrpcserver->mw_newPost( array( 1, 'contributor', 'contributor', $post ) );
     
    6985        function test_invalid_author() {
    7086                $this->knownWPBug( 20356 );
     87                $this->make_user_by_role( 'editor' );
     88
    7189                $post = array( 'title' => 'Test', 'wp_author_id' => 99999999 );
    7290                $result = $this->myxmlrpcserver->mw_newPost( array( 1, 'editor', 'editor', $post ) );
     
    7694
    7795        function test_empty_author() {
    78                 $my_author_id = get_user_by( 'login', 'author' )->ID;
     96                $my_author_id = $this->make_user_by_role( 'author' );
     97
    7998                $post = array( 'title' => 'Test' );
    8099                $result = $this->myxmlrpcserver->mw_newPost( array( 1, 'author', 'author', $post ) );
     
    89108        function test_post_thumbnail() {
    90109                add_theme_support( 'post-thumbnails' );
     110
     111                $this->make_user_by_role( 'author' );
    91112
    92113                // create attachment
     
    113134
    114135        function test_incapable_set_post_type_as_page() {
     136                $this->make_user_by_role( 'author' );
     137
    115138                $post = array( 'title' => 'Test', 'post_type' => 'page' );
    116139                $result = $this->myxmlrpcserver->mw_newPost( array( 1, 'author', 'author', $post ) );
     
    120143
    121144        function test_capable_set_post_type_as_page() {
     145                $this->make_user_by_role( 'editor' );
     146
    122147                $post = array( 'title' => 'Test', 'post_type' => 'page' );
    123148                $result = $this->myxmlrpcserver->mw_newPost( array( 1, 'editor', 'editor', $post ) );
  • trunk/wp-testcase/test-xmlrpc-api/test_wp_deletePost.php

    r739 r768  
    11<?php
    22
    3 class TestXMLRPCServer_wp_deletePost extends WPXMLRPCServerTestCase {
     3class TestXMLRPCServer_wp_deletePost extends WP_XMLRPC_UnitTestCase {
    44
    55        function test_invalid_username_password() {
     
    1010
    1111        function test_invalid_post() {
     12                $this->make_user_by_role( 'editor' );
     13
    1214                $result = $this->myxmlrpcserver->wp_deletePost( array( 1, 'editor', 'editor', 0 ) );
    1315                $this->assertInstanceOf( 'IXR_Error', $result );
     
    1618
    1719        function test_incapable_user() {
    18                 $this->_insert_quick_posts( 1 );
    19                 $post_id = array_pop( $this->post_ids );
     20                $this->make_user_by_role( 'subscriber' );
     21                $post_id = $this->factory->post->create();
    2022
    2123                $result = $this->myxmlrpcserver->wp_deletePost( array( 1, 'subscriber', 'subscriber', $post_id ) );
    2224                $this->assertInstanceOf( 'IXR_Error', $result );
    2325                $this->assertEquals( 401, $result->code );
    24 
    25                 wp_delete_post( $post_id, true );
    2626        }
    2727
    2828        function test_post_deleted() {
    29                 $this->_insert_quick_posts( 1 );
    30                 $post_id = array_pop( $this->post_ids );
     29                $this->make_user_by_role( 'editor' );
     30                $post_id = $this->factory->post->create();
    3131
    3232                $result = $this->myxmlrpcserver->wp_deletePost( array( 1, 'editor', 'editor', $post_id ) );
     
    3636                $post = get_post( $post_id );
    3737                $this->assertEquals( 'trash', $post->post_status );
    38 
    39                 wp_delete_post( $post_id, true );
    4038        }
    4139}
  • trunk/wp-testcase/test-xmlrpc-api/test_wp_deleteTerm.php

    r735 r768  
    11<?php
    22
    3 class TestXMLRPCServer_wp_deleteTerm extends WPXMLRPCServerTestCase {
     3class TestXMLRPCServer_wp_deleteTerm extends WP_XMLRPC_UnitTestCase {
    44        var $term;
    55
     
    88
    99                $this->term = wp_insert_term( 'term' . rand_str() , 'category' );
    10         }
    11 
    12         function tearDown() {
    13                 parent::tearDown();
    14 
    15                 wp_delete_term( $this->term['term_id'], 'category' );
    1610        }
    1711
     
    2317
    2418        function test_empty_taxonomy() {
     19                $this->make_user_by_role( 'subscriber' );
     20
    2521                $result = $this->myxmlrpcserver->wp_deleteTerm( array( 1, 'subscriber', 'subscriber', '', 0 ) );
    2622                $this->assertInstanceOf( 'IXR_Error', $result );
     
    3026
    3127        function test_invalid_taxonomy() {
     28                $this->make_user_by_role( 'subscriber' );
     29
    3230                $result = $this->myxmlrpcserver->wp_deleteTerm( array( 1, 'subscriber', 'subscriber', 'not_existing', 0 ) );
    3331                $this->assertInstanceOf( 'IXR_Error', $result );
     
    3735
    3836        function test_incapable_user() {
     37                $this->make_user_by_role( 'subscriber' );
     38
    3939                $result = $this->myxmlrpcserver->wp_deleteTerm( array( 1, 'subscriber', 'subscriber', 'category', $this->term['term_id'] ) );
    4040                $this->assertInstanceOf( 'IXR_Error', $result );
     
    4444
    4545        function test_empty_term() {
     46                $this->make_user_by_role( 'editor' );
     47
    4648                $result = $this->myxmlrpcserver->wp_deleteTerm( array( 1, 'editor', 'editor', 'category', '' ) );
    4749                $this->assertInstanceOf( 'IXR_Error', $result );
     
    5153
    5254        function test_invalid_term() {
     55                $this->make_user_by_role( 'editor' );
     56
    5357                $result = $this->myxmlrpcserver->wp_deleteTerm( array( 1, 'editor', 'editor', 'category', 9999 ) );
    5458                $this->assertInstanceOf( 'IXR_Error', $result );
     
    5862
    5963        function test_term_deleted() {
     64                $this->make_user_by_role( 'editor' );
     65
    6066                $result = $this->myxmlrpcserver->wp_deleteTerm( array( 1, 'editor', 'editor', 'category', $this->term['term_id'] ) );
    6167                $this->assertNotInstanceOf( 'IXR_Error', $result );
  • trunk/wp-testcase/test-xmlrpc-api/test_wp_editPost.php

    r739 r768  
    11<?php
    22
    3 class TestXMLRPCServer_wp_editPost extends WPXMLRPCServerTestCase {
     3class TestXMLRPCServer_wp_editPost extends WP_XMLRPC_UnitTestCase {
    44
    55        function test_invalid_username_password() {
     
    1010
    1111        function test_edit_own_post() {
    12                 $contributor_id = get_user_by( 'login', 'contributor' )->ID;
     12                $contributor_id = $this->make_user_by_role( 'contributor' );
     13
    1314                $post = array( 'post_title' => 'Post test', 'post_author' => $contributor_id );
    1415                $post_id = wp_insert_post( $post );
     
    2526
    2627        function test_capable_edit_others_post() {
    27                 $contributor_id = get_user_by( 'login', 'contributor' )->ID;
     28                $contributor_id = $this->make_user_by_role( 'contributor' );
     29                $this->make_user_by_role( 'editor' );
     30
    2831                $post = array( 'post_title' => 'Post test', 'post_author' => $contributor_id );
    2932                $post_id = wp_insert_post( $post );
     
    4043
    4144        function test_incapable_edit_others_post() {
    42                 $author_id = get_user_by( 'login', 'author' )->ID;
     45                $this->make_user_by_role( 'contributor' );
     46                $author_id = $this->make_user_by_role( 'author' );
     47
    4348                $original_title = 'Post test';
    4449                $post = array( 'post_title' => $original_title, 'post_author' => $author_id );
     
    5661
    5762        function test_capable_reassign_author() {
    58                 $contributor_id = get_user_by( 'login', 'contributor' )->ID;
    59                 $post = array( 'post_title' => 'Post test', 'post_author' => $contributor_id );
    60                 $post_id = wp_insert_post( $post );
    61 
    62                 $author_id = get_user_by( 'login', 'author' )->ID;
     63                $contributor_id = $this->make_user_by_role( 'contributor' );
     64                $author_id = $this->make_user_by_role( 'author' );
     65                $this->make_user_by_role( 'editor' );
     66
     67                $post = array( 'post_title' => 'Post test', 'post_author' => $contributor_id );
     68                $post_id = wp_insert_post( $post );
     69
    6370                $post2 = array( 'post_author' => $author_id );
    6471                $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'editor', 'editor', $post_id, $post2 ) );
     
    7178
    7279        function test_incapable_reassign_author() {
    73                 $contributor_id = get_user_by( 'login', 'contributor' )->ID;
    74                 $post = array( 'post_title' => 'Post test', 'post_author' => $contributor_id );
    75                 $post_id = wp_insert_post( $post );
    76 
    77                 $author_id = get_user_by( 'login', 'author' )->ID;
     80                $contributor_id = $this->make_user_by_role( 'contributor' );
     81                $author_id = $this->make_user_by_role( 'author' );
     82
     83                $post = array( 'post_title' => 'Post test', 'post_author' => $contributor_id );
     84                $post_id = wp_insert_post( $post );
     85
    7886                $post2 = array( 'post_author' => $author_id );
    7987                $result = $this->myxmlrpcserver->wp_editPost( array( 1, 'contributor', 'contributor', $post_id, $post2 ) );
     
    8896                add_theme_support( 'post-thumbnails' );
    8997
    90                 $author_id = get_user_by( 'login', 'author' )->ID;
     98                $author_id = $this->make_user_by_role( 'author' );
     99
    91100                $post = array( 'post_title' => 'Post Thumbnail Test', 'post_author' => $author_id );
    92101                $post_id = wp_insert_post( $post );
     
    153162
    154163        function test_edit_custom_fields() {
    155                 $contributor_id = get_user_by( 'login', 'contributor' )->ID;
     164                $contributor_id = $this->make_user_by_role( 'contributor' );
     165
    156166                $post = array( 'post_title' => 'Post test', 'post_author' => $contributor_id );
    157167                $post_id = wp_insert_post( $post );
     
    186196
    187197        function test_capable_unsticky() {
    188                 $this->author = get_user_by( 'login', 'editor' );
    189                 $this->_insert_quick_posts( 1 );
    190                 $post_id = array_pop( $this->post_ids );
     198                $editor_id = $this->make_user_by_role( 'editor' );
     199
     200                $post_id = $this->factory->post->create( array( 'post_author' => $editor_id ) );
    191201                stick_post( $post_id );
    192202
     
    195205                $this->assertNotInstanceOf( 'IXR_Error', $result );
    196206                $this->assertFalse( is_sticky( $post_id ) );
    197 
    198                 wp_delete_post( $post_id, true );
    199207        }
    200208
    201209        function test_password_transition_unsticky() {
    202210                // when transitioning to private status or adding a post password, post should be un-stuck
    203                 $this->author = get_user_by( 'login', 'editor' );
    204                 $this->_insert_quick_posts( 1 );
    205                 $post_id = array_pop( $this->post_ids );
     211                $editor_id = $this->make_user_by_role( 'editor' );
     212                $post_id = $this->factory->post->create( array( 'post_author' => $editor_id ) );
    206213                stick_post( $post_id );
    207214
     
    210217                $this->assertNotInstanceOf( 'IXR_Error', $result );
    211218                $this->assertFalse( is_sticky( $post_id ) );
    212 
    213                 wp_delete_post( $post_id, true );
    214219        }
    215220
  • trunk/wp-testcase/test-xmlrpc-api/test_wp_editTerm.php

    r735 r768  
    11<?php
    22
    3 class TestXMLRPCServer_wp_editTerm extends WPXMLRPCServerTestCase {
     3class TestXMLRPCServer_wp_editTerm extends WP_XMLRPC_UnitTestCase {
    44        var $parent_term;
    55        var $child_term;
     
    1414        }
    1515
    16         function tearDown() {
    17                 parent::tearDown();
    18 
    19                 wp_delete_term( $this->parent_term['term_id'], 'category' );
    20                 wp_delete_term( $this->child_term['term_id'], 'category' );
    21                 wp_delete_term( $this->post_tag['term_id'], 'post_tag' );
    22         }
    23 
    2416        function test_invalid_username_password() {
    2517                $result = $this->myxmlrpcserver->wp_editTerm( array( 1, 'username', 'password', 'category', 1 ) );
     
    2921
    3022        function test_empty_taxonomy() {
     23                $this->make_user_by_role( 'subscriber' );
     24
    3125                $result = $this->myxmlrpcserver->wp_editTerm( array( 1, 'subscriber', 'subscriber', '', array( 'taxonomy' => '' ) ) );
    3226                $this->assertInstanceOf( 'IXR_Error', $result );
     
    3630
    3731        function test_invalid_taxonomy() {
     32                $this->make_user_by_role( 'subscriber' );
     33
    3834                $result = $this->myxmlrpcserver->wp_editTerm( array( 1, 'subscriber', 'subscriber', $this->parent_term['term_id'], array( 'taxonomy' => 'not_existing' ) ) );
    3935                $this->assertInstanceOf( 'IXR_Error', $result );
     
    4339
    4440        function test_incapable_user() {
     41                $this->make_user_by_role( 'subscriber' );
     42
    4543                $result = $this->myxmlrpcserver->wp_editTerm( array( 1, 'subscriber', 'subscriber', $this->parent_term['term_id'], array( 'taxonomy' => 'category' ) ) );
    4644                $this->assertInstanceOf( 'IXR_Error', $result );
     
    5048
    5149        function test_term_not_exists() {
     50                $this->make_user_by_role( 'editor' );
     51
    5252                $result = $this->myxmlrpcserver->wp_editTerm( array( 1, 'editor', 'editor', 9999, array( 'taxonomy' => 'category' ) ) );
    5353                $this->assertInstanceOf( 'IXR_Error', $result );
     
    5757
    5858        function test_empty_term() {
     59                $this->make_user_by_role( 'editor' );
     60
    5961                $result = $this->myxmlrpcserver->wp_editTerm( array( 1, 'editor', 'editor', '', array( 'taxonomy' => 'category' ) ) );
    6062                $this->assertInstanceOf( 'IXR_Error', $result );
     
    6466
    6567        function test_empty_term_name() {
     68                $this->make_user_by_role( 'editor' );
     69
    6670                $result = $this->myxmlrpcserver->wp_editTerm( array( 1, 'editor', 'editor', $this->parent_term['term_id'], array( 'taxonomy' => 'category', 'name' => '' ) ) );
    6771                $this->assertInstanceOf( 'IXR_Error', $result );
     
    7175
    7276        function test_parent_for_nonhierarchical() {
     77                $this->make_user_by_role( 'editor' );
     78
    7379                $result = $this->myxmlrpcserver->wp_editTerm( array( 1, 'editor', 'editor', $this->post_tag['term_id'], array( 'taxonomy' => 'post_tag', 'parent' => $this->parent_term['term_id'] ) ) );
    7480                $this->assertInstanceOf( 'IXR_Error', $result );
     
    7884
    7985        function test_parent_empty() {
     86                $this->make_user_by_role( 'editor' );
     87
    8088                $result = $this->myxmlrpcserver->wp_editTerm( array( 1, 'editor', 'editor', $this->child_term['term_id'], array( 'taxonomy' => 'category', 'parent' => '', 'name' => 'test' ) ) );
    8189                $this->assertInstanceOf( 'IXR_Error', $result );
     
    8593
    8694        function test_parent_invalid() {
     95                $this->make_user_by_role( 'editor' );
     96
    8797                $result = $this->myxmlrpcserver->wp_editTerm( array( 1, 'editor', 'editor', $this->child_term['term_id'], array( 'taxonomy' => 'category', 'parent' => 'dasda', 'name' => 'test' ) ) );
    8898                $this->assertInstanceOf( 'IXR_Error', $result );
     
    91101
    92102        function test_parent_not_existing() {
     103                $this->make_user_by_role( 'editor' );
     104
    93105                $result = $this->myxmlrpcserver->wp_editTerm( array( 1, 'editor', 'editor', $this->child_term['term_id'], array( 'taxonomy' => 'category', 'parent' => 9999, 'name' => 'test' ) ) );
    94106                $this->assertInstanceOf( 'IXR_Error', $result );
     
    98110
    99111        function test_parent_duplicate_slug() {
     112                $this->make_user_by_role( 'editor' );
     113
    100114                $parent_term = get_term_by( 'id', $this->parent_term['term_id'], 'category' );
    101115                $result = $this->myxmlrpcserver->wp_editTerm( array( 1, 'editor', 'editor', $this->child_term['term_id'], array( 'taxonomy' => 'category', 'slug' => $parent_term->slug ) ) );
     
    106120
    107121        function test_edit_all_fields() {
     122                $this->make_user_by_role( 'editor' );
     123
    108124                $fields = array( 'taxonomy' => 'category', 'name' => 'Child 2', 'parent' => $this->parent_term['term_id'], 'description' => 'Child term', 'slug' => 'child_2' );
    109125                $result = $this->myxmlrpcserver->wp_editTerm( array( 1, 'editor', 'editor', $this->child_term['term_id'], $fields ) );
  • trunk/wp-testcase/test-xmlrpc-api/test_wp_getComment.php

    r720 r768  
    22
    33
    4 class TestXMLRPCServer_wp_getComment extends WPXMLRPCServerTestCase {
     4class TestXMLRPCServer_wp_getComment extends WP_XMLRPC_UnitTestCase {
    55        var $post_id;
    66        var $parent_comment_id;
     
    1212                parent::setUp();
    1313
    14                 $this->_insert_quick_posts( 1 );
    15                 $this->post_id = $this->post_ids[0];
     14                $this->post_id = $this->factory->post->create();
    1615
    1716                $this->parent_comment_data = array(
     
    3534        }
    3635
    37         function tearDown() {
    38                 parent::tearDown();
    39 
    40                 wp_delete_comment( $this->child_comment_id );
    41                 wp_delete_comment( $this->parent_comment_id );
    42                 wp_delete_post( $this->post_id );
    43         }
    44 
    4536        function test_invalid_username_password() {
    4637                $result = $this->myxmlrpcserver->wp_getComment( array( 1, 'username', 'password', $this->parent_comment_id ) );
     
    5041
    5142        function test_incapable_user() {
     43                $this->make_user_by_role( 'contributor' );
     44
    5245                $result = $this->myxmlrpcserver->wp_getComment( array( 1, 'contributor', 'contributor', $this->parent_comment_id ) );
    5346                $this->assertInstanceOf( 'IXR_Error', $result );
     
    5649
    5750        function test_valid_comment() {
     51                $this->make_user_by_role( 'editor' );
     52
    5853                $result = $this->myxmlrpcserver->wp_getComment( array( 1, 'editor', 'editor', $this->parent_comment_id ) );
    5954                $this->assertNotInstanceOf( 'IXR_Error', $result );
     
    9085
    9186        function test_valid_child_comment() {
     87                $this->make_user_by_role( 'editor' );
     88
    9289                $result = $this->myxmlrpcserver->wp_getComment( array( 1, 'editor', 'editor', $this->child_comment_id ) );
    9390                $this->assertNotInstanceOf( 'IXR_Error', $result );
     
    9895
    9996        function test_invalid_id() {
     97                $this->make_user_by_role( 'editor' );
     98
    10099                $result = $this->myxmlrpcserver->wp_getComment( array( 1, 'editor', 'editor', 123456789 ) );
    101100                $this->assertInstanceOf( 'IXR_Error', $result );
  • trunk/wp-testcase/test-xmlrpc-api/test_wp_getComments.php

    r720 r768  
    22
    33
    4 class TestXMLRPCServer_wp_getComments extends WPXMLRPCServerTestCase {
     4class TestXMLRPCServer_wp_getComments extends WP_XMLRPC_UnitTestCase {
    55        var $post_id;
    66
     
    88                parent::setUp();
    99
    10                 $this->_insert_quick_posts( 1 );
    11                 $this->post_id = $this->post_ids[0];
    12                 $this->_insert_quick_comments( $this->post_id, 15 );
    13         }
    14 
    15         function tearDown() {
    16                 parent::tearDown();
    17 
    18                 wp_delete_post( $this->post_id );
     10                $this->post_id = $this->factory->post->create();
     11                $this->factory->comment->create_post_comments( $this->post_id, 15 );
    1912        }
    2013
     
    2619
    2720        function test_incapable_user() {
     21                $this->make_user_by_role( 'contributor' );
     22
    2823                $result = $this->myxmlrpcserver->wp_getComments( array( 1, 'contributor', 'contributor', array() ) );
    2924                $this->assertInstanceOf( 'IXR_Error', $result );
     
    3227
    3328        function test_capable_user() {
     29                $this->make_user_by_role( 'editor' );
     30
    3431                $results = $this->myxmlrpcserver->wp_getComments( array( 1, 'editor', 'editor', array() ) );
    3532                $this->assertNotInstanceOf( 'IXR_Error', $results );
     
    4239
    4340        function test_post_filter() {
     41                $this->make_user_by_role( 'editor' );
     42
    4443                $filter = array(
    4544                        'post_id' => $this->post_id
     
    5453
    5554        function test_number_filter() {
     55                $this->make_user_by_role( 'editor' );
     56
    5657                $filter = array(
    5758                        'post_id' => $this->post_id,
  • trunk/wp-testcase/test-xmlrpc-api/test_wp_getMediaItem.php

    r707 r768  
    11<?php
    2 class TestXMLRPCServer_wp_getMediaItem extends WPXMLRPCServerTestCase {
     2class TestXMLRPCServer_wp_getMediaItem extends WP_XMLRPC_UnitTestCase {
    33        var $post_id;
    44        var $attachment_data;
     
    3737
    3838        function tearDown() {
     39                remove_theme_support( 'post-thumbnails' );
     40
    3941                parent::tearDown();
    40 
    41                 wp_delete_attachment( $this->attachment_id );
    42                 wp_delete_post( $this->post_id );
    43 
    44                 remove_theme_support( 'post-thumbnails' );
    4542        }
    4643
     
    5249
    5350        function test_valid_media_item() {
     51                $this->make_user_by_role( 'author' );
     52
    5453                $fields = array( 'post' );
    5554                $result = $this->myxmlrpcserver->wp_getMediaItem( array( 1, 'author', 'author', $this->attachment_id, $fields ) );
  • trunk/wp-testcase/test-xmlrpc-api/test_wp_getOptions.php

    r684 r768  
    11<?php
    22
    3 class TestXMLRPCServer_wp_getOptions extends WPXMLRPCServerTestCase {
     3class TestXMLRPCServer_wp_getOptions extends WP_XMLRPC_UnitTestCase {
    44
    55        function test_invalid_username_password() {
     
    1010
    1111        function test_valid_username_password() {
     12                $this->make_user_by_role( 'subscriber' );
     13
    1214                $result = $this->myxmlrpcserver->wp_getOptions( array( 1, 'subscriber', 'subscriber' ) );
    1315                $this->assertInternalType( 'array', $result );
     
    1618
    1719        function test_option_value() {
     20                $this->make_user_by_role( 'administrator' );
     21
    1822                $result = $this->myxmlrpcserver->wp_getOptions( array( 1, 'administrator', 'administrator', 'default_comment_status' ) );
    1923                $this->assertInternalType( 'array', $result );
     
    2731
    2832                $this->knownWPBug( 20201 );
     33
     34                $this->make_user_by_role( 'subscriber' );
    2935
    3036                $result = $this->myxmlrpcserver->wp_getOptions( array( 1, 'subscriber', 'subscriber' ) );
     
    111117                global $wp_version;
    112118
     119                $this->make_user_by_role( 'administrator' );
     120
    113121                $result = $this->myxmlrpcserver->wp_getOptions( array( 1, 'administrator', 'administrator' ) );
    114122                $this->assertInternalType( 'array', $result );
  • trunk/wp-testcase/test-xmlrpc-api/test_wp_getPage.php

    r604 r768  
    11<?php
    22
    3 include_once(ABSPATH . WPINC . '/post-thumbnail-template.php');
    4 
    5 class TestXMLRPCServer_wp_getPage extends WPXMLRPCServerTestCase {
     3class TestXMLRPCServer_wp_getPage extends WP_XMLRPC_UnitTestCase {
    64        var $post_data;
    75        var $post_id;
     
    1715                        'post_content' => rand_str( 2000 ),
    1816                        'post_excerpt' => rand_str( 100 ),
    19                         'post_author' => get_user_by( 'login', 'author' )->ID,
     17                        'post_author' => $this->make_user_by_role( 'author' ),
    2018                        'post_date'  => strftime( "%Y-%m-%d %H:%M:%S", $this->post_date_ts ),
    2119                );
     
    3836                $this->knownWPBug(20336);
    3937
    40                 $result = $this->myxmlrpcserver->wp_getPage( array( 1, 9999, 'author', 'author' ) );
     38                $this->make_user_by_role( 'editor' );
     39
     40                $result = $this->myxmlrpcserver->wp_getPage( array( 1, 9999, 'editor', 'editor' ) );
    4141                $this->assertInstanceOf( 'IXR_Error', $result );
    4242                $this->assertEquals( 404, $result->code );
     
    4444
    4545        function test_valid_page() {
     46                $this->make_user_by_role( 'editor' );
     47
    4648                $result = $this->myxmlrpcserver->wp_getPage( array( 1, $this->post_id, 'editor', 'editor' ) );
    4749                $this->assertNotInstanceOf( 'IXR_Error', $result );
     
    8183
    8284        function test_date() {
     85                $this->make_user_by_role( 'editor' );
     86
    8387                $result = $this->myxmlrpcserver->wp_getPage( array( 1, $this->post_id, 'editor', 'editor' ) );
    8488                $this->assertNotInstanceOf( 'IXR_Error', $result );
  • trunk/wp-testcase/test-xmlrpc-api/test_wp_getPageList.php

    r607 r768  
    33include_once(ABSPATH . WPINC . '/post-thumbnail-template.php');
    44
    5 class TestXMLRPCServer_wp_getPageList extends WPXMLRPCServerTestCase {
     5class TestXMLRPCServer_wp_getPageList extends WP_XMLRPC_UnitTestCase {
    66        var $post_data;
    77        var $post_id;
     
    1717                        'post_content' => rand_str( 2000 ),
    1818                        'post_excerpt' => rand_str( 100 ),
    19                         'post_author' => get_user_by( 'login', 'author' )->ID,
     19                        'post_author' => $this->make_user_by_role( 'author' ),
    2020                        'post_date'  => strftime( "%Y-%m-%d %H:%M:%S", $this->post_date_ts ),
    2121                );
    2222                $this->post_id = wp_insert_post( $this->post_data );
    23         }
    24 
    25         function tearDown() {
    26                 parent::tearDown();
    27 
    28                 wp_delete_post( $this->post_id );
    2923        }
    3024
     
    3630
    3731        function test_incapable_user() {
     32                $this->make_user_by_role( 'contributor' );
     33
    3834                $result = $this->myxmlrpcserver->wp_getPageList( array( 1, 'contributor', 'contributor' ) );
    3935                $this->assertInstanceOf( 'IXR_Error', $result );
     
    4137        }
    4238
     39        function test_date() {
     40                $this->make_user_by_role( 'editor' );
    4341
    44         function test_date() {
    4542                $results = $this->myxmlrpcserver->wp_getPageList( array( 1, 'editor', 'editor' ) );
    4643                $this->assertNotInstanceOf( 'IXR_Error', $results );
  • trunk/wp-testcase/test-xmlrpc-api/test_wp_getPages.php

    r716 r768  
    11<?php
    22
    3 class TestXMLRPCServer_wp_getPages extends WPXMLRPCServerTestCase {
     3class TestXMLRPCServer_wp_getPages extends WP_XMLRPC_UnitTestCase {
    44    var $post_data;
    55    var $post_id;
     
    1616            'post_content' => rand_str( 2000 ),
    1717            'post_excerpt' => rand_str( 100 ),
    18             'post_author' => get_user_by( 'login', 'administrator' )->ID,
     18            'post_author' => $this->make_user_by_role( 'administrator' ),
    1919            'post_date'  => strftime( "%Y-%m-%d %H:%M:%S", $this->post_date_ts ),
    2020        );
    2121        $this->post_id = wp_insert_post( $this->post_data );
    22         $this->editor_id = get_user_by( 'login', 'editor' )->ID;
    23     }
    24 
    25     function tearDown() {
    26         parent::tearDown();
    27 
    28         wp_delete_post( $this->post_id );
     22        $this->editor_id = $this->make_user_by_role( 'editor' );
    2923    }
    3024
     
    3630
    3731    function test_incapable_user() {
     32                $this->make_user_by_role( 'contributor' );
     33
    3834        $result = $this->myxmlrpcserver->wp_getPages( array( 1, 'contributor', 'contributor' ) );
    3935        $this->assertInstanceOf( 'IXR_Error', $result );
  • trunk/wp-testcase/test-xmlrpc-api/test_wp_getPost.php

    r739 r768  
    11<?php
    22
    3 class TestXMLRPCServer_wp_getPost extends WPXMLRPCServerTestCase {
     3class TestXMLRPCServer_wp_getPost extends WP_XMLRPC_UnitTestCase {
    44        var $post_data;
    55        var $post_id;
     
    1515                        'post_content' => rand_str( 2000 ),
    1616                        'post_excerpt' => rand_str( 100 ),
    17                         'post_author' => get_user_by( 'login', 'author' )->ID,
     17                        'post_author' => $this->make_user_by_role( 'author' ),
    1818                        'post_date'  => strftime( "%Y-%m-%d %H:%M:%S", $this->post_date_ts ),
    1919                );
     
    2121                $this->post_custom_field = array( 'key' => 'test_custom_field', 'value' => 12345678);
    2222                $this->post_custom_field['id'] = add_post_meta( $this->post_id, $this->post_custom_field['key'], $this->post_custom_field['value'] );
    23         }
    24 
    25         function tearDown() {
    26                 parent::tearDown();
    27 
    28                 wp_delete_post( $this->post_id );
    2923        }
    3024
  • trunk/wp-testcase/test-xmlrpc-api/test_wp_getPostType.php

    r709 r768  
    11<?php
    22
    3 class TestXMLRPCServer_wp_getPostType extends WPXMLRPCServerTestCase {
     3class TestXMLRPCServer_wp_getPostType extends WP_XMLRPC_UnitTestCase {
    44        var $cpt_name;
    55        var $cpt_args;
     
    2828
    2929        function test_invalid_post_type_name() {
     30                $this->make_user_by_role( 'editor' );
     31
    3032                $result = $this->myxmlrpcserver->wp_getPostType( array( 1, 'editor', 'editor', 'foobar' ) );
    3133                $this->assertInstanceOf( 'IXR_Error', $result );
     
    3436
    3537        function test_valid_post_type_name() {
     38                $this->make_user_by_role( 'editor' );
     39
    3640                $result = $this->myxmlrpcserver->wp_getPostType( array( 1, 'editor', 'editor', 'post' ) );
    3741                $this->assertNotInstanceOf( 'IXR_Error', $result );
     
    3943
    4044        function test_incapable_user() {
     45                $this->make_user_by_role( 'subscriber' );
     46
    4147                $result = $this->myxmlrpcserver->wp_getPostType( array( 1, 'subscriber', 'subscriber', 'post' ) );
    4248                $this->assertInstanceOf( 'IXR_Error', $result );
     
    4551
    4652        function test_valid_type() {
     53                $this->make_user_by_role( 'editor' );
     54
    4755                $result = $this->myxmlrpcserver->wp_getPostType( array( 1, 'editor', 'editor', $this->cpt_name, array( 'labels', 'cap', 'menu', 'taxonomies' ) ) );
    4856                $this->assertNotInstanceOf( 'IXR_Error', $result );
  • trunk/wp-testcase/test-xmlrpc-api/test_wp_getPostTypes.php

    r587 r768  
    11<?php
    22
    3 class TestXMLRPCServer_wp_getPostTypes extends WPXMLRPCServerTestCase {
     3class TestXMLRPCServer_wp_getPostTypes extends WP_XMLRPC_UnitTestCase {
    44        function test_invalid_username_password() {
    55                $result = $this->myxmlrpcserver->wp_getPostTypes( array( 1, 'username', 'password', 'post' ) );
     
    99
    1010        function test_incapable_user() {
     11                $this->make_user_by_role( 'subscriber' );
     12
    1113                $result = $this->myxmlrpcserver->wp_getPostTypes( array( 1, 'subscriber', 'subscriber' ) );
    1214                $this->assertNotInstanceOf( 'IXR_Error', $result );
     
    1618
    1719        function test_capable_user() {
     20                $this->make_user_by_role( 'editor' );
     21
    1822                $result = $this->myxmlrpcserver->wp_getPostTypes( array( 1, 'editor', 'editor' ) );
    1923                $this->assertNotInstanceOf( 'IXR_Error', $result );
     
    2327
    2428        function test_simple_filter() {
     29                $this->make_user_by_role( 'editor' );
     30
    2531                $result = $this->myxmlrpcserver->wp_getPostTypes( array( 1, 'editor', 'editor', array( 'hierarchical' => true ) ) );
    2632                $this->assertNotInstanceOf( 'IXR_Error', $result );
  • trunk/wp-testcase/test-xmlrpc-api/test_wp_getPosts.php

    r739 r768  
    11<?php
    22
    3 class TestXMLRPCServer_wp_getPosts extends WPXMLRPCServerTestCase {
     3class TestXMLRPCServer_wp_getPosts extends WP_XMLRPC_UnitTestCase {
    44
    55        function test_invalid_username_password() {
     
    1111        function test_incapable_user() {
    1212                $this->knownWPBug( 20991 );
     13
     14                $this->make_user_by_role( 'subscriber' );
    1315
    1416                $result = $this->myxmlrpcserver->wp_getPosts( array( 1, 'subscriber', 'subscriber' ) );
     
    2325
    2426        function test_capable_user() {
     27                $this->make_user_by_role( 'editor' );
     28
    2529                $result = $this->myxmlrpcserver->wp_getPosts( array( 1, 'editor', 'editor' ) );
    2630                $this->assertNotInstanceOf( 'IXR_Error', $result );
     
    2832
    2933        function test_invalid_post_type() {
     34                $this->make_user_by_role( 'editor' );
     35
    3036                $filter = array( 'post_type' => 'invalid_post_type_name' );
    3137                $result = $this->myxmlrpcserver->wp_getPosts( array( 1, 'editor', 'editor', $filter ) );
     
    3440
    3541        function test_filters() {
     42                $this->make_user_by_role( 'editor' );
     43
    3644                $cpt_name = 'test_wp_getposts_cpt';
    3745                register_post_type( $cpt_name, array(
     
    4149
    4250                $num_posts = 17;
    43                 $this->_insert_quick_posts( $num_posts, $cpt_name );
     51                $post_ids = $this->factory->post->create_many( $num_posts, array( 'post_type' => $cpt_name ) );
    4452
    4553                // get them all
     
    6068                        $filter['offset'] += $filter['number'];
    6169                } while ( count( $presults ) > 0 );
    62                 // verify that $post_ids (populated by _insert_quick_posts) matches $posts_found
    63                 $this->assertEquals( 0, count( array_diff( $this->post_ids, $posts_found ) ) );
     70                // verify that $post_ids matches $posts_found
     71                $this->assertEquals( 0, count( array_diff( $post_ids, $posts_found ) ) );
    6472
    6573                // add comments to some of the posts
    66                 $random_posts = array_rand( $this->post_ids, $num_posts / 2 );
     74                $random_posts = array_rand( $post_ids, $num_posts / 2 );
    6775                foreach ( $random_posts as $i ) {
    68                         $post = $this->post_ids[$i];
    69                         $this->_insert_quick_comments( $post, rand( 1, 20 ) );
     76                        $post = $post_ids[$i];
     77                        $this->factory->comment->create_post_comments( $post, rand( 1, 20 ) );
    7078                }
    7179
     
    8290
    8391                // set one of the posts to draft and get drafts
    84                 $post = get_post( $this->post_ids[$random_posts[0]] );
     92                $post = get_post( $post_ids[$random_posts[0]] );
    8593                $post->post_status = 'draft';
    8694                wp_update_post( $post );
     
    93101
    94102        function test_fields() {
    95                 $this->_insert_quick_posts( 1 );
     103                $this->make_user_by_role( 'editor' );
     104                $this->factory->post->create();
    96105
    97106                // check default fields
  • trunk/wp-testcase/test-xmlrpc-api/test_wp_getTaxonomies.php

    r700 r768  
    11<?php
    22
    3 class TestXMLRPCServer_wp_getTaxonomies extends WPXMLRPCServerTestCase {
     3class TestXMLRPCServer_wp_getTaxonomies extends WP_XMLRPC_UnitTestCase {
    44
    55        function test_invalid_username_password() {
     
    1010
    1111        function test_taxonomy_validated() {
     12                $this->make_user_by_role( 'editor' );
     13
    1214                $result = $this->myxmlrpcserver->wp_getTaxonomies( array( 1, 'editor', 'editor' ) );
    1315                $this->assertNotInstanceOf( 'IXR_Error', $result );
  • trunk/wp-testcase/test-xmlrpc-api/test_wp_getTaxonomy.php

    r732 r768  
    11<?php
    22
    3 class TestXMLRPCServer_wp_getTaxonomy extends WPXMLRPCServerTestCase {
     3class TestXMLRPCServer_wp_getTaxonomy extends WP_XMLRPC_UnitTestCase {
    44
    55        function test_invalid_username_password() {
     
    1010
    1111        function test_empty_taxonomy() {
    12                 $result = $this->myxmlrpcserver->wp_getTaxonomy( array( 1, 'subscriber', 'subscriber', '' ) );
     12                $this->make_user_by_role( 'editor' );
     13
     14                $result = $this->myxmlrpcserver->wp_getTaxonomy( array( 1, 'editor', 'editor', '' ) );
    1315                $this->assertInstanceOf( 'IXR_Error', $result );
    1416                $this->assertEquals( 403, $result->code );
     
    1719
    1820        function test_invalid_taxonomy() {
    19                 $result = $this->myxmlrpcserver->wp_getTaxonomy( array( 1, 'subscriber', 'subscriber', 'not_existing' ) );
     21                $this->make_user_by_role( 'editor' );
     22
     23                $result = $this->myxmlrpcserver->wp_getTaxonomy( array( 1, 'editor', 'editor', 'not_existing' ) );
    2024                $this->assertInstanceOf( 'IXR_Error', $result );
    2125                $this->assertEquals( 403, $result->code );
     
    2428
    2529        function test_incapable_user() {
     30                $this->make_user_by_role( 'subscriber' );
     31
    2632                $result = $this->myxmlrpcserver->wp_getTaxonomy( array( 1, 'subscriber', 'subscriber', 'category' ) );
    2733                $this->assertInstanceOf( 'IXR_Error', $result );
     
    3137
    3238        function test_taxonomy_validated() {
     39                $this->make_user_by_role( 'editor' );
     40
    3341                $result = $this->myxmlrpcserver->wp_getTaxonomy( array( 1, 'editor', 'editor', 'category' ) );
    3442                $this->assertNotInstanceOf( 'IXR_Error', $result );
     
    3644
    3745        function test_prepare_taxonomy() {
     46                $this->make_user_by_role( 'editor' );
     47
    3848                $result = $this->myxmlrpcserver->wp_getTaxonomy( array( 1, 'editor', 'editor', 'category' ) );
    3949                $taxonomy = get_taxonomy( 'category' );
  • trunk/wp-testcase/test-xmlrpc-api/test_wp_getTerm.php

    r735 r768  
    11<?php
    22
    3 class TestXMLRPCServer_wp_getTerm extends WPXMLRPCServerTestCase {
     3class TestXMLRPCServer_wp_getTerm extends WP_XMLRPC_UnitTestCase {
    44        var $term;
    55
     
    88
    99                $this->term = wp_insert_term( 'term' . rand_str() , 'category' );
    10         }
    11 
    12         function tearDown() {
    13                 parent::tearDown();
    14 
    15                 wp_delete_term( $this->term['term_id'], 'category' );
    1610        }
    1711
     
    2317
    2418        function test_empty_taxonomy() {
    25                 $result = $this->myxmlrpcserver->wp_getTerm( array( 1, 'subscriber', 'subscriber', '', 0 ) );
     19                $this->make_user_by_role( 'editor' );
     20
     21                $result = $this->myxmlrpcserver->wp_getTerm( array( 1, 'editor', 'editor', '', 0 ) );
    2622                $this->assertInstanceOf( 'IXR_Error', $result );
    2723                $this->assertEquals( 403, $result->code );
     
    3026
    3127        function test_invalid_taxonomy() {
    32                 $result = $this->myxmlrpcserver->wp_getTerm( array( 1, 'subscriber', 'subscriber', 'not_existing', 0 ) );
     28                $this->make_user_by_role( 'editor' );
     29
     30                $result = $this->myxmlrpcserver->wp_getTerm( array( 1, 'editor', 'editor', 'not_existing', 0 ) );
    3331                $this->assertInstanceOf( 'IXR_Error', $result );
    3432                $this->assertEquals( 403, $result->code );
     
    3735
    3836        function test_incapable_user() {
     37                $this->make_user_by_role( 'subscriber' );
     38
    3939                $result = $this->myxmlrpcserver->wp_getTerm( array( 1, 'subscriber', 'subscriber', 'category', $this->term['term_id'] ) );
    4040                $this->assertInstanceOf( 'IXR_Error', $result );
     
    4545
    4646        function test_empty_term() {
     47                $this->make_user_by_role( 'editor' );
     48
    4749                $result = $this->myxmlrpcserver->wp_getTerm( array( 1, 'editor', 'editor', 'category', '' ) );
    4850                $this->assertInstanceOf( 'IXR_Error', $result );
     
    5254
    5355        function test_invalid_term() {
     56                $this->make_user_by_role( 'editor' );
     57
    5458                $result = $this->myxmlrpcserver->wp_getTerm( array( 1, 'editor', 'editor', 'category', 9999 ) );
    5559                $this->assertInstanceOf( 'IXR_Error', $result );
     
    5963
    6064        function test_valid_term() {
     65                $this->make_user_by_role( 'editor' );
     66
    6167                $term = get_term( $this->term['term_id'], 'category', ARRAY_A );
    6268
  • trunk/wp-testcase/test-xmlrpc-api/test_wp_getTerms.php

    r739 r768  
    11<?php
    22
    3 class TestXMLRPCServer_wp_getTerms extends WPXMLRPCServerTestCase {
     3class TestXMLRPCServer_wp_getTerms extends WP_XMLRPC_UnitTestCase {
    44
    55        function test_invalid_username_password() {
     
    1010
    1111        function test_empty_taxonomy() {
     12                $this->make_user_by_role( 'editor' );
     13
    1214                $result = $this->myxmlrpcserver->wp_getTerms( array( 1, 'editor', 'editor', '' ) );
    1315                $this->assertInstanceOf( 'IXR_Error', $result );
     
    1719
    1820        function test_invalid_taxonomy() {
     21                $this->make_user_by_role( 'editor' );
     22
    1923                $result = $this->myxmlrpcserver->wp_getTerms( array( 1, 'editor', 'editor', 'not_existing' ) );
    2024                $this->assertInstanceOf( 'IXR_Error', $result );
     
    2428
    2529        function test_incapable_user() {
     30                $this->make_user_by_role( 'subscriber' );
     31
    2632                $result = $this->myxmlrpcserver->wp_getTerms( array( 1, 'subscriber', 'subscriber', 'category' ) );
    2733                $this->assertInstanceOf( 'IXR_Error', $result );
     
    3137
    3238        function test_valid_terms() {
     39                $this->make_user_by_role( 'editor' );
     40
    3341                // make sure there's at least one category
    3442                $cat = wp_insert_term( 'term' . rand_str() , 'category' );
     
    4654                        $this->assertStringMatchesFormat( '%d', $term['parent'] );
    4755                }
    48 
    49                 wp_delete_term( $cat['term_id'], 'category' );
    5056        }
    5157
    5258        function test_custom_taxonomy() {
     59                $this->make_user_by_role( 'editor' );
     60
    5361                // create a taxonomy and some terms for it
    5462                $tax_name = 'wp_getTerms_custom_taxonomy';
     
    9199
    92100        function test_term_ordering() {
     101                $this->make_user_by_role( 'editor' );
     102
    93103                $cat1 = wp_create_category( 'wp.getTerms_' . rand_str( 16 ) );
    94104                $cat2 = wp_create_category( 'wp.getTerms_' . rand_str( 16 ) );
    95105
    96                 $this->_insert_quick_posts( 5, 'post', array( 'post_category' => array( $cat1 ) ) );
    97                 $this->_insert_quick_posts( 3, 'post', array( 'post_category' => array( $cat2 ) ) );
     106                $this->factory->post->create_many( 5, array( 'post_category' => array( $cat1 ) ) );
     107                $this->factory->post->create_many( 3, array( 'post_category' => array( $cat2 ) ) );
    98108
    99109                $filter = array( 'orderby' => 'count', 'order' => 'DESC' );
     
    110120                        }
    111121                }
    112 
    113                 wp_delete_category( $cat1 );
    114                 wp_delete_category( $cat2 );
    115122        }
    116123
    117124        function test_terms_search() {
     125                $this->make_user_by_role( 'editor' );
     126
    118127                $name = rand_str( 30 );
    119128                $name_id = wp_create_category( $name );
     
    134143                $this->assertEquals( $name, $results2[0]['name'] );
    135144                $this->assertEquals( $name_id, $results2[0]['term_id'] );
    136 
    137                 wp_delete_category( $name_id );
    138145        }
    139146}
  • trunk/wp-testcase/test-xmlrpc-api/test_wp_newPost.php

    r739 r768  
    11<?php
    22
    3 class TestXMLRPCServer_wp_newPost extends WPXMLRPCServerTestCase {
     3class TestXMLRPCServer_wp_newPost extends WP_XMLRPC_UnitTestCase {
    44
    55        function test_invalid_username_password() {
     
    1010
    1111        function test_incapable_user() {
     12                $this->make_user_by_role( 'subscriber' );
     13
    1214                $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'subscriber', 'subscriber', array() ) );
    1315                $this->assertInstanceOf( 'IXR_Error', $result );
     
    1618
    1719        function test_no_content() {
     20                $this->make_user_by_role( 'author' );
     21
    1822                $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'author', 'author', array() ) );
    1923                $this->assertInstanceOf( 'IXR_Error', $result );
     
    2327
    2428        function test_basic_content() {
     29                $this->make_user_by_role( 'author' );
     30
    2531                $post = array( 'post_title' => 'Test' );
    2632                $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'author', 'author', $post ) );
     
    3036
    3137        function test_ignore_id() {
     38                $this->make_user_by_role( 'author' );
     39
    3240                $post = array( 'post_title' => 'Test', 'ID' => 103948 );
    3341                $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'author', 'author', $post ) );
     
    3745
    3846        function test_capable_publish() {
     47                $this->make_user_by_role( 'author' );
     48
    3949                $post = array( 'post_title' => 'Test', 'post_status' => 'publish' );
    4050                $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'author', 'author', $post ) );
     
    4353
    4454        function test_incapable_publish() {
     55                $this->make_user_by_role( 'contributor' );
     56
    4557                $post = array( 'post_title' => 'Test', 'post_status' => 'publish' );
    4658                $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'contributor', 'contributor', $post ) );
     
    5062
    5163        function test_capable_private() {
     64                $this->make_user_by_role( 'editor' );
     65
    5266                $post = array( 'post_title' => 'Test', 'post_status' => 'private' );
    5367                $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'editor', 'editor', $post ) );
     
    5670
    5771        function test_incapable_private() {
     72                $this->make_user_by_role( 'contributor' );
     73
    5874                $post = array( 'post_title' => 'Test', 'post_status' => 'private' );
    5975                $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'contributor', 'contributor', $post ) );
     
    6379
    6480        function test_capable_other_author() {
    65                 $other_author_id = get_user_by( 'login', 'author' )->ID;
     81                $other_author_id = $this->make_user_by_role( 'author' );
     82                $this->make_user_by_role( 'editor' );
     83
    6684                $post = array( 'post_title' => 'Test', 'post_author' => $other_author_id );
    6785                $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'editor', 'editor', $post ) );
     
    7088
    7189        function test_incapable_other_author() {
    72                 $other_author_id = get_user_by( 'login', 'author' )->ID;
     90                $other_author_id = $this->make_user_by_role( 'author' );
     91                $this->make_user_by_role( 'contributor' );
     92
    7393                $post = array( 'post_title' => 'Test', 'post_author' => $other_author_id );
    7494                $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'contributor', 'contributor', $post ) );
     
    7898
    7999        function test_invalid_author() {
     100                $this->make_user_by_role( 'editor' );
     101
    80102                $post = array( 'post_title' => 'Test', 'post_author' => 99999999 );
    81103                $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'editor', 'editor', $post ) );
     
    85107
    86108        function test_empty_author() {
    87                 $my_author_id = get_user_by( 'login', 'author' )->ID;
     109                $my_author_id = $this->make_user_by_role( 'author' );
     110
    88111                $post = array( 'post_title' => 'Test' );
    89112                $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'author', 'author', $post ) );
     
    98121        function test_post_thumbnail() {
    99122                add_theme_support( 'post-thumbnails' );
     123
     124                $this->make_user_by_role( 'author' );
    100125
    101126                // create attachment
     
    122147
    123148        function test_invalid_post_status() {
     149                $this->make_user_by_role( 'author' );
     150
    124151                $post = array( 'post_title' => 'Test', 'post_status' => 'foobar_status' );
    125152                $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'author', 'author', $post ) );
     
    129156
    130157        function test_incapable_sticky() {
     158                $this->make_user_by_role( 'contributor' );
     159
    131160                $post = array( 'post_title' => 'Test', 'sticky' => true );
    132161                $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'contributor', 'contributor', $post ) );
     
    136165
    137166        function test_capable_sticky() {
     167                $this->make_user_by_role( 'editor' );
     168
    138169                $post = array( 'post_title' => 'Test', 'sticky' => true );
    139170                $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'editor', 'editor', $post ) );
     
    143174
    144175        function test_private_sticky() {
     176                $this->make_user_by_role( 'editor' );
     177
    145178                $post = array( 'post_title' => 'Test', 'post_status' => 'private', 'sticky' => true );
    146179                $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'editor', 'editor', $post ) );
     
    150183
    151184        function test_post_format() {
     185                $this->make_user_by_role( 'editor' );
     186
    152187                $post = array( 'post_title' => 'Test', 'post_format' => 'quote' );
    153188                $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'editor', 'editor', $post ) );
     
    157192
    158193        function test_invalid_post_format() {
     194                $this->make_user_by_role( 'editor' );
     195
    159196                $post = array( 'post_title' => 'Test', 'post_format' => 'tumblr' );
    160197                $result = $this->myxmlrpcserver->wp_newPost( array( 1, 'editor', 'editor', $post ) );
     
    164201
    165202        function test_invalid_taxonomy() {
     203                $this->make_user_by_role( 'editor' );
     204
    166205                $post = array(
    167206                        'post_title' => 'Test',
     
    186225
    187226        function test_invalid_term_id() {
     227                $this->make_user_by_role( 'editor' );
     228
    188229                $post = array(
    189230                        'post_title' => 'Test',
     
    198239
    199240        function test_terms() {
     241                $this->make_user_by_role( 'editor' );
     242
    200243                $tag1 = wp_create_tag ( rand_str( 30 ) );
    201244                $tag2 = wp_create_tag ( rand_str( 30 ) );
     
    218261
    219262        function test_terms_names() {
     263                $this->make_user_by_role( 'editor' );
     264
    220265                $ambiguous_name = rand_str( 30 );
    221266                $parent_cat = wp_create_category( $ambiguous_name );
     
    253298                $this->assertInstanceOf( 'IXR_Error', $result2 );
    254299                $this->assertEquals( 401, $result2->code );
    255 
    256                 // cleanup
    257                 wp_delete_term( $child_cat, 'category' );
    258                 wp_delete_term( $cat1, 'category' );
    259                 wp_delete_term( $cat2->term_id, 'category' );
    260                 wp_delete_term( $parent_cat, 'category' );
    261300        }
    262301
  • trunk/wp-testcase/test-xmlrpc-api/test_wp_newTerm.php

    r732 r768  
    11<?php
    22
    3 class TestXMLRPCServer_wp_newTerm extends WPXMLRPCServerTestCase {
    4         var $term_ids = array();
     3class TestXMLRPCServer_wp_newTerm extends WP_XMLRPC_UnitTestCase {
    54        var $parent_term;
    65
    76        function setUp() {
    87                parent::setUp();
    9                 $this->term_ids = array();
     8
    109                $this->parent_term = wp_insert_term( 'parent' . rand_str(), 'category' );
    1110                $this->parent_term = $this->parent_term['term_id'];
    12         }
    13 
    14         function tearDown() {
    15                 parent::tearDown();
    16 
    17                 wp_delete_term( $this->parent_term, 'category' );
    18                 foreach ( $this->term_ids as $term_id )
    19                         wp_delete_term( $term_id, 'category' );
    2011        }
    2112
     
    2718
    2819        function test_empty_taxonomy() {
    29                 $result = $this->myxmlrpcserver->wp_newTerm( array( 1, 'subscriber', 'subscriber', array( 'taxonomy' => '' ) ) );
     20                $this->make_user_by_role( 'editor' );
     21
     22                $result = $this->myxmlrpcserver->wp_newTerm( array( 1, 'editor', 'editor', array( 'taxonomy' => '' ) ) );
    3023                $this->assertInstanceOf( 'IXR_Error', $result );
    3124                $this->assertEquals( 403, $result->code );
     
    3427
    3528        function test_invalid_taxonomy() {
    36                 $result = $this->myxmlrpcserver->wp_newTerm( array( 1, 'subscriber', 'subscriber', array( 'taxonomy' => 'not_existing' ) ) );
     29                $this->make_user_by_role( 'editor' );
     30
     31                $result = $this->myxmlrpcserver->wp_newTerm( array( 1, 'editor', 'editor', array( 'taxonomy' => 'not_existing' ) ) );
    3732                $this->assertInstanceOf( 'IXR_Error', $result );
    3833                $this->assertEquals( 403, $result->code );
     
    4136
    4237        function test_incapable_user() {
     38                $this->make_user_by_role( 'subscriber' );
     39
    4340                $result = $this->myxmlrpcserver->wp_newTerm( array( 1, 'subscriber', 'subscriber', array( 'taxonomy' => 'category' ) ) );
    4441                $this->assertInstanceOf( 'IXR_Error', $result );
     
    4845
    4946        function test_empty_term() {
     47                $this->make_user_by_role( 'editor' );
     48
    5049                $result = $this->myxmlrpcserver->wp_newTerm( array( 1, 'editor', 'editor', array( 'taxonomy' => 'category', 'name' => '' ) ) );
    5150                $this->assertInstanceOf( 'IXR_Error', $result );
     
    5554
    5655        function test_parent_for_nonhierarchical() {
     56                $this->make_user_by_role( 'editor' );
     57
    5758                $result = $this->myxmlrpcserver->wp_newTerm( array( 1, 'editor', 'editor', array( 'taxonomy' => 'post_tag', 'parent' => $this->parent_term, 'name' => 'test' ) ) );
    5859                $this->assertInstanceOf( 'IXR_Error', $result );
     
    6263
    6364        function test_parent_invalid() {
     65                $this->make_user_by_role( 'editor' );
     66
    6467                $result = $this->myxmlrpcserver->wp_newTerm( array( 1, 'editor', 'editor', array( 'taxonomy' => 'category', 'parent' => 'dasda', 'name' => 'test' ) ) );
    6568                $this->assertInstanceOf( 'IXR_Error', $result );
     
    6871
    6972        function test_parent_not_existing() {
     73                $this->make_user_by_role( 'editor' );
     74
    7075                $result = $this->myxmlrpcserver->wp_newTerm( array( 1, 'editor', 'editor', array( 'taxonomy' => 'category', 'parent' => 9999, 'name' => 'test' ) ) );
    7176                $this->assertInstanceOf( 'IXR_Error', $result );
     
    7681
    7782        function test_add_term() {
     83                $this->make_user_by_role( 'editor' );
     84
    7885                $result = $this->myxmlrpcserver->wp_newTerm( array( 1, 'editor', 'editor', array( 'taxonomy' => 'category', 'name' => 'test' ) ) );
    7986                $this->assertNotInstanceOf( 'IXR_Error', $result );
    8087                $this->assertStringMatchesFormat( '%d', $result );
    81 
    82                 $this->term_ids[] = $result;
    8388        }
    8489
    8590        function test_add_term_with_parent() {
     91                $this->make_user_by_role( 'editor' );
     92
    8693                $result  = $this->myxmlrpcserver->wp_newTerm( array( 1, 'editor', 'editor', array( 'taxonomy' => 'category', 'parent' => $this->parent_term, 'name' => 'test' ) ) );
    8794                $this->assertNotInstanceOf( 'IXR_Error', $result );
    8895                $this->assertStringMatchesFormat( '%d', $result );
    89 
    90                 $this->term_ids[] = $result;
    9196        }
    9297
    9398        function test_add_term_with_all() {
     99                $this->make_user_by_role( 'editor' );
     100
    94101                $taxonomy = array( 'taxonomy' => 'category', 'parent' => $this->parent_term, 'name' => 'test_all', 'description' => 'Test all', 'slug' => 'test_all' );
    95102                $result  = $this->myxmlrpcserver->wp_newTerm( array( 1, 'editor', 'editor', $taxonomy ) );
    96103                $this->assertNotInstanceOf( 'IXR_Error', $result );
    97104                $this->assertStringMatchesFormat( '%d', $result );
    98 
    99                 $this->term_ids[] = $result;
    100105        }
    101106}
  • trunk/wp-testcase/test-xmlrpc-api/test_wp_uploadFile.php

    r588 r768  
    11<?php
    22
    3 class TestXMLRPCServer_wp_uploadFile extends WPXMLRPCServerTestCase {
     3class TestXMLRPCServer_wp_uploadFile extends WP_XMLRPC_UnitTestCase {
    44        function test_valid_attachment() {
     5                $this->make_user_by_role( 'editor' );
     6
    57                // create attachment
    68                $filename = ( DIR_TESTDATA.'/images/a2-small.jpg' );
Note: See TracChangeset for help on using the changeset viewer.