WordPress.org

Make WordPress Core

Changeset 548 in tests


Ignore:
Timestamp:
02/22/12 21:44:03 (2 years ago)
Author:
maxcutler
Message:

Add a base class for XMLRPC test cases.

Files:
11 edited

Legend:

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

    r545 r548  
    11<?php 
    2 include_once(ABSPATH . 'wp-admin/includes/admin.php'); 
    3 include_once(ABSPATH . WPINC . '/class-IXR.php'); 
    4 include_once(ABSPATH . WPINC . '/class-wp-xmlrpc-server.php'); 
    52 
    6 class TestXMLRPCServer_wp_deleteTerm extends WPTestCase { 
    7     var $user_ids = array(); 
     3class TestXMLRPCServer_wp_deleteTerm extends WPXMLRPCServerTestCase { 
    84    var $term; 
    95 
    106    function setUp() { 
    117        parent::setUp(); 
    12         // keep track of users we create 
    13         $this->user_ids = array(); 
    14         $this->_flush_roles(); 
    15  
    16         $this->orig_users = get_users_of_blog(); 
    17         add_filter( 'pre_option_enable_xmlrpc', '__return_true' ); 
    18  
    19         $this->_make_user( 'subscriber', 'subscriber', 'subscriber' ); 
    20         $this->_make_user( 'contributor', 'contributor', 'contributor' ); 
    21         $this->_make_user( 'author', 'author', 'author' ); 
    22         $this->_make_user( 'editor', 'editor', 'editor' ); 
    238 
    249        $this->term = wp_insert_term( 'term' . rand_str() , 'category' ); 
    25  
    26         $this->myxmlrpcserver = new wp_xmlrpc_server(); 
    2710    } 
    2811 
    2912    function tearDown() { 
    3013        parent::tearDown(); 
    31         // delete any users that were created during tests 
    32         foreach ( $this->user_ids as $id ) 
    33             wp_delete_user($id); 
    3414 
    3515        wp_delete_term( $this->term['term_id'], 'category' ); 
    36  
    37         remove_filter( 'pre_option_enable_xmlrpc', '__return_true' ); 
    38     } 
    39  
    40     function _flush_roles() { 
    41         // we want to make sure we're testing against the db, not just in-memory data 
    42         // this will flush everything and reload it from the db 
    43         unset( $GLOBALS['wp_user_roles'] ); 
    4416    } 
    4517 
  • wp-testcase/test-xmlrpc-api/test_wp_editPost.php

    r528 r548  
    11<?php 
    2 include_once(ABSPATH . 'wp-admin/includes/admin.php'); 
    3 include_once(ABSPATH . WPINC . '/class-IXR.php'); 
    4 include_once(ABSPATH . WPINC . '/class-wp-xmlrpc-server.php'); 
    52 
    6 class TestXMLRPCServer_wp_editPost extends WPTestCase { 
    7     var $user_ids = array(); 
    8  
    9     function setUp() { 
    10  
    11         parent::setUp(); 
    12         // keep track of users we create 
    13         $this->user_ids = array(); 
    14         $this->_flush_roles(); 
    15  
    16         $this->orig_users = get_users_of_blog(); 
    17         add_filter( 'pre_option_enable_xmlrpc', '__return_true' ); 
    18  
    19         $this->_make_user( 'subscriber', 'subscriber', 'subscriber' ); 
    20         $this->_make_user( 'contributor', 'contributor', 'contributor' ); 
    21         $this->_make_user( 'author', 'author', 'author' ); 
    22         $this->_make_user( 'editor', 'editor', 'editor' ); 
    23  
    24         $this->myxmlrpcserver = new wp_xmlrpc_server(); 
    25     } 
    26  
    27     function tearDown() { 
    28         parent::tearDown(); 
    29         // delete any users that were created during tests 
    30         foreach ($this->user_ids as $id) 
    31             wp_delete_user($id); 
    32  
    33         remove_filter( 'pre_option_enable_xmlrpc', '__return_true' ); 
    34     } 
    35  
    36     function _flush_roles() { 
    37         // we want to make sure we're testing against the db, not just in-memory data 
    38         // this will flush everything and reload it from the db 
    39         unset( $GLOBALS['wp_user_roles'] ); 
    40     } 
     3class TestXMLRPCServer_wp_editPost extends WPXMLRPCServerTestCase { 
    414 
    425    function test_invalid_username_password() { 
  • wp-testcase/test-xmlrpc-api/test_wp_editTerm.php

    r545 r548  
    11<?php 
    2 include_once(ABSPATH . 'wp-admin/includes/admin.php'); 
    3 include_once(ABSPATH . WPINC . '/class-IXR.php'); 
    4 include_once(ABSPATH . WPINC . '/class-wp-xmlrpc-server.php'); 
    52 
    6 class TestXMLRPCServer_wp_editTerm extends WPTestCase { 
    7     var $user_ids = array(); 
    8  
     3class TestXMLRPCServer_wp_editTerm extends WPXMLRPCServerTestCase { 
    94    var $parent_term; 
    105    var $child_term; 
     
    138    function setUp() { 
    149        parent::setUp(); 
    15         // keep track of users we create 
    16         $this->user_ids = array(); 
    17         $this->_flush_roles(); 
    18  
    19         $this->orig_users = get_users_of_blog(); 
    20         add_filter( 'pre_option_enable_xmlrpc', '__return_true' ); 
    21  
    22         $this->_make_user( 'subscriber', 'subscriber', 'subscriber' ); 
    23         $this->_make_user( 'contributor', 'contributor', 'contributor' ); 
    24         $this->_make_user( 'author', 'author', 'author' ); 
    25         $this->_make_user( 'editor', 'editor', 'editor' ); 
    2610 
    2711        $this->parent_term = wp_insert_term( 'parent' . rand_str() , 'category' ); 
    2812        $this->child_term = wp_insert_term( 'child' . rand_str() , 'category' ); 
    2913        $this->post_tag = wp_insert_term( 'test' . rand_str() , 'post_tag' ); 
    30  
    31         $this->myxmlrpcserver = new wp_xmlrpc_server(); 
    3214    } 
    3315 
    3416    function tearDown() { 
    3517        parent::tearDown(); 
    36         // delete any users that were created during tests 
    37         foreach ($this->user_ids as $id) 
    38             wp_delete_user($id); 
    3918 
    4019        wp_delete_term( $this->parent_term['term_id'], 'category' ); 
    4120        wp_delete_term( $this->child_term['term_id'], 'category' ); 
    4221        wp_delete_term( $this->post_tag['term_id'], 'post_tag' ); 
    43  
    44         remove_filter( 'pre_option_enable_xmlrpc', '__return_true' ); 
    4522    } 
    46  
    47     function _flush_roles() { 
    48         // we want to make sure we're testing against the db, not just in-memory data 
    49         // this will flush everything and reload it from the db 
    50         unset( $GLOBALS['wp_user_roles'] ); 
    51     } 
    52  
    5323 
    5424    function test_invalid_username_password() { 
  • wp-testcase/test-xmlrpc-api/test_wp_getOptions.php

    r523 r548  
    11<?php 
    2 include_once(ABSPATH . 'wp-admin/includes/admin.php'); 
    3 include_once(ABSPATH . WPINC . '/class-IXR.php'); 
    4 include_once(ABSPATH . WPINC . '/class-wp-xmlrpc-server.php'); 
    52 
    6 class TestXMLRPCServer_wp_getOptions extends WPTestCase { 
    7     var $user_ids = array(); 
    8  
    9     function setUp() { 
    10  
    11         parent::setUp(); 
    12         // keep track of users we create 
    13         $this->user_ids = array(); 
    14         $this->_flush_roles(); 
    15  
    16         $this->orig_users = get_users_of_blog(); 
    17         add_filter( 'pre_option_enable_xmlrpc', '__return_true' ); 
    18     } 
    19  
    20     function tearDown() { 
    21         parent::tearDown(); 
    22         // delete any users that were created during tests 
    23         foreach ($this->user_ids as $id) 
    24             wp_delete_user($id); 
    25  
    26         remove_filter( 'pre_option_enable_xmlrpc', '__return_true' ); 
    27     } 
    28  
    29     function _flush_roles() { 
    30         // we want to make sure we're testing against the db, not just in-memory data 
    31         // this will flush everything and reload it from the db 
    32         unset( $GLOBALS['wp_user_roles'] ); 
    33     } 
     3class TestXMLRPCServer_wp_getOptions extends WPXMLRPCServerTestCase { 
    344 
    355    function test_invalid_username_password() { 
    36         $myxmlrpcserver = new wp_xmlrpc_server(); 
    37         $result = $myxmlrpcserver->wp_getOptions( array( 1, 'username', 'password' ) ); 
     6        $result = $this->myxmlrpcserver->wp_getOptions( array( 1, 'username', 'password' ) ); 
    387        $this->assertInstanceOf( 'IXR_Error', $result ); 
    398        $this->assertEquals( 403, $result->code ); 
     
    4110 
    4211    function test_valid_username_password() { 
    43         $this->_make_user( 'subscriber', 'subscriber', 'subscriber' ); 
    44         $myxmlrpcserver = new wp_xmlrpc_server(); 
    45         $result = $myxmlrpcserver->wp_getOptions( array( 1, 'subscriber', 'subscriber' ) ); 
     12        $result = $this->myxmlrpcserver->wp_getOptions( array( 1, 'subscriber', 'subscriber' ) ); 
    4613        $this->assertInternalType( 'array', $result ); 
    4714        $this->assertEquals( 'WordPress', $result['software_name']['value'] ); 
     
    4916 
    5017    function test_option_values() { 
    51         $this->_make_user( 'subscriber', 'subscriber', 'subscriber' ); 
    52         $myxmlrpcserver = new wp_xmlrpc_server(); 
    53         $result = $myxmlrpcserver->wp_getOptions( array( 1, 'subscriber', 'subscriber', 'default_comment_status' ) ); 
     18        $result = $this->myxmlrpcserver->wp_getOptions( array( 1, 'subscriber', 'subscriber', 'default_comment_status' ) ); 
    5419        $this->assertInternalType( 'array', $result ); 
    5520        $this->assertEquals( get_option( 'default_comment_status' ), $result['default_comment_status']['value'] ); 
  • wp-testcase/test-xmlrpc-api/test_wp_getTaxonomies.php

    r539 r548  
    11<?php 
    2 include_once(ABSPATH . 'wp-admin/includes/admin.php'); 
    3 include_once(ABSPATH . WPINC . '/class-IXR.php'); 
    4 include_once(ABSPATH . WPINC . '/class-wp-xmlrpc-server.php'); 
    52 
    6 class TestXMLRPCServer_wp_getTaxonomies extends WPTestCase { 
    7     var $user_ids = array(); 
    8  
    9     function setUp() { 
    10         parent::setUp(); 
    11         // keep track of users we create 
    12         $this->user_ids = array(); 
    13         $this->_flush_roles(); 
    14  
    15         $this->orig_users = get_users_of_blog(); 
    16         add_filter( 'pre_option_enable_xmlrpc', '__return_true' ); 
    17  
    18         $this->_make_user( 'subscriber', 'subscriber', 'subscriber' ); 
    19         $this->_make_user( 'contributor', 'contributor', 'contributor' ); 
    20         $this->_make_user( 'author', 'author', 'author' ); 
    21         $this->_make_user( 'editor', 'editor', 'editor' ); 
    22  
    23         $this->myxmlrpcserver = new wp_xmlrpc_server(); 
    24     } 
    25  
    26     function tearDown() { 
    27         parent::tearDown(); 
    28         // delete any users that were created during tests 
    29         foreach ( $this->user_ids as $id ) 
    30             wp_delete_user($id); 
    31  
    32         remove_filter( 'pre_option_enable_xmlrpc', '__return_true' ); 
    33     } 
    34  
    35     function _flush_roles() { 
    36         // we want to make sure we're testing against the db, not just in-memory data 
    37         // this will flush everything and reload it from the db 
    38         unset( $GLOBALS['wp_user_roles'] ); 
    39     } 
     3class TestXMLRPCServer_wp_getTaxonomies extends WPXMLRPCServerTestCase { 
    404 
    415    function test_invalid_username_password() { 
  • wp-testcase/test-xmlrpc-api/test_wp_getTaxonomy.php

    r538 r548  
    11<?php 
    2 include_once(ABSPATH . 'wp-admin/includes/admin.php'); 
    3 include_once(ABSPATH . WPINC . '/class-IXR.php'); 
    4 include_once(ABSPATH . WPINC . '/class-wp-xmlrpc-server.php'); 
    52 
    6 class TestXMLRPCServer_wp_getTaxonomy extends WPTestCase { 
    7     var $user_ids = array(); 
    8  
    9     function setUp() { 
    10         parent::setUp(); 
    11         // keep track of users we create 
    12         $this->user_ids = array(); 
    13         $this->_flush_roles(); 
    14  
    15         $this->orig_users = get_users_of_blog(); 
    16         add_filter( 'pre_option_enable_xmlrpc', '__return_true' ); 
    17  
    18         $this->_make_user( 'subscriber', 'subscriber', 'subscriber' ); 
    19         $this->_make_user( 'contributor', 'contributor', 'contributor' ); 
    20         $this->_make_user( 'author', 'author', 'author' ); 
    21         $this->_make_user( 'editor', 'editor', 'editor' ); 
    22  
    23         $this->myxmlrpcserver = new wp_xmlrpc_server(); 
    24     } 
    25  
    26     function tearDown() { 
    27         parent::tearDown(); 
    28         // delete any users that were created during tests 
    29         foreach ( $this->user_ids as $id ) 
    30             wp_delete_user($id); 
    31  
    32         remove_filter( 'pre_option_enable_xmlrpc', '__return_true' ); 
    33     } 
    34  
    35     function _flush_roles() { 
    36         // we want to make sure we're testing against the db, not just in-memory data 
    37         // this will flush everything and reload it from the db 
    38         unset( $GLOBALS['wp_user_roles'] ); 
    39     } 
     3class TestXMLRPCServer_wp_getTaxonomy extends WPXMLRPCServerTestCase { 
    404 
    415    function test_invalid_username_password() { 
     
    6630    } 
    6731 
    68  
    6932    function test_taxonomy_validated() { 
    7033        $result = $this->myxmlrpcserver->wp_getTaxonomy( array( 1, 'editor', 'editor', 'category' ) ); 
  • wp-testcase/test-xmlrpc-api/test_wp_getTerm.php

    r543 r548  
    11<?php 
    2 include_once(ABSPATH . 'wp-admin/includes/admin.php'); 
    3 include_once(ABSPATH . WPINC . '/class-IXR.php'); 
    4 include_once(ABSPATH . WPINC . '/class-wp-xmlrpc-server.php'); 
    52 
    6 class TestXMLRPCServer_wp_getTerm extends WPTestCase { 
    7     var $user_ids = array(); 
     3class TestXMLRPCServer_wp_getTerm extends WPXMLRPCServerTestCase { 
    84    var $term; 
    95 
    106    function setUp() { 
    117        parent::setUp(); 
    12         // keep track of users we create 
    13         $this->user_ids = array(); 
    14         $this->_flush_roles(); 
    15  
    16         $this->orig_users = get_users_of_blog(); 
    17         add_filter( 'pre_option_enable_xmlrpc', '__return_true' ); 
    18  
    19         $this->_make_user( 'subscriber', 'subscriber', 'subscriber' ); 
    20         $this->_make_user( 'contributor', 'contributor', 'contributor' ); 
    21         $this->_make_user( 'author', 'author', 'author' ); 
    22         $this->_make_user( 'editor', 'editor', 'editor' ); 
    238 
    249        $this->term = wp_insert_term( 'term' . rand_str() , 'category' ); 
    25  
    26         $this->myxmlrpcserver = new wp_xmlrpc_server(); 
    2710    } 
    2811 
    2912    function tearDown() { 
    3013        parent::tearDown(); 
    31         // delete any users that were created during tests 
    32         foreach ( $this->user_ids as $id ) 
    33             wp_delete_user($id); 
    3414 
    3515        wp_delete_term( $this->term['term_id'], 'category' ); 
    36  
    37         remove_filter( 'pre_option_enable_xmlrpc', '__return_true' ); 
    38     } 
    39  
    40     function _flush_roles() { 
    41         // we want to make sure we're testing against the db, not just in-memory data 
    42         // this will flush everything and reload it from the db 
    43         unset( $GLOBALS['wp_user_roles'] ); 
    4416    } 
    4517 
  • wp-testcase/test-xmlrpc-api/test_wp_getTerms.php

    r544 r548  
    11<?php 
    2 include_once(ABSPATH . 'wp-admin/includes/admin.php'); 
    3 include_once(ABSPATH . WPINC . '/class-IXR.php'); 
    4 include_once(ABSPATH . WPINC . '/class-wp-xmlrpc-server.php'); 
    52 
    6 class TestXMLRPCServer_wp_getTerms extends WPTestCase { 
    7     var $user_ids = array(); 
     3class TestXMLRPCServer_wp_getTerms extends WPXMLRPCServerTestCase { 
    84    var $term; 
    95 
    106    function setUp() { 
    117        parent::setUp(); 
    12         // keep track of users we create 
    13         $this->user_ids = array(); 
    14         $this->_flush_roles(); 
    15  
    16         $this->orig_users = get_users_of_blog(); 
    17         add_filter( 'pre_option_enable_xmlrpc', '__return_true' ); 
    18  
    19         $this->_make_user( 'subscriber', 'subscriber', 'subscriber' ); 
    20         $this->_make_user( 'contributor', 'contributor', 'contributor' ); 
    21         $this->_make_user( 'author', 'author', 'author' ); 
    22         $this->_make_user( 'editor', 'editor', 'editor' ); 
    238 
    249        $this->term = wp_insert_term( 'term'. rand_str() , 'category' ); 
    25  
    26         $this->myxmlrpcserver = new wp_xmlrpc_server(); 
    2710    } 
    2811 
    2912    function tearDown() { 
    3013        parent::tearDown(); 
    31         // delete any users that were created during tests 
    32         foreach ( $this->user_ids as $id ) 
    33             wp_delete_user($id); 
    3414 
    3515        wp_delete_term( $this->term['term_id'], 'category' ); 
    36  
    37         remove_filter( 'pre_option_enable_xmlrpc', '__return_true' ); 
    38     } 
    39  
    40     function _flush_roles() { 
    41         // we want to make sure we're testing against the db, not just in-memory data 
    42         // this will flush everything and reload it from the db 
    43         unset( $GLOBALS['wp_user_roles'] ); 
    4416    } 
    4517 
  • wp-testcase/test-xmlrpc-api/test_wp_newPost.php

    r527 r548  
    11<?php 
    2 include_once(ABSPATH . 'wp-admin/includes/admin.php'); 
    3 include_once(ABSPATH . WPINC . '/class-IXR.php'); 
    4 include_once(ABSPATH . WPINC . '/class-wp-xmlrpc-server.php'); 
    52 
    6 class TestXMLRPCServer_wp_newPost extends WPTestCase { 
    7     var $user_ids = array(); 
    8  
    9     function setUp() { 
    10  
    11         parent::setUp(); 
    12         // keep track of users we create 
    13         $this->user_ids = array(); 
    14         $this->_flush_roles(); 
    15  
    16         $this->orig_users = get_users_of_blog(); 
    17         add_filter( 'pre_option_enable_xmlrpc', '__return_true' ); 
    18  
    19         $this->_make_user( 'subscriber', 'subscriber', 'subscriber' ); 
    20         $this->_make_user( 'contributor', 'contributor', 'contributor' ); 
    21         $this->_make_user( 'author', 'author', 'author' ); 
    22         $this->_make_user( 'editor', 'editor', 'editor' ); 
    23  
    24         $this->myxmlrpcserver = new wp_xmlrpc_server(); 
    25     } 
    26  
    27     function tearDown() { 
    28         parent::tearDown(); 
    29         // delete any users that were created during tests 
    30         foreach ($this->user_ids as $id) 
    31             wp_delete_user($id); 
    32  
    33         remove_filter( 'pre_option_enable_xmlrpc', '__return_true' ); 
    34     } 
    35  
    36     function _flush_roles() { 
    37         // we want to make sure we're testing against the db, not just in-memory data 
    38         // this will flush everything and reload it from the db 
    39         unset( $GLOBALS['wp_user_roles'] ); 
    40     } 
     3class TestXMLRPCServer_wp_newPost extends WPXMLRPCServerTestCase { 
    414 
    425    function test_invalid_username_password() { 
  • wp-testcase/test-xmlrpc-api/test_wp_newTerm.php

    r534 r548  
    11<?php 
    2 include_once(ABSPATH . 'wp-admin/includes/admin.php'); 
    3 include_once(ABSPATH . WPINC . '/class-IXR.php'); 
    4 include_once(ABSPATH . WPINC . '/class-wp-xmlrpc-server.php'); 
    52 
    6 class TestXMLRPCServer_wp_newTerm extends WPTestCase { 
    7     var $user_ids = array(); 
     3class TestXMLRPCServer_wp_newTerm extends WPXMLRPCServerTestCase { 
    84    var $term_ids = array(); 
    95    var $parent_term; 
     
    117    function setUp() { 
    128        parent::setUp(); 
    13         // keep track of users we create 
    14         $this->user_ids = array(); 
    159        $this->term_ids = array(); 
    16         $this->_flush_roles(); 
    17  
    18         $this->orig_users = get_users_of_blog(); 
    19         add_filter( 'pre_option_enable_xmlrpc', '__return_true' ); 
    20  
    21         $this->_make_user( 'subscriber', 'subscriber', 'subscriber' ); 
    22         $this->_make_user( 'contributor', 'contributor', 'contributor' ); 
    23         $this->_make_user( 'author', 'author', 'author' ); 
    24         $this->_make_user( 'editor', 'editor', 'editor' ); 
    25  
    2610        $this->parent_term = wp_insert_term( 'parent' . rand_str(), 'category' ); 
    27  
    28         $this->myxmlrpcserver = new wp_xmlrpc_server(); 
    2911    } 
    3012 
    3113    function tearDown() { 
    3214        parent::tearDown(); 
    33         // delete any users that were created during tests 
    34         foreach ( $this->user_ids as $id ) 
    35             wp_delete_user($id); 
    3615 
    3716        wp_delete_term( $this->parent_term, 'category' ); 
    3817        foreach ( $this->term_ids as $term_id ) 
    3918            wp_delete_term( $term_id, 'category' ); 
    40  
    41         remove_filter( 'pre_option_enable_xmlrpc', '__return_true' ); 
    42     } 
    43  
    44     function _flush_roles() { 
    45         // we want to make sure we're testing against the db, not just in-memory data 
    46         // this will flush everything and reload it from the db 
    47         unset( $GLOBALS['wp_user_roles'] ); 
    4819    } 
    4920 
  • wp-testlib/base.php

    r525 r548  
    582582} 
    583583 
     584/** 
     585 * Base class for XML-RPC tests. 
     586 * 
     587 * Initializes XML-RPC server instance and creates set of users. 
     588 */ 
     589abstract class WPXMLRPCServerTestCase extends WPTestCase { 
     590    var $myxmlrpcserver; 
     591    var $user_ids = array(); 
     592 
     593    function setUp() { 
     594 
     595        parent::setUp(); 
     596        // keep track of users we create 
     597        $this->user_ids = array(); 
     598        $this->_flush_roles(); 
     599 
     600        add_filter( 'pre_option_enable_xmlrpc', '__return_true' ); 
     601 
     602        $this->_make_user( 'subscriber', 'subscriber', 'subscriber' ); 
     603        $this->_make_user( 'contributor', 'contributor', 'contributor' ); 
     604        $this->_make_user( 'author', 'author', 'author' ); 
     605        $this->_make_user( 'editor', 'editor', 'editor' ); 
     606 
     607        $this->myxmlrpcserver = new wp_xmlrpc_server(); 
     608    } 
     609 
     610    function tearDown() { 
     611        parent::tearDown(); 
     612        // delete any users that were created during tests 
     613        foreach ($this->user_ids as $id) 
     614            wp_delete_user($id); 
     615 
     616        remove_filter( 'pre_option_enable_xmlrpc', '__return_true' ); 
     617    } 
     618 
     619    function _flush_roles() { 
     620        // we want to make sure we're testing against the db, not just in-memory data 
     621        // this will flush everything and reload it from the db 
     622        unset( $GLOBALS['wp_user_roles'] ); 
     623    } 
     624} 
     625 
    584626?> 
Note: See TracChangeset for help on using the changeset viewer.