Make WordPress Core


Ignore:
Timestamp:
10/08/2019 01:41:29 PM (7 years ago)
Author:
kadamwhite
Message:

REST API: Ensure rest_controller instantiates the post type's declared REST controller class.

Ensures that the ::get_rest_controller() method will always return an instanceof the expected controller class, or null.
Removes unused private static property $post_type_controllers.

Props dlh, TimothyBlynJacobs.
Fixes #45677.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/rest-api/rest-posts-controller.php

    r46434 r46435  
    46184618        }
    46194619
     4620        /**
     4621         * @ticket 45677
     4622         */
     4623        public function test_get_for_post_type_returns_null_for_invalid_provided_controller() {
     4624                register_post_type(
     4625                        'test',
     4626                        array(
     4627                                'show_in_rest'    => true,
     4628                                'rest_controller' => new \stdClass(),
     4629                        )
     4630                );
     4631
     4632                $this->assertNull( get_post_type_object( 'test' )->get_rest_controller() );
     4633        }
     4634
     4635        /**
     4636         * @ticket 45677
     4637         */
     4638        public function test_get_for_post_type_returns_null_for_controller_class_mismatch() {
     4639                register_post_type(
     4640                        'test',
     4641                        array(
     4642                                'show_in_rest'          => true,
     4643                                'rest_controller_class' => WP_REST_Posts_Controller::class,
     4644                                'rest_controller'       => new WP_REST_Terms_Controller( 'category' ),
     4645                        )
     4646                );
     4647
     4648                $this->assertNull( get_post_type_object( 'test' )->get_rest_controller() );
     4649        }
     4650
    46204651        public function tearDown() {
    46214652                _unregister_post_type( 'private-post' );
Note: See TracChangeset for help on using the changeset viewer.