Wordpress/tests/phpunit/includes/class-wp-rest-test-configurable-controller.php
Timothy Jacobs 8a62f46beb REST API: Don't assume all item schemas have properties.
All schema types, not just objects, are permitted as the base type of a resource. A future patch could add validation support for those types, but this fix only prevents a PHP warning from being issued.

Props dhavalkasvala, johnwatkins0, birgire.
Fixes #48785.


git-svn-id: https://develop.svn.wordpress.org/trunk@47328 602fd350-edb4-49c9-b593-d223f7449a82
2020-02-20 16:56:17 +00:00

61 lines
1.0 KiB
PHP

<?php
/**
* Unit tests covering WP_REST_Controller functionality using a flexible schema.
*
* @package WordPress
* @subpackage REST API
* @since 5.4.0
*/
/**
* WP_REST_Test_Configurable_Controller class.
*
* @group restapi
*
* @since 5.4.0
*/
class WP_REST_Test_Configurable_Controller extends WP_REST_Controller {
/**
* Test schema.
*
* @since 5.4.0
*
* @var array $test_schema
*/
protected $test_schema;
/**
* Class constructor.
*
* @since 5.4.0
*
* @param array $test_schema Schema for use in testing.
*/
public function __construct( $test_schema ) {
$this->test_schema = $test_schema;
}
/**
* Provides the test schema.
*
* @since 5.4.0
*
* @return array Test schema.
*/
public function get_test_schema() {
return $this->test_schema;
}
/**
* Get the item's schema, conforming to JSON Schema.
*
* @since 5.4.0
*
* @return array
*/
public function get_item_schema() {
return $this->add_additional_fields_schema( $this->get_test_schema() );
}
}