mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2025-10-16 12:05:38 +00:00
Adds a `public` visibility to test fixtures, tests, data providers, and callbacks methods. Adds a `private` visibility to helper methods within test classes. Renames callbacks and helpers that previously started with a `_` prefix. Why? For consistency and to leverage using the method visibility. Further naming standardizations is beyond the scope of this commit. Props costdev, jrf, hellofromTonya. Fixes #54177. git-svn-id: https://develop.svn.wordpress.org/trunk@52010 602fd350-edb4-49c9-b593-d223f7449a82
92 lines
2.4 KiB
PHP
92 lines
2.4 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @group xmlrpc
|
|
*/
|
|
class Tests_XMLRPC_wp_getPages extends WP_XMLRPC_UnitTestCase {
|
|
protected static $post_id;
|
|
protected static $editor_id;
|
|
|
|
public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
|
|
self::$post_id = $factory->post->create(
|
|
array(
|
|
'post_type' => 'page',
|
|
'post_author' => $factory->user->create(
|
|
array(
|
|
'user_login' => 'administrator',
|
|
'user_pass' => 'administrator',
|
|
'role' => 'administrator',
|
|
)
|
|
),
|
|
'post_date' => date_format( date_create( '+1 day' ), 'Y-m-d H:i:s' ),
|
|
)
|
|
);
|
|
self::$editor_id = $factory->user->create(
|
|
array(
|
|
'user_login' => 'editor',
|
|
'user_pass' => 'editor',
|
|
'role' => 'editor',
|
|
)
|
|
);
|
|
}
|
|
|
|
public function test_invalid_username_password() {
|
|
$result = $this->myxmlrpcserver->wp_getPages( array( 1, 'username', 'password' ) );
|
|
$this->assertIXRError( $result );
|
|
$this->assertSame( 403, $result->code );
|
|
}
|
|
|
|
public function test_incapable_user() {
|
|
$this->make_user_by_role( 'contributor' );
|
|
|
|
$result = $this->myxmlrpcserver->wp_getPages( array( 1, 'contributor', 'contributor' ) );
|
|
$this->assertIXRError( $result );
|
|
$this->assertSame( 401, $result->code );
|
|
}
|
|
|
|
public function test_capable_user() {
|
|
$results = $this->myxmlrpcserver->wp_getPages( array( 1, 'administrator', 'administrator' ) );
|
|
$this->assertNotIXRError( $results );
|
|
|
|
foreach ( $results as $result ) {
|
|
$page = get_post( $result['page_id'] );
|
|
$this->assertSame( $page->post_type, 'page' );
|
|
}
|
|
}
|
|
|
|
public function remove_editor_edit_page_cap( $caps, $cap, $user_id, $args ) {
|
|
if ( in_array( $cap, array( 'edit_page', 'edit_others_pages' ), true ) ) {
|
|
if ( $user_id === self::$editor_id && $args[0] === self::$post_id ) {
|
|
return array( false );
|
|
}
|
|
}
|
|
|
|
return $caps;
|
|
}
|
|
|
|
/**
|
|
* @ticket 20629
|
|
*/
|
|
public function test_semi_capable_user() {
|
|
add_filter( 'map_meta_cap', array( $this, 'remove_editor_edit_page_cap' ), 10, 4 );
|
|
|
|
$results = $this->myxmlrpcserver->wp_getPages( array( 1, 'editor', 'editor' ) );
|
|
$this->assertNotIXRError( $results );
|
|
|
|
$found_incapable = false;
|
|
foreach ( $results as $result ) {
|
|
// WP#20629
|
|
$this->assertNotIXRError( $result );
|
|
|
|
if ( $result['page_id'] === self::$post_id ) {
|
|
$found_incapable = true;
|
|
break;
|
|
}
|
|
}
|
|
$this->assertFalse( $found_incapable );
|
|
|
|
remove_filter( 'map_meta_cap', array( $this, 'remove_editor_edit_page_cap' ), 10, 4 );
|
|
}
|
|
|
|
}
|