Skip to content

Commit

Permalink
Add comprehensive unit tests for REST search controller and fix bugs …
Browse files Browse the repository at this point in the history
…detected by tests.
  • Loading branch information
Felix Arntz committed May 5, 2018
1 parent d80560f commit 311413e
Show file tree
Hide file tree
Showing 2 changed files with 407 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/class-wp-rest-search-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,12 @@ public function get_items( $request ) {
public function check_read_permission( $post ) {

// Is the post readable?
if ( 'publish' === $post->post_status || current_user_can( $post_type->cap->read_post, $post->ID ) ) {
if ( 'publish' === $post->post_status ) {
return true;
}

$post_type = get_post_type_object( $post->post_type );
if ( current_user_can( $post_type->cap->read_post, $post->ID ) ) {
return true;
}

Expand Down Expand Up @@ -790,7 +795,7 @@ protected function get_allowed_post_stati() {
$post_stati = get_post_stati( array(
'public' => true,
'internal' => false,
) );
), 'objects' );

$post_stati['inherit'] = get_post_status_object( 'inherit' );

Expand All @@ -811,7 +816,7 @@ protected function get_allowed_post_types( $editable = false ) {
$post_types = get_post_types( array(
'public' => true,
'show_in_rest' => true,
) );
), 'objects' );

if ( $editable ) {
$allowed = array();
Expand Down
Loading

0 comments on commit 311413e

Please sign in to comment.