WordPress.org

Make WordPress Core

Changeset 40104


Ignore:
Timestamp:
02/23/2017 03:49:44 PM (16 months ago)
Author:
jnylen0
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/rest-api/rest-schema-setup.php

    r40077 r40104  
    3737        $this->assertTrue( is_array( $routes ), '`get_routes` should return an array.' );
    3838        $this->assertTrue( ! empty( $routes ), 'Routes should not be empty.' );
     39
     40        $routes = array_filter( array_keys( $routes ), array( $this, 'is_builtin_route' ) );
    3941
    4042        $expected_routes = array(
     
    7173        );
    7274
    73         $this->assertEquals( $expected_routes, array_keys( $routes ) );
     75        $this->assertEquals( $expected_routes, $routes );
     76    }
     77
     78    private function is_builtin_route( $route ) {
     79        return (
     80            '/' === $route ||
     81            preg_match( '#^/oembed/1\.0(/.+)?$#', $route ) ||
     82            preg_match( '#^/wp/v2(/.+)?$#', $route )
     83        );
    7484    }
    7585
Note: See TracChangeset for help on using the changeset viewer.