From 6a23c57ad558ef132c24951fc0feedf3f264e8b6 Mon Sep 17 00:00:00 2001 From: James Nylen Date: Thu, 23 Feb 2017 15:49:44 +0000 Subject: [PATCH] REST API: Ensure that tests pass if extra endpoints are registered. Many plugins and themes use the WP core test suite to run their unit tests, so the API tests shouldn't fail if there are extra endpoints registered in non-core namespaces. Props rachelbaker. Fixes #39264. git-svn-id: https://develop.svn.wordpress.org/trunk@40104 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/rest-api/rest-schema-setup.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tests/phpunit/tests/rest-api/rest-schema-setup.php b/tests/phpunit/tests/rest-api/rest-schema-setup.php index c286504e18..eea2224331 100644 --- a/tests/phpunit/tests/rest-api/rest-schema-setup.php +++ b/tests/phpunit/tests/rest-api/rest-schema-setup.php @@ -37,6 +37,8 @@ class WP_Test_REST_Schema_Initialization extends WP_Test_REST_TestCase { $this->assertTrue( is_array( $routes ), '`get_routes` should return an array.' ); $this->assertTrue( ! empty( $routes ), 'Routes should not be empty.' ); + $routes = array_filter( array_keys( $routes ), array( $this, 'is_builtin_route' ) ); + $expected_routes = array( '/', '/oembed/1.0', @@ -70,7 +72,15 @@ class WP_Test_REST_Schema_Initialization extends WP_Test_REST_TestCase { '/wp/v2/settings', ); - $this->assertEquals( $expected_routes, array_keys( $routes ) ); + $this->assertEquals( $expected_routes, $routes ); + } + + private function is_builtin_route( $route ) { + return ( + '/' === $route || + preg_match( '#^/oembed/1\.0(/.+)?$#', $route ) || + preg_match( '#^/wp/v2(/.+)?$#', $route ) + ); } public function test_build_wp_api_client_fixtures() {