WordPress.org

Make WordPress Core

Ticket #40600: 40600_unit_test.patch

File 40600_unit_test.patch, 1.2 KB (added by ruud@…, 3 years ago)

Unit test for get_item with filter

  • tests/phpunit/tests/rest-api/rest-posts-controller.php

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    990990                $this->check_get_post_response( $response, 'view' );
    991991        }
    992992
     993        public function filter_rest_pre_get_item( $request ) {
     994
     995                $error = new WP_Error( 'rest_post_invalid_id', __( 'Invalid post ID.' ), array( 'status' => 404 ) );
     996                return $error;
     997        }
     998
     999        public function test_get_item_with_filter() {
     1000
     1001                add_filter( 'rest_pre_get_item', array( $this, 'filter_rest_pre_get_item' ), 10, 1 );
     1002
     1003                $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
     1004                $response = $this->server->dispatch( $request );
     1005
     1006                $this->assertErrorResponse( 'rest_post_invalid_id', $response, 404 );
     1007        }
     1008
    9931009        public function test_get_item_links() {
    9941010                $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
    9951011                $response = $this->server->dispatch( $request );