REST API: Require namespace when registering routes.

Props danielbachhuber.
Fixes #34416.


git-svn-id: https://develop.svn.wordpress.org/trunk@35651 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan McCue
2015-11-17 02:38:31 +00:00
parent 8b4a1d65cd
commit 0a501976db
2 changed files with 44 additions and 13 deletions
+28
View File
@@ -148,6 +148,34 @@ class Tests_REST_API extends WP_UnitTestCase {
$this->assertTrue( $endpoint[0]['should_exist'] );
}
/**
* Test that we reject routes without namespaces
*
* @expectedIncorrectUsage register_rest_route
*/
public function test_route_reject_empty_namespace() {
register_rest_route( '', '/test-empty-namespace', array(
'methods' => array( 'POST' ),
'callback' => '__return_null',
), true );
$endpoints = $GLOBALS['wp_rest_server']->get_routes();
$this->assertFalse( isset( $endpoints['/test-empty-namespace'] ) );
}
/**
* Test that we reject empty routes
*
* @expectedIncorrectUsage register_rest_route
*/
public function test_route_reject_empty_route() {
register_rest_route( '/test-empty-route', '', array(
'methods' => array( 'POST' ),
'callback' => '__return_null',
), true );
$endpoints = $GLOBALS['wp_rest_server']->get_routes();
$this->assertFalse( isset( $endpoints['/test-empty-route'] ) );
}
/**
* The rest_route query variable should be registered.
*/