Changeset 39189 for trunk/tests/phpunit/tests/xmlrpc/wp/getPages.php
- Timestamp:
- 11/10/2016 01:53:08 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/xmlrpc/wp/getPages.php
r25002 r39189 5 5 */ 6 6 class Tests_XMLRPC_wp_getPages extends WP_XMLRPC_UnitTestCase { 7 var $post_data; 8 var $post_id; 9 var $post_date_ts; 10 var $editor_id; 7 protected static $post_id; 8 protected static $editor_id; 11 9 12 function setUp() { 13 parent::setUp(); 10 public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { 11 self::$post_id = $factory->post->create( array( 12 'post_type' => 'page', 13 'post_author' => $factory->user->create( array( 14 'user_login' => 'administrator', 15 'user_pass' => 'administrator', 16 'role' => 'administrator' 17 ) ), 18 'post_date' => strftime( "%Y-%m-%d %H:%M:%S", strtotime( '+1 day' ) ), 19 ) ); 20 self::$editor_id = $factory->user->create( array( 21 'user_login' => 'editor', 22 'user_pass' => 'editor', 23 'role' => 'editor' 24 ) ); 25 } 14 26 15 $this->post_date_ts = strtotime( '+1 day' ); 16 $this->post_data = array( 17 'post_type' => 'page', 18 'post_title' => rand_str(), 19 'post_content' => rand_str( 2000 ), 20 'post_excerpt' => rand_str( 100 ), 21 'post_author' => $this->make_user_by_role( 'administrator' ), 22 'post_date' => strftime( "%Y-%m-%d %H:%M:%S", $this->post_date_ts ), 23 ); 24 $this->post_id = wp_insert_post( $this->post_data ); 25 $this->editor_id = $this->make_user_by_role( 'editor' ); 26 } 27 function test_invalid_username_password() { 28 $result = $this->myxmlrpcserver->wp_getPages( array( 1, 'username', 'password' ) ); 29 $this->assertInstanceOf( 'IXR_Error', $result ); 30 $this->assertEquals( 403, $result->code ); 31 } 27 32 28 function test_invalid_username_password() { 29 $result = $this->myxmlrpcserver->wp_getPages( array( 1, 'username', 'password' ) ); 30 $this->assertInstanceOf( 'IXR_Error', $result ); 31 $this->assertEquals( 403, $result->code ); 32 } 33 34 function test_incapable_user() { 33 function test_incapable_user() { 35 34 $this->make_user_by_role( 'contributor' ); 36 35 37 38 39 40 36 $result = $this->myxmlrpcserver->wp_getPages( array( 1, 'contributor', 'contributor' ) ); 37 $this->assertInstanceOf( 'IXR_Error', $result ); 38 $this->assertEquals( 401, $result->code ); 39 } 41 40 42 43 44 41 function test_capable_user() { 42 $results = $this->myxmlrpcserver->wp_getPages( array( 1, 'administrator', 'administrator' ) ); 43 $this->assertNotInstanceOf( 'IXR_Error', $results ); 45 44 46 47 48 49 50 45 foreach( $results as $result ) { 46 $page = get_post( $result['page_id'] ); 47 $this->assertEquals( $page->post_type, 'page' ); 48 } 49 } 51 50 52 53 54 if ( $user_id == $this->editor_id && $args[0] == $this->post_id ) {55 56 57 51 function remove_editor_edit_page_cap( $caps, $cap, $user_id, $args ) { 52 if ( in_array( $cap, array( 'edit_page', 'edit_others_pages' ) ) ) { 53 if ( $user_id == self::$editor_id && $args[0] == self::$post_id ) { 54 return array( false ); 55 } 56 } 58 57 59 60 58 return $caps; 59 } 61 60 62 61 /** … … 64 63 */ 65 64 function test_semi_capable_user() { 66 65 add_filter( 'map_meta_cap', array( $this, 'remove_editor_edit_page_cap') , 10, 4 ); 67 66 68 69 67 $results = $this->myxmlrpcserver->wp_getPages( array( 1, 'editor', 'editor' ) ); 68 $this->assertNotInstanceOf( 'IXR_Error', $results ); 70 69 71 72 73 74 70 $found_incapable = false; 71 foreach( $results as $result ) { 72 // WP#20629 73 $this->assertNotInstanceOf( 'IXR_Error', $result ); 75 74 76 if ( $result['page_id'] == $this->post_id ) {77 78 79 80 81 75 if ( $result['page_id'] == self::$post_id ) { 76 $found_incapable = true; 77 break; 78 } 79 } 80 $this->assertFalse( $found_incapable ); 82 81 83 84 82 remove_filter( 'map_meta_cap', array( $this, 'remove_editor_edit_page_cap' ), 10, 4 ); 83 } 85 84 86 85 }
Note: See TracChangeset
for help on using the changeset viewer.