class-wp-rest-test-configurable-controller.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /**
  3. * Unit tests covering WP_REST_Controller functionality using a flexible schema.
  4. *
  5. * @package WordPress
  6. * @subpackage REST API
  7. * @since 5.4.0
  8. */
  9. /**
  10. * WP_REST_Test_Configurable_Controller class.
  11. *
  12. * @group restapi
  13. *
  14. * @since 5.4.0
  15. */
  16. class WP_REST_Test_Configurable_Controller extends WP_REST_Controller {
  17. /**
  18. * Test schema.
  19. *
  20. * @since 5.4.0
  21. *
  22. * @var array $test_schema
  23. */
  24. protected $test_schema;
  25. /**
  26. * Class constructor.
  27. *
  28. * @since 5.4.0
  29. *
  30. * @param array $test_schema Schema for use in testing.
  31. */
  32. public function __construct( $test_schema ) {
  33. $this->test_schema = $test_schema;
  34. }
  35. /**
  36. * Provides the test schema.
  37. *
  38. * @since 5.4.0
  39. *
  40. * @return array Test schema.
  41. */
  42. public function get_test_schema() {
  43. return $this->test_schema;
  44. }
  45. /**
  46. * Get the item's schema, conforming to JSON Schema.
  47. *
  48. * @since 5.4.0
  49. *
  50. * @return array
  51. */
  52. public function get_item_schema() {
  53. return $this->add_additional_fields_schema( $this->get_test_schema() );
  54. }
  55. }