WordPress.org

Make WordPress Core

Changeset 520 in tests


Ignore:
Timestamp:
02/07/12 11:00:37 (2 years ago)
Author:
westi
Message:

Start some simple test cases for wp.newPost.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wp-testcase/test_includes_class-wp-xmlrpc-server.php

    r519 r520  
    6767 
    6868} 
     69 
     70class TestXMLRPCServer_wp_newPost extends WPTestCase { 
     71    var $user_ids = array(); 
     72 
     73    function setUp() { 
     74 
     75        parent::setUp(); 
     76        // keep track of users we create 
     77        $user_ids = array(); 
     78        $this->_flush_roles(); 
     79 
     80        $this->orig_users = get_users_of_blog(); 
     81        add_filter( 'pre_option_enable_xmlrpc', '__return_true' ); 
     82    } 
     83 
     84    function tearDown() { 
     85        parent::tearDown(); 
     86        // delete any users that were created during tests 
     87        foreach ($this->user_ids as $id) 
     88            wp_delete_user($id); 
     89 
     90        remove_filter( 'pre_option_enable_xmlrpc', '__return_true' ); 
     91    } 
     92 
     93    function _flush_roles() { 
     94        // we want to make sure we're testing against the db, not just in-memory data 
     95        // this will flush everything and reload it from the db 
     96        unset( $GLOBALS['wp_user_roles'] ); 
     97    } 
     98 
     99    function test_invalid_username_password() { 
     100        $myxmlrpcserver = new wp_xmlrpc_server(); 
     101        $result = $myxmlrpcserver->wp_newPost( array( 1, 'username', 'password' ) ); 
     102        $this->assertInstanceOf( 'IXR_Error', $result ); 
     103        $this->assertEquals( 403, $result->code ); 
     104    } 
     105 
     106    function test_incapable_user() { 
     107        $this->_make_user( 'subscriber', 'subscriber', 'subscriber' ); 
     108        $myxmlrpcserver = new wp_xmlrpc_server(); 
     109        $result = $myxmlrpcserver->wp_newPost( array( 1, 'subscriber', 'subscriber' ) ); 
     110        $this->assertInstanceOf( 'IXR_Error', $result ); 
     111        $this->assertEquals( 401, $result->code ); 
     112    } 
     113 
     114    function test_no_content() { 
     115        $this->_make_user( 'author', 'author', 'author' ); 
     116        $myxmlrpcserver = new wp_xmlrpc_server(); 
     117        $result = $myxmlrpcserver->wp_newPost( array( 1, 'author', 'author' ) ); 
     118        $this->assertInstanceOf( 'IXR_Error', $result ); 
     119        $this->assertEquals( 500, $result->code ); 
     120        $this->assertEquals( 'Content, title, and excerpt are empty.', $result->message ); 
     121    } 
     122 
     123} 
Note: See TracChangeset for help on using the changeset viewer.