WordPress.org

Make WordPress Core

Changeset 519 in tests


Ignore:
Timestamp:
02/07/2012 10:49:14 AM (6 years ago)
Author:
westi
Message:

Add some simple tests for wp_getOptions

File:
1 edited

Legend:

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

    r518 r519  
    1313    }
    1414}
     15
     16class TestXMLRPCServer_wp_getOptions extends WPTestCase {
     17    var $user_ids = array();
     18
     19    function setUp() {
     20
     21        parent::setUp();
     22        // keep track of users we create
     23        $user_ids = array();
     24        $this->_flush_roles();
     25
     26        $this->orig_users = get_users_of_blog();
     27        add_filter( 'pre_option_enable_xmlrpc', '__return_true' );
     28    }
     29
     30    function tearDown() {
     31        parent::tearDown();
     32        // delete any users that were created during tests
     33        foreach ($this->user_ids as $id)
     34            wp_delete_user($id);
     35
     36        remove_filter( 'pre_option_enable_xmlrpc', '__return_true' );
     37    }
     38
     39    function _flush_roles() {
     40        // we want to make sure we're testing against the db, not just in-memory data
     41        // this will flush everything and reload it from the db
     42        unset( $GLOBALS['wp_user_roles'] );
     43    }
     44
     45    function test_invalid_username_password() {
     46        $myxmlrpcserver = new wp_xmlrpc_server();
     47        $result = $myxmlrpcserver->wp_getOptions( array( 1, 'username', 'password' ) );
     48        $this->assertInstanceOf( 'IXR_Error', $result );
     49        $this->assertEquals( 403, $result->code );
     50    }
     51
     52    function test_valid_username_password() {
     53        $this->_make_user( 'subscriber', 'subscriber', 'subscriber' );
     54        $myxmlrpcserver = new wp_xmlrpc_server();
     55        $result = $myxmlrpcserver->wp_getOptions( array( 1, 'subscriber', 'subscriber' ) );
     56        $this->assertInternalType( 'array', $result );
     57        $this->assertEquals( 'WordPress', $result['software_name']['value'] );
     58    }
     59
     60    function test_option_values() {
     61        $this->_make_user( 'subscriber', 'subscriber', 'subscriber' );
     62        $myxmlrpcserver = new wp_xmlrpc_server();
     63        $result = $myxmlrpcserver->wp_getOptions( array( 1, 'subscriber', 'subscriber', 'default_comment_status' ) );
     64        $this->assertInternalType( 'array', $result );
     65        $this->assertEquals( get_option( 'default_comment_status' ), $result['default_comment_status']['value'] );
     66    }
     67
     68}
Note: See TracChangeset for help on using the changeset viewer.