Make WordPress Core


Ignore:
Timestamp:
11/17/2015 02:38:31 AM (11 years ago)
Author:
rmccue
Message:

REST API: Require namespace when registering routes.

Props danielbachhuber.
Fixes #34416.

File:
1 edited

Legend:

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

    r35351 r35651  
    147147                $this->assertArrayHasKey( 'should_exist', $endpoint[0] );
    148148                $this->assertTrue( $endpoint[0]['should_exist'] );
     149        }
     150
     151        /**
     152         * Test that we reject routes without namespaces
     153         *
     154         * @expectedIncorrectUsage register_rest_route
     155         */
     156        public function test_route_reject_empty_namespace() {
     157                register_rest_route( '', '/test-empty-namespace', array(
     158                        'methods'      => array( 'POST' ),
     159                        'callback'     => '__return_null',
     160                ), true );
     161                $endpoints = $GLOBALS['wp_rest_server']->get_routes();
     162                $this->assertFalse( isset( $endpoints['/test-empty-namespace'] ) );
     163        }
     164
     165        /**
     166         * Test that we reject empty routes
     167         *
     168         * @expectedIncorrectUsage register_rest_route
     169         */
     170        public function test_route_reject_empty_route() {
     171                register_rest_route( '/test-empty-route', '', array(
     172                        'methods'      => array( 'POST' ),
     173                        'callback'     => '__return_null',
     174                ), true );
     175                $endpoints = $GLOBALS['wp_rest_server']->get_routes();
     176                $this->assertFalse( isset( $endpoints['/test-empty-route'] ) );
    149177        }
    150178
Note: See TracChangeset for help on using the changeset viewer.