WordPress.org

Make WordPress Core

Ticket #52640: 52640-1.patch

File 52640-1.patch, 1.6 KB (added by chrisl27, 7 months ago)

Patch for this issue, with test

  • src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php

    diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
    index 066e4181d6..7a89a594ca 100644
    a b class WP_REST_Posts_Controller extends WP_REST_Controller { 
    18491849                        }
    18501850                }
    18511851
     1852                if ( 'attachment' === $this->post_type ) {
     1853                        return $response;
     1854                }
     1855
    18521856                /**
    18531857                 * Filters the post data for a REST API response.
    18541858                 *
  • tests/phpunit/tests/rest-api/rest-attachments-controller.php

    diff --git a/tests/phpunit/tests/rest-api/rest-attachments-controller.php b/tests/phpunit/tests/rest-api/rest-attachments-controller.php
    index c023033369..181aaa873b 100644
    a b class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control 
    21542154                $this->assertErrorResponse( 'rest_image_not_edited', $response_3, 400 );
    21552155        }
    21562156
     2157        public function test_rest_prepare_attachment_hook_runs_once() {
     2158                $attachment_id = $this->factory->attachment->create_object(
     2159                        $this->test_file,
     2160                        0,
     2161                        array(
     2162                                'post_mime_type' => 'image/jpeg',
     2163                                'post_excerpt'   => 'A sample caption',
     2164                        )
     2165                );
     2166
     2167                $filter = new MockAction();
     2168                add_filter( 'rest_prepare_attachment', array( $filter, 'filter' ) );
     2169
     2170                $request = new WP_REST_Request( 'GET', '/wp/v2/media/' . $attachment_id );
     2171                rest_get_server()->dispatch( $request );
     2172
     2173                $this->assertSame( 1, $filter->get_call_count() );
     2174        }
     2175
    21572176        /**
    21582177         * Sets up the mock image editor.
    21592178         *