Ticket #18428: 18428.combo_unittests.patch
File 18428.combo_unittests.patch, 15.7 KB (added by , 12 years ago) |
---|
-
wp-testcase/test-xmlrpc-api/test_wp_deleteUser.php
1 <?php 2 3 class TestXMLRPCServer_wp_deleteUser extends WPXMLRPCServerTestCase { 4 5 function test_invalid_username_password() { 6 $result = $this->myxmlrpcserver->wp_deleteUser( array( 1, 'username', 'password', 1 ) ); 7 $this->assertInstanceOf( 'IXR_Error', $result ); 8 $this->assertEquals( 403, $result->code ); 9 } 10 11 function test_incapable_user() { 12 $result = $this->myxmlrpcserver->wp_deleteUser( array( 1, 'author', 'author', 1 ) ); 13 $this->assertInstanceOf( 'IXR_Error', $result ); 14 $this->assertEquals( 401, $result->code ); 15 } 16 17 function test_invalid_user() { 18 $result = $this->myxmlrpcserver->wp_deleteUser( array( 1, 'administrator', 'administrator', 3492083940823 ) ); 19 $this->assertInstanceOf( 'IXR_Error', $result ); 20 $this->assertEquals( 404, $result->code ); 21 } 22 23 function test_delete_self() { 24 $administrator_id = get_user_by( 'login', 'administrator' )->ID; 25 $result = $this->myxmlrpcserver->wp_deleteUser( array( 1, 'administrator', 'administrator', $administrator_id ) ); 26 $this->assertInstanceOf( 'IXR_Error', $result ); 27 $this->assertEquals( 401, $result->code ); 28 } 29 30 function test_invalid_reassign_user() { 31 $author_id = get_user_by( 'login', 'author' )->ID; 32 $result = $this->myxmlrpcserver->wp_deleteUser( array( 1, 'administrator', 'administrator', $author_id, 3908423098423 ) ); 33 $this->assertInstanceOf( 'IXR_Error', $result ); 34 $this->assertEquals( 404, $result->code ); 35 } 36 37 function test_reassign_same() { 38 $author_id = get_user_by( 'login', 'author' )->ID; 39 $result = $this->myxmlrpcserver->wp_deleteUser( array( 1, 'administrator', 'administrator', $author_id, $author_id ) ); 40 $this->assertInstanceOf( 'IXR_Error', $result ); 41 $this->assertEquals( 401, $result->code ); 42 } 43 44 function test_valid_delete() { 45 $user_id = $this->_make_user( 'author' ); 46 47 // make some posts for the user 48 $this->_insert_quick_posts( rand( 3, 10 ), 'post', array( 'post_author' => $user_id ) ); 49 50 $result = $this->myxmlrpcserver->wp_deleteUser( array( 1, 'administrator', 'administrator', $user_id ) ); 51 $this->assertNotInstanceOf( 'IXR_Error', $result ); 52 53 // verify user was deleted 54 $this->assertFalse( get_user_by( 'id', $user_id ) ); 55 56 // since reassign wasn't used, the user's posts should have been trashed 57 foreach ( $this->post_ids as $post_id ) { 58 $post = get_post( $post_id ); 59 $this->assertEquals( 'trash', $post->post_status ); 60 } 61 62 // cleanup 63 $this->post_ids = array(); 64 } 65 66 function test_valid_delete_reassign() { 67 $user_id = $this->_make_user( 'author' ); 68 $reassign_id = $this->_make_user( 'author' ); 69 70 // make some posts for the user 71 $this->_insert_quick_posts( rand( 3, 10 ), 'post', array( 'post_author' => $user_id ) ); 72 73 $result = $this->myxmlrpcserver->wp_deleteUser( array( 1, 'administrator', 'administrator', $user_id, $reassign_id ) ); 74 $this->assertNotInstanceOf( 'IXR_Error', $result ); 75 76 // verify user was deleted 77 $this->assertFalse( get_user_by( 'id', $user_id ) ); 78 79 // verify posts were reassigned to other author 80 foreach ( $this->post_ids as $post_id ) { 81 $post = get_post( $post_id ); 82 $this->assertEquals( $reassign_id, $post->post_author ); 83 $this->assertEquals( 'publish', $post->post_status ); 84 } 85 } 86 } 87 No newline at end of file -
wp-testcase/test-xmlrpc-api/test_wp_editUser.php
1 <?php 2 3 class TestXMLRPCServer_wp_editUser extends WPXMLRPCServerTestCase { 4 5 function test_invalid_username_password() { 6 $result = $this->myxmlrpcserver->wp_editUser( array( 1, 'username', 'password', 1, array() ) ); 7 $this->assertInstanceOf( 'IXR_Error', $result ); 8 $this->assertEquals( 403, $result->code ); 9 } 10 } 11 No newline at end of file -
wp-testcase/test-xmlrpc-api/test_wp_getUser.php
1 <?php 2 3 class TestXMLRPCServer_wp_getUser extends WPXMLRPCServerTestCase { 4 5 function test_invalid_username_password() { 6 $result = $this->myxmlrpcserver->wp_getUser( array( 1, 'username', 'password', 1 ) ); 7 $this->assertInstanceOf( 'IXR_Error', $result ); 8 $this->assertEquals( 403, $result->code ); 9 } 10 11 function test_invalid_user() { 12 $result = $this->myxmlrpcserver->wp_getUser( array( 1, 'administrator', 'administrator', 34902348908234 ) ); 13 $this->assertInstanceOf( 'IXR_Error', $result ); 14 $this->assertEquals( 404, $result->code ); 15 } 16 17 function test_incapable_user() { 18 $editor_id = get_user_by( 'login', 'editor' )->ID; 19 $result = $this->myxmlrpcserver->wp_getUser( array( 1, 'subscriber', 'subscriber', $editor_id ) ); 20 $this->assertInstanceOf( 'IXR_Error', $result ); 21 $this->assertEquals( 401, $result->code ); 22 } 23 24 function test_subscriber_self() { 25 $subscriber_id = get_user_by( 'login', 'subscriber' )->ID; 26 $result = $this->myxmlrpcserver->wp_getUser( array( 1, 'subscriber', 'subscriber', $subscriber_id ) ); 27 $this->assertNotInstanceOf( 'IXR_Error', $result ); 28 $this->assertEquals( $subscriber_id, $result['user_id'] ); 29 } 30 31 function test_valid_user() { 32 $registered_date = strtotime( '-1 day' ); 33 $user_data = array( 34 'user_login' => 'getUserTestUser', 35 'user_pass' => rand_str(), 36 'first_name' => rand_str(), 37 'last_name' => rand_str(), 38 'description' => rand_str(100), 39 'user_email' => 'getUserTestUser@example.com', 40 'nickname' => rand_str(), 41 'user_nicename' => rand_str(), 42 'display_name' => rand_str(), 43 'user_url' => 'http://www.example.com/testuser', 44 'role' => 'author', 45 'aim' => rand_str(), 46 'user_registered' => strftime( "%Y-%m-%d %H:%M:%S", $registered_date ) 47 ); 48 $user_id = wp_insert_user( $user_data ); 49 50 $result = $this->myxmlrpcserver->wp_getUser( array( 1, 'administrator', 'administrator', $user_id ) ); 51 $this->assertNotInstanceOf( 'IXR_Error', $result ); 52 53 // check data types 54 $this->assertInternalType( 'string', $result['user_id'] ); 55 $this->assertStringMatchesFormat( '%d', $result['user_id'] ); 56 $this->assertInternalType( 'string', $result['username'] ); 57 $this->assertInternalType( 'string', $result['first_name'] ); 58 $this->assertInternalType( 'string', $result['last_name'] ); 59 $this->assertInstanceOf( 'IXR_Date', $result['registered'] ); 60 $this->assertInternalType( 'string', $result['bio'] ); 61 $this->assertInternalType( 'string', $result['email'] ); 62 $this->assertInternalType( 'string', $result['nickname'] ); 63 $this->assertInternalType( 'string', $result['nicename'] ); 64 $this->assertInternalType( 'string', $result['url'] ); 65 $this->assertInternalType( 'string', $result['display_name'] ); 66 $this->assertInternalType( 'array', $result['capabilities'] ); 67 $this->assertInternalType( 'array', $result['roles'] ); 68 $this->assertInternalType( 'array', $result['user_contacts'] ); 69 70 // check expected values 71 $this->assertEquals( $user_id, $result['user_id'] ); 72 $this->assertEquals( $user_data['user_login'], $result['username'] ); 73 $this->assertEquals( $user_data['first_name'], $result['first_name'] ); 74 $this->assertEquals( $user_data['last_name'], $result['last_name'] ); 75 $this->assertEquals( $registered_date, $result['registered']->getTimestamp() ); 76 $this->assertEquals( $user_data['description'], $result['bio'] ); 77 $this->assertEquals( $user_data['user_email'], $result['email'] ); 78 $this->assertEquals( $user_data['nickname'], $result['nickname'] ); 79 $this->assertEquals( $user_data['user_nicename'], $result['nicename'] ); 80 $this->assertEquals( $user_data['user_url'], $result['url'] ); 81 $this->assertEquals( $user_data['display_name'], $result['display_name'] ); 82 $this->assertArrayHasKey( $user_data['role'], $result['capabilities'] ); 83 $this->assertEquals( 1, $result['capabilities'][$user_data['role']] ); 84 $this->assertEquals( $user_data['user_login'], $result['username'] ); 85 $this->assertContains( $user_data['role'], $result['roles'] ); 86 $this->assertArrayHasKey( 'aim', $result['user_contacts'] ); 87 $this->assertEquals( $user_data['aim'], $result['user_contacts']['aim'] ); 88 89 wp_delete_user( $user_id ); 90 } 91 92 function test_no_fields() { 93 $editor_id = get_user_by( 'login', 'editor' )->ID; 94 $result = $this->myxmlrpcserver->wp_getUser( array( 1, 'administrator', 'administrator', $editor_id, array() ) ); 95 $this->assertNotInstanceOf( 'IXR_Error', $result ); 96 $this->assertEquals( $editor_id, $result['user_id'] ); 97 98 $expected_fields = array( 'user_id' ); 99 $this->assertEquals( $expected_fields, array_keys( $result ) ); 100 } 101 102 function test_basic_fields() { 103 $editor_id = get_user_by( 'login', 'editor' )->ID; 104 $result = $this->myxmlrpcserver->wp_getUser( array( 1, 'administrator', 'administrator', $editor_id, array( 'basic' ) ) ); 105 $this->assertNotInstanceOf( 'IXR_Error', $result ); 106 $this->assertEquals( $editor_id, $result['user_id'] ); 107 108 $expected_fields = array( 'user_id', 'username', 'email', 'registered', 'display_name', 'nicename' ); 109 $this->assertEquals( sort( $expected_fields ), sort( array_keys( $result ) ) ); 110 } 111 112 function test_arbitrary_fields() { 113 $fields = array( 'email', 'bio', 'user_contacts' ); 114 115 $editor_id = get_user_by( 'login', 'editor' )->ID; 116 $result = $this->myxmlrpcserver->wp_getUser( array( 1, 'administrator', 'administrator', $editor_id, $fields ) ); 117 $this->assertNotInstanceOf( 'IXR_Error', $result ); 118 $this->assertEquals( $editor_id, $result['user_id'] ); 119 120 $expected_fields = array_merge( array( 'user_id' ), $fields ); 121 $this->assertEquals( sort( $expected_fields ), sort( array_keys( $result ) ) ); 122 } 123 } 124 No newline at end of file -
wp-testcase/test-xmlrpc-api/test_wp_getUserInfo.php
1 <?php 2 3 class TestXMLRPCServer_wp_getUserInfo extends WPXMLRPCServerTestCase { 4 5 function test_invalid_username_password() { 6 $result = $this->myxmlrpcserver->wp_getUserInfo( array( 1, 'username', 'password' ) ); 7 $this->assertInstanceOf( 'IXR_Error', $result ); 8 $this->assertEquals( 403, $result->code ); 9 } 10 11 function test_subscriber() { 12 $subscriber_id = get_user_by( 'login', 'subscriber' )->ID; 13 $result = $this->myxmlrpcserver->wp_getUserInfo( array( 1, 'subscriber', 'subscriber' ) ); 14 $this->assertNotInstanceOf( 'IXR_Error', $result ); 15 $this->assertEquals( $subscriber_id, $result['user_id'] ); 16 $this->assertContains( 'subscriber', $result['roles'] ); 17 } 18 19 function test_administrator() { 20 $administrator_id = get_user_by( 'login', 'administrator' )->ID; 21 $result = $this->myxmlrpcserver->wp_getUserInfo( array( 1, 'administrator', 'administrator' ) ); 22 $this->assertNotInstanceOf( 'IXR_Error', $result ); 23 $this->assertEquals( $administrator_id, $result['user_id'] ); 24 $this->assertContains( 'administrator', $result['roles'] ); 25 } 26 27 function test_arbitrary_fields() { 28 $fields = array( 'email', 'bio', 'user_contacts' ); 29 30 $editor_id = get_user_by( 'login', 'editor' )->ID; 31 $result = $this->myxmlrpcserver->wp_getUserInfo( array( 1, 'editor', 'editor', $fields ) ); 32 $this->assertNotInstanceOf( 'IXR_Error', $result ); 33 $this->assertEquals( $editor_id, $result['user_id'] ); 34 35 $expected_fields = array_merge( array( 'user_id' ), $fields ); 36 $this->assertEquals( sort( $expected_fields ), sort( array_keys( $result ) ) ); 37 } 38 } 39 No newline at end of file -
wp-testcase/test-xmlrpc-api/test_wp_getUsers.php
1 <?php 2 3 class TestXMLRPCServer_wp_getUsers extends WPXMLRPCServerTestCase { 4 5 function test_invalid_username_password() { 6 $results = $this->myxmlrpcserver->wp_getUsers( array( 1, 'username', 'password' ) ); 7 $this->assertInstanceOf( 'IXR_Error', $results ); 8 $this->assertEquals( 403, $results->code ); 9 } 10 11 function test_incapable_user() { 12 $results = $this->myxmlrpcserver->wp_getUsers( array( 1, 'subscriber', 'subscriber' ) ); 13 $this->assertInstanceOf( 'IXR_Error', $results ); 14 $this->assertEquals( 401, $results->code ); 15 } 16 17 function test_capable_user() { 18 $results = $this->myxmlrpcserver->wp_getUsers( array( 1, 'administrator', 'administrator' ) ); 19 $this->assertNotInstanceOf( 'IXR_Error', $results ); 20 } 21 22 function test_invalid_role() { 23 $filter = array( 'role' => rand_str() ); 24 $results = $this->myxmlrpcserver->wp_getUsers( array( 1, 'administrator', 'administrator', $filter ) ); 25 $this->assertInstanceOf( 'IXR_Error', $results ); 26 $this->assertEquals( 403, $results->code ); 27 } 28 29 function test_role_filter() { 30 $editor_id = get_user_by( 'login', 'editor' )->ID; 31 32 $filter = array( 'role' => 'editor' ); 33 $results = $this->myxmlrpcserver->wp_getUsers( array( 1, 'administrator', 'administrator', $filter ) ); 34 $this->assertNotInstanceOf( 'IXR_Error', $results ); 35 36 $this->assertCount( 1, $results ); 37 $this->assertEquals( $editor_id, $results[0]['user_id'] ); 38 } 39 40 function test_paging_filters() { 41 $user_ids = get_users( array( 'fields' => 'ID' ) ); 42 43 $users_found = array(); 44 $page_size = count( $user_ids ) / 3; 45 $filter = array( 'number' => $page_size, $offset = 0 ); 46 do { 47 $presults = $this->myxmlrpcserver->wp_getUsers( array( 1, 'administrator', 'administrator', $filter ) ); 48 foreach( $presults as $user ) { 49 $users_found[] = $user['user_id']; 50 } 51 $filter['offset'] += $page_size; 52 } while ( count( $presults ) > 0 ); 53 54 // verify that $user_ids matches $users_found 55 $this->assertEquals( 0, count( array_diff( $user_ids, $users_found ) ) ); 56 } 57 58 function test_order_filters() { 59 $filter = array( 'orderby' => 'email', 'order' => 'ASC' ); 60 $results = $this->myxmlrpcserver->wp_getUsers( array( 1, 'administrator', 'administrator', $filter ) ); 61 $this->assertNotInstanceOf( 'IXR_Error', $results ); 62 63 $last_email = ''; 64 foreach ( $results as $user ) { 65 $this->assertLessThanOrEqual( 0, strcmp( $last_email, $user['email'] ) ); 66 $last_email = $user['email']; 67 } 68 } 69 } 70 No newline at end of file -
wp-testcase/test-xmlrpc-api/test_wp_newUser.php
1 <?php 2 3 class TestXMLRPCServer_wp_newUser extends WPXMLRPCServerTestCase { 4 5 function test_invalid_username_password() { 6 $result = $this->myxmlrpcserver->wp_newUser( array( 1, 'username', 'password', array() ) ); 7 $this->assertInstanceOf( 'IXR_Error', $result ); 8 $this->assertEquals( 403, $result->code ); 9 } 10 } 11 No newline at end of file