testcase-rest-controller.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. abstract class WP_Test_REST_Controller_Testcase extends WP_Test_REST_TestCase {
  3. protected $server;
  4. public function setUp() {
  5. parent::setUp();
  6. add_filter( 'rest_url', array( $this, 'filter_rest_url_for_leading_slash' ), 10, 2 );
  7. /** @var WP_REST_Server $wp_rest_server */
  8. global $wp_rest_server;
  9. $wp_rest_server = new Spy_REST_Server;
  10. do_action( 'rest_api_init', $wp_rest_server );
  11. }
  12. public function tearDown() {
  13. remove_filter( 'rest_url', array( $this, 'test_rest_url_for_leading_slash' ), 10, 2 );
  14. /** @var WP_REST_Server $wp_rest_server */
  15. global $wp_rest_server;
  16. $wp_rest_server = null;
  17. parent::tearDown();
  18. }
  19. abstract public function test_register_routes();
  20. abstract public function test_context_param();
  21. abstract public function test_get_items();
  22. abstract public function test_get_item();
  23. abstract public function test_create_item();
  24. abstract public function test_update_item();
  25. abstract public function test_delete_item();
  26. abstract public function test_prepare_item();
  27. abstract public function test_get_item_schema();
  28. public function filter_rest_url_for_leading_slash( $url, $path ) {
  29. if ( is_multisite() || get_option( 'permalink_structure' ) ) {
  30. return $url;
  31. }
  32. // Make sure path for rest_url has a leading slash for proper resolution.
  33. $this->assertTrue( 0 === strpos( $path, '/' ), 'REST API URL should have a leading slash.' );
  34. return $url;
  35. }
  36. }