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.



git-svn-id: https://develop.svn.wordpress.org/trunk@46435 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
K. Adam White
2019-10-08 13:41:29 +00:00
parent 040304def7
commit e2cf94fa04
3 changed files with 36 additions and 10 deletions

View File

@@ -4617,6 +4617,37 @@ class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te
);
}
/**
* @ticket 45677
*/
public function test_get_for_post_type_returns_null_for_invalid_provided_controller() {
register_post_type(
'test',
array(
'show_in_rest' => true,
'rest_controller' => new \stdClass(),
)
);
$this->assertNull( get_post_type_object( 'test' )->get_rest_controller() );
}
/**
* @ticket 45677
*/
public function test_get_for_post_type_returns_null_for_controller_class_mismatch() {
register_post_type(
'test',
array(
'show_in_rest' => true,
'rest_controller_class' => WP_REST_Posts_Controller::class,
'rest_controller' => new WP_REST_Terms_Controller( 'category' ),
)
);
$this->assertNull( get_post_type_object( 'test' )->get_rest_controller() );
}
public function tearDown() {
_unregister_post_type( 'private-post' );
_unregister_post_type( 'youseeme' );