Ticket #18438: term_unittests_all.patch
File term_unittests_all.patch, 27.7 KB (added by , 13 years ago) |
---|
-
wp-testcase/test-xmlrpc-api/test_wp_getTaxonomies.php
1 <?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'); 5 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->term_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 } 41 42 function test_invalid_username_password() { 43 $result = $this->myxmlrpcserver->wp_getTaxonomies( array( 1, 'username', 'password' ) ); 44 $this->assertInstanceOf( 'IXR_Error', $result ); 45 $this->assertEquals( 403, $result->code ); 46 } 47 48 function test_taxonomy_validated() { 49 $result = $this->myxmlrpcserver->wp_getTaxonomies( array( 1, 'editor', 'editor', 'category' ) ); 50 $this->assertNotInstanceOf( 'IXR_Error', $result ); 51 } 52 } 53 No newline at end of file -
wp-testcase/test-xmlrpc-api/test_wp_getTerm.php
1 <?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'); 5 6 class TestXMLRPCServer_wp_getTerm extends WPTestCase { 7 var $user_ids = array(); 8 var $term; 9 10 function setUp() { 11 parent::setUp(); 12 // keep track of users we create 13 $this->user_ids = array(); 14 $this->term_ids = array(); 15 $this->_flush_roles(); 16 17 $this->orig_users = get_users_of_blog(); 18 add_filter( 'pre_option_enable_xmlrpc', '__return_true' ); 19 20 $this->_make_user( 'subscriber', 'subscriber', 'subscriber' ); 21 $this->_make_user( 'contributor', 'contributor', 'contributor' ); 22 $this->_make_user( 'author', 'author', 'author' ); 23 $this->_make_user( 'editor', 'editor', 'editor' ); 24 25 $this->term = wp_insert_term( 'term' , 'category' ); 26 27 $this->myxmlrpcserver = new wp_xmlrpc_server(); 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 wp_delete_term( $this->term['term_id'], 'category' ); 37 38 remove_filter( 'pre_option_enable_xmlrpc', '__return_true' ); 39 } 40 41 function _flush_roles() { 42 // we want to make sure we're testing against the db, not just in-memory data 43 // this will flush everything and reload it from the db 44 unset( $GLOBALS['wp_user_roles'] ); 45 } 46 47 function test_invalid_username_password() { 48 $result = $this->myxmlrpcserver->wp_getTerm( array( 1, 'username', 'password' ) ); 49 $this->assertInstanceOf( 'IXR_Error', $result ); 50 $this->assertEquals( 403, $result->code ); 51 } 52 53 function test_empty_taxonomy() { 54 $result = $this->myxmlrpcserver->wp_getTerm( array( 1, 'subscriber', 'subscriber' ) ); 55 $this->assertInstanceOf( 'IXR_Error', $result ); 56 $this->assertEquals( 403, $result->code ); 57 $this->assertEquals( __( 'Invalid taxonomy.' ), $result->message ); 58 } 59 60 function test_invalid_taxonomy() { 61 $result = $this->myxmlrpcserver->wp_getTerm( array( 1, 'subscriber', 'subscriber', 'not_existing' ) ); 62 $this->assertInstanceOf( 'IXR_Error', $result ); 63 $this->assertEquals( 403, $result->code ); 64 $this->assertEquals( __( 'Invalid taxonomy.' ), $result->message ); 65 } 66 67 function test_incapable_user() { 68 $result = $this->myxmlrpcserver->wp_getTerm( array( 1, 'subscriber', 'subscriber', 'category', $this->term['term_id'] ) ); 69 $this->assertInstanceOf( 'IXR_Error', $result ); 70 $this->assertEquals( 401, $result->code ); 71 $this->assertEquals( __( 'You are not allowed to assign terms in this taxonomy.' ), $result->message ); 72 } 73 74 75 function test_empty_term() { 76 $result = $this->myxmlrpcserver->wp_getTerm( array( 1, 'editor', 'editor', 'category', '' ) ); 77 $this->assertInstanceOf( 'IXR_Error', $result ); 78 $this->assertEquals( 500, $result->code ); 79 $this->assertEquals( __('Empty Term'), $result->message ); 80 } 81 82 function test_invalid_term() { 83 $result = $this->myxmlrpcserver->wp_getTerm( array( 1, 'editor', 'editor', 'category', 9999 ) ); 84 $this->assertInstanceOf( 'IXR_Error', $result ); 85 $this->assertEquals( 404, $result->code ); 86 $this->assertEquals( __('Invalid term ID.'), $result->message ); 87 } 88 89 function test_term_validated() { 90 $result = $this->myxmlrpcserver->wp_getTerm( array( 1, 'editor', 'editor', 'category', $this->term['term_id'] ) ); 91 $this->assertNotInstanceOf( 'IXR_Error', $result ); 92 93 $term = (array)get_term( $this->term['term_id'], 'category' ); 94 $this->assertEquals( $result, $term ); 95 } 96 } 97 No newline at end of file -
wp-testcase/test-xmlrpc-api/test_wp_deleteTerm.php
1 <?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'); 5 6 class TestXMLRPCServer_wp_deleteTerm extends WPTestCase { 7 var $user_ids = array(); 8 var $term; 9 10 function setUp() { 11 parent::setUp(); 12 // keep track of users we create 13 $this->user_ids = array(); 14 $this->term_ids = array(); 15 $this->_flush_roles(); 16 17 $this->orig_users = get_users_of_blog(); 18 add_filter( 'pre_option_enable_xmlrpc', '__return_true' ); 19 20 $this->_make_user( 'subscriber', 'subscriber', 'subscriber' ); 21 $this->_make_user( 'contributor', 'contributor', 'contributor' ); 22 $this->_make_user( 'author', 'author', 'author' ); 23 $this->_make_user( 'editor', 'editor', 'editor' ); 24 25 $this->term = wp_insert_term( 'term' , 'category' ); 26 27 $this->myxmlrpcserver = new wp_xmlrpc_server(); 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 wp_delete_term( $this->term['term_id'], 'category' ); 37 38 remove_filter( 'pre_option_enable_xmlrpc', '__return_true' ); 39 } 40 41 function _flush_roles() { 42 // we want to make sure we're testing against the db, not just in-memory data 43 // this will flush everything and reload it from the db 44 unset( $GLOBALS['wp_user_roles'] ); 45 } 46 47 function test_invalid_username_password() { 48 $result = $this->myxmlrpcserver->wp_deleteTerm( array( 1, 'username', 'password' ) ); 49 $this->assertInstanceOf( 'IXR_Error', $result ); 50 $this->assertEquals( 403, $result->code ); 51 } 52 53 function test_empty_taxonomy() { 54 $result = $this->myxmlrpcserver->wp_deleteTerm( array( 1, 'subscriber', 'subscriber' ) ); 55 $this->assertInstanceOf( 'IXR_Error', $result ); 56 $this->assertEquals( 403, $result->code ); 57 $this->assertEquals( __( 'Invalid taxonomy.' ), $result->message ); 58 } 59 60 function test_invalid_taxonomy() { 61 $result = $this->myxmlrpcserver->wp_deleteTerm( array( 1, 'subscriber', 'subscriber', 'not_existing' ) ); 62 $this->assertInstanceOf( 'IXR_Error', $result ); 63 $this->assertEquals( 403, $result->code ); 64 $this->assertEquals( __( 'Invalid taxonomy.' ), $result->message ); 65 } 66 67 function test_incapable_user() { 68 $result = $this->myxmlrpcserver->wp_deleteTerm( array( 1, 'subscriber', 'subscriber', 'category', $this->term['term_id'] ) ); 69 $this->assertInstanceOf( 'IXR_Error', $result ); 70 $this->assertEquals( 401, $result->code ); 71 $this->assertEquals( __( 'You are not allowed to delete terms in this taxonomy.' ), $result->message ); 72 } 73 74 function test_empty_term() { 75 $result = $this->myxmlrpcserver->wp_deleteTerm( array( 1, 'editor', 'editor', 'category', '' ) ); 76 $this->assertInstanceOf( 'IXR_Error', $result ); 77 $this->assertEquals( 500, $result->code ); 78 $this->assertEquals( __('Empty Term'), $result->message ); 79 } 80 81 function test_invalid_term() { 82 $result = $this->myxmlrpcserver->wp_deleteTerm( array( 1, 'editor', 'editor', 'category', 9999 ) ); 83 $this->assertInstanceOf( 'IXR_Error', $result ); 84 $this->assertEquals( 404, $result->code ); 85 $this->assertEquals( __('Invalid term ID.'), $result->message ); 86 } 87 88 function test_term_deleted() { 89 $result = $this->myxmlrpcserver->wp_deleteTerm( array( 1, 'editor', 'editor', 'category', $this->term['term_id'] ) ); 90 $this->assertNotInstanceOf( 'IXR_Error', $result ); 91 } 92 } 93 No newline at end of file -
wp-testcase/test-xmlrpc-api/test_wp_getTerms.php
1 <?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'); 5 6 class TestXMLRPCServer_wp_getTerms extends WPTestCase { 7 var $user_ids = array(); 8 var $term; 9 10 function setUp() { 11 parent::setUp(); 12 // keep track of users we create 13 $this->user_ids = array(); 14 $this->term_ids = array(); 15 $this->_flush_roles(); 16 17 $this->orig_users = get_users_of_blog(); 18 add_filter( 'pre_option_enable_xmlrpc', '__return_true' ); 19 20 $this->_make_user( 'subscriber', 'subscriber', 'subscriber' ); 21 $this->_make_user( 'contributor', 'contributor', 'contributor' ); 22 $this->_make_user( 'author', 'author', 'author' ); 23 $this->_make_user( 'editor', 'editor', 'editor' ); 24 25 $this->term = wp_insert_term( 'term' , 'category' ); 26 27 $this->myxmlrpcserver = new wp_xmlrpc_server(); 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 wp_delete_term( $this->term['term_id'], 'category' ); 37 38 remove_filter( 'pre_option_enable_xmlrpc', '__return_true' ); 39 } 40 41 function _flush_roles() { 42 // we want to make sure we're testing against the db, not just in-memory data 43 // this will flush everything and reload it from the db 44 unset( $GLOBALS['wp_user_roles'] ); 45 } 46 47 function test_invalid_username_password() { 48 $result = $this->myxmlrpcserver->wp_getTerms( array( 1, 'username', 'password' ) ); 49 $this->assertInstanceOf( 'IXR_Error', $result ); 50 $this->assertEquals( 403, $result->code ); 51 } 52 53 function test_empty_taxonomy() { 54 $result = $this->myxmlrpcserver->wp_getTerms( array( 1, 'subscriber', 'subscriber' ) ); 55 $this->assertInstanceOf( 'IXR_Error', $result ); 56 $this->assertEquals( 403, $result->code ); 57 $this->assertEquals( __( 'Invalid taxonomy.' ), $result->message ); 58 } 59 60 function test_invalid_taxonomy() { 61 $result = $this->myxmlrpcserver->wp_getTerms( array( 1, 'subscriber', 'subscriber', 'not_existing' ) ); 62 $this->assertInstanceOf( 'IXR_Error', $result ); 63 $this->assertEquals( 403, $result->code ); 64 $this->assertEquals( __( 'Invalid taxonomy.' ), $result->message ); 65 } 66 67 function test_incapable_user() { 68 $result = $this->myxmlrpcserver->wp_getTerms( array( 1, 'subscriber', 'subscriber', 'category' ) ); 69 $this->assertInstanceOf( 'IXR_Error', $result ); 70 $this->assertEquals( 401, $result->code ); 71 $this->assertEquals( __( 'You are not allowed to assign terms in this taxonomy.' ), $result->message ); 72 } 73 74 75 function test_terms_validated() { 76 $result = $this->myxmlrpcserver->wp_getTerms( array( 1, 'editor', 'editor', 'category', $this->term['term_id'] ) ); 77 $this->assertNotInstanceOf( 'IXR_Error', $result ); 78 } 79 } 80 No newline at end of file -
wp-testcase/test-xmlrpc-api/test_wp_editTerm.php
1 <?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'); 5 6 class TestXMLRPCServer_wp_editTerm extends WPTestCase { 7 var $user_ids = array(); 8 var $term_ids = array(); 9 10 var $parent_term; 11 var $child_term; 12 var $post_tag; 13 14 function setUp() { 15 parent::setUp(); 16 // keep track of users we create 17 $this->user_ids = array(); 18 $this->_flush_roles(); 19 20 $this->orig_users = get_users_of_blog(); 21 add_filter( 'pre_option_enable_xmlrpc', '__return_true' ); 22 23 $this->_make_user( 'subscriber', 'subscriber', 'subscriber' ); 24 $this->_make_user( 'contributor', 'contributor', 'contributor' ); 25 $this->_make_user( 'author', 'author', 'author' ); 26 $this->_make_user( 'editor', 'editor', 'editor' ); 27 28 $this->parent_term = wp_insert_term( 'parent' , 'category' ); 29 $this->child_term = wp_insert_term( 'child' , 'category' ); 30 $this->post_tag = wp_insert_term( 'test' , 'post_tag' ); 31 32 $this->myxmlrpcserver = new wp_xmlrpc_server(); 33 } 34 35 function tearDown() { 36 parent::tearDown(); 37 // delete any users that were created during tests 38 foreach ($this->user_ids as $id) 39 wp_delete_user($id); 40 41 wp_delete_term( $this->parent_term['term_id'], 'category' ); 42 wp_delete_term( $this->child_term['term_id'], 'category' ); 43 wp_delete_term( $this->post_tag['term_id'], 'post_tag' ); 44 45 remove_filter( 'pre_option_enable_xmlrpc', '__return_true' ); 46 } 47 48 function _flush_roles() { 49 // we want to make sure we're testing against the db, not just in-memory data 50 // this will flush everything and reload it from the db 51 unset( $GLOBALS['wp_user_roles'] ); 52 } 53 54 55 function test_invalid_username_password() { 56 $result = $this->myxmlrpcserver->wp_editTerm( array( 1, 'username', 'password' ) ); 57 $this->assertInstanceOf( 'IXR_Error', $result ); 58 $this->assertEquals( 403, $result->code ); 59 } 60 61 function test_empty_taxonomy() { 62 $result = $this->myxmlrpcserver->wp_editTerm( array( 1, 'subscriber', 'subscriber' ) ); 63 $this->assertInstanceOf( 'IXR_Error', $result ); 64 $this->assertEquals( 403, $result->code ); 65 $this->assertEquals( __( 'Invalid taxonomy.' ), $result->message ); 66 } 67 68 function test_invalid_taxonomy() { 69 $result = $this->myxmlrpcserver->wp_editTerm( array( 1, 'subscriber', 'subscriber', $this->parent_term['term_id'], array( 'taxonomy' => 'not_existing' ) ) ); 70 $this->assertInstanceOf( 'IXR_Error', $result ); 71 $this->assertEquals( 403, $result->code ); 72 $this->assertEquals( __( 'Invalid taxonomy.' ), $result->message ); 73 } 74 75 function test_incapable_user() { 76 $result = $this->myxmlrpcserver->wp_editTerm( array( 1, 'subscriber', 'subscriber', $this->parent_term['term_id'], array( 'taxonomy' => 'category' ) ) ); 77 $this->assertInstanceOf( 'IXR_Error', $result ); 78 $this->assertEquals( 401, $result->code ); 79 $this->assertEquals( __( 'You are not allowed to edit terms in this taxonomy.' ), $result->message ); 80 } 81 82 function test_term_not_exists() { 83 $result = $this->myxmlrpcserver->wp_editTerm( array( 1, 'editor', 'editor', 9999, array( 'taxonomy' => 'category' ) ) ); 84 $this->assertInstanceOf( 'IXR_Error', $result ); 85 $this->assertEquals( 404, $result->code ); 86 $this->assertEquals( __( 'Invalid term ID.' ), $result->message ); 87 } 88 89 function test_empty_term() { 90 $result = $this->myxmlrpcserver->wp_editTerm( array( 1, 'editor', 'editor', '', array( 'taxonomy' => 'category' ) ) ); 91 $this->assertInstanceOf( 'IXR_Error', $result ); 92 $this->assertEquals( 500, $result->code ); 93 $this->assertEquals( __('Empty Term'), $result->message ); 94 } 95 96 function test_empty_term_name() { 97 $result = $this->myxmlrpcserver->wp_editTerm( array( 1, 'editor', 'editor', $this->parent_term['term_id'], array( 'taxonomy' => 'category', 'name' => '' ) ) ); 98 $this->assertInstanceOf( 'IXR_Error', $result ); 99 $this->assertEquals( 403, $result->code ); 100 $this->assertEquals( __( 'The term name cannot be empty.' ), $result->message ); 101 } 102 103 function test_parent_for_nonhierarchical() { 104 $result = $this->myxmlrpcserver->wp_editTerm( array( 1, 'editor', 'editor', $this->post_tag['term_id'], array( 'taxonomy' => 'post_tag', 'parent' => $this->parent_term['term_id'] ) ) ); 105 $this->assertInstanceOf( 'IXR_Error', $result ); 106 $this->assertEquals( 403, $result->code ); 107 $this->assertEquals( __( 'This taxonomy is not hierarchical.' ), $result->message ); 108 } 109 110 function test_parent_empty() { 111 $result = $this->myxmlrpcserver->wp_editTerm( array( 1, 'editor', 'editor', $this->child_term['term_id'], array( 'taxonomy' => 'category', 'parent' => '', 'name' => 'test' ) ) ); 112 $this->assertInstanceOf( 'IXR_Error', $result ); 113 $this->assertEquals( 500, $result->code ); 114 $this->assertEquals( __('Empty Term'), $result->message ); 115 } 116 117 function test_parent_invalid() { 118 $result = $this->myxmlrpcserver->wp_editTerm( array( 1, 'editor', 'editor', $this->child_term['term_id'], array( 'taxonomy' => 'category', 'parent' => 'dasda', 'name' => 'test' ) ) ); 119 $this->assertInstanceOf( 'IXR_Error', $result ); 120 $this->assertEquals( 500, $result->code ); 121 } 122 123 function test_parent_not_existing() { 124 $result = $this->myxmlrpcserver->wp_editTerm( array( 1, 'editor', 'editor', $this->child_term['term_id'], array( 'taxonomy' => 'category', 'parent' => 9999, 'name' => 'test' ) ) ); 125 $this->assertInstanceOf( 'IXR_Error', $result ); 126 $this->assertEquals( 403, $result->code ); 127 $this->assertEquals( __( 'Parent term does not exist.' ), $result->message ); 128 } 129 130 function test_parent_duplicate_slug() { 131 $result = $this->myxmlrpcserver->wp_editTerm( array( 1, 'editor', 'editor', $this->child_term['term_id'], array( 'taxonomy' => 'category', 'slug' => 'parent' ) ) ); 132 $this->assertInstanceOf( 'IXR_Error', $result ); 133 $this->assertEquals( 500, $result->code ); 134 $this->assertEquals( htmlspecialchars( sprintf( __('The slug “%s” is already in use by another term'), 'parent' ) ), $result->message ); 135 } 136 137 function test_edit_all_fields() { 138 $fields = array( 'taxonomy' => 'category', 'name' => 'Child 2', 'parent' => $this->parent_term['term_id'], 'description' => 'Child term', 'slug' => 'child_2' ); 139 $result = $this->myxmlrpcserver->wp_editTerm( array( 1, 'editor', 'editor', $this->child_term['term_id'], $fields ) ); 140 $this->assertNotInstanceOf( 'IXR_Error', $result ); 141 } 142 } 143 No newline at end of file -
wp-testcase/test-xmlrpc-api/test_wp_getTaxonomy.php
1 <?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'); 5 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->term_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 } 41 42 function test_invalid_username_password() { 43 $result = $this->myxmlrpcserver->wp_getTaxonomy( array( 1, 'username', 'password' ) ); 44 $this->assertInstanceOf( 'IXR_Error', $result ); 45 $this->assertEquals( 403, $result->code ); 46 } 47 48 function test_empty_taxonomy() { 49 $result = $this->myxmlrpcserver->wp_getTaxonomy( array( 1, 'subscriber', 'subscriber' ) ); 50 $this->assertInstanceOf( 'IXR_Error', $result ); 51 $this->assertEquals( 403, $result->code ); 52 $this->assertEquals( __( 'Invalid taxonomy.' ), $result->message ); 53 } 54 55 function test_invalid_taxonomy() { 56 $result = $this->myxmlrpcserver->wp_getTaxonomy( array( 1, 'subscriber', 'subscriber', 'not_existing' ) ); 57 $this->assertInstanceOf( 'IXR_Error', $result ); 58 $this->assertEquals( 403, $result->code ); 59 $this->assertEquals( __( 'Invalid taxonomy.' ), $result->message ); 60 } 61 62 function test_incapable_user() { 63 $result = $this->myxmlrpcserver->wp_getTaxonomy( array( 1, 'subscriber', 'subscriber', 'category' ) ); 64 $this->assertInstanceOf( 'IXR_Error', $result ); 65 $this->assertEquals( 401, $result->code ); 66 $this->assertEquals( __( 'You are not allowed to assign terms in this taxonomy.' ), $result->message ); 67 } 68 69 70 function test_taxonomy_validated() { 71 $result = $this->myxmlrpcserver->wp_getTaxonomy( array( 1, 'editor', 'editor', 'category' ) ); 72 $this->assertNotInstanceOf( 'IXR_Error', $result ); 73 } 74 } 75 No newline at end of file -
wp-testcase/test-xmlrpc-api/test_wp_newTerm.php
1 <?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'); 5 6 class TestXMLRPCServer_wp_newTerm extends WPTestCase { 7 var $user_ids = array(); 8 var $term_ids = array(); 9 var $parent_term; 10 11 function setUp() { 12 parent::setUp(); 13 // keep track of users we create 14 $this->user_ids = array(); 15 $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 26 $this->parent_term = wp_insert_term( 'parent' , 'category' ); 27 28 $this->myxmlrpcserver = new wp_xmlrpc_server(); 29 } 30 31 function tearDown() { 32 parent::tearDown(); 33 // delete any users that were created during tests 34 foreach ( $this->user_ids as $id ) 35 wp_delete_user($id); 36 37 wp_delete_term( $this->parent_term['term_id'], 'category' ); 38 foreach ( $this->term_ids as $term_id ) 39 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'] ); 48 } 49 50 function test_invalid_username_password() { 51 $result = $this->myxmlrpcserver->wp_newTerm( array( 1, 'username', 'password' ) ); 52 $this->assertInstanceOf( 'IXR_Error', $result ); 53 $this->assertEquals( 403, $result->code ); 54 } 55 56 function test_empty_taxonomy() { 57 $result = $this->myxmlrpcserver->wp_newTerm( array( 1, 'subscriber', 'subscriber' ) ); 58 $this->assertInstanceOf( 'IXR_Error', $result ); 59 $this->assertEquals( 403, $result->code ); 60 $this->assertEquals( __( 'Invalid taxonomy.' ), $result->message ); 61 } 62 63 function test_invalid_taxonomy() { 64 $result = $this->myxmlrpcserver->wp_newTerm( array( 1, 'subscriber', 'subscriber', array( 'taxonomy' => 'not_existing' ) ) ); 65 $this->assertInstanceOf( 'IXR_Error', $result ); 66 $this->assertEquals( 403, $result->code ); 67 $this->assertEquals( __( 'Invalid taxonomy.' ), $result->message ); 68 } 69 70 function test_incapable_user() { 71 $result = $this->myxmlrpcserver->wp_newTerm( array( 1, 'subscriber', 'subscriber', array( 'taxonomy' => 'category' ) ) ); 72 $this->assertInstanceOf( 'IXR_Error', $result ); 73 $this->assertEquals( 401, $result->code ); 74 $this->assertEquals( __( 'You are not allowed to create terms in this taxonomy.' ), $result->message ); 75 } 76 77 function test_empty_term() { 78 $result = $this->myxmlrpcserver->wp_newTerm( array( 1, 'editor', 'editor', array( 'taxonomy' => 'category', 'name' => '' ) ) ); 79 $this->assertInstanceOf( 'IXR_Error', $result ); 80 $this->assertEquals( 403, $result->code ); 81 $this->assertEquals( __( 'The term name cannot be empty.' ), $result->message ); 82 } 83 84 function test_parent_for_nonhierarchical() { 85 $result = $this->myxmlrpcserver->wp_newTerm( array( 1, 'editor', 'editor', array( 'taxonomy' => 'post_tag', 'parent' => $this->parent_term['term_id'], 'name' => 'test' ) ) ); 86 $this->assertInstanceOf( 'IXR_Error', $result ); 87 $this->assertEquals( 403, $result->code ); 88 $this->assertEquals( __( 'This taxonomy is not hierarchical.' ), $result->message ); 89 } 90 91 function test_parent_invalid() { 92 $result = $this->myxmlrpcserver->wp_newTerm( array( 1, 'editor', 'editor', array( 'taxonomy' => 'category', 'parent' => 'dasda', 'name' => 'test' ) ) ); 93 $this->assertInstanceOf( 'IXR_Error', $result ); 94 $this->assertEquals( 500, $result->code ); 95 } 96 97 function test_parent_not_existing() { 98 $result = $this->myxmlrpcserver->wp_newTerm( array( 1, 'editor', 'editor', array( 'taxonomy' => 'category', 'parent' => 9999, 'name' => 'test' ) ) ); 99 $this->assertInstanceOf( 'IXR_Error', $result ); 100 $this->assertEquals( 403, $result->code ); 101 $this->assertEquals( __( 'Parent term does not exist.' ), $result->message ); 102 } 103 104 105 function test_add_term() { 106 $result = $this->myxmlrpcserver->wp_newTerm( array( 1, 'editor', 'editor', array( 'taxonomy' => 'category', 'name' => 'test' ) ) ); 107 $this->assertNotInstanceOf( 'IXR_Error', $result ); 108 $this->assertStringMatchesFormat( '%d', $result ); 109 110 $term_ids[] = $result; 111 } 112 113 function test_add_term_with_parent() { 114 $result = $this->myxmlrpcserver->wp_newTerm( array( 1, 'editor', 'editor', array( 'taxonomy' => 'category', 'parent' => $this->parent_term['term_id'], 'name' => 'test' ) ) ); 115 $this->assertNotInstanceOf( 'IXR_Error', $result ); 116 $this->assertStringMatchesFormat( '%d', $result ); 117 118 $term_ids[] = $result; 119 } 120 121 function test_add_term_with_all() { 122 $taxonomy = array( 'taxonomy' => 'category', 'parent' => $this->parent_term['term_id'], 'name' => 'test_all', 'description' => 'Test all', 'slug' => 'test_all' ); 123 $result = $this->myxmlrpcserver->wp_newTerm( array( 1, 'editor', 'editor', $taxonomy ) ); 124 $this->assertNotInstanceOf( 'IXR_Error', $result ); 125 $this->assertStringMatchesFormat( '%d', $result ); 126 127 $term_ids[] = $result; 128 } 129 } 130 No newline at end of file