From 2ae5273a0ece19fa90341a86f1f1f168fb440b96 Mon Sep 17 00:00:00 2001 From: ramon Date: Tue, 22 Oct 2024 12:29:31 +1100 Subject: [PATCH] Linty McGinty --- ...-gutenberg-rest-post-counts-controller.php | 10 ++++---- ...nberg-rest-post-counts-controller-test.php | 24 ++++++++++--------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/lib/compat/wordpress-6.8/class-gutenberg-rest-post-counts-controller.php b/lib/compat/wordpress-6.8/class-gutenberg-rest-post-counts-controller.php index 21875839c7a770..31bf3c108a2226 100644 --- a/lib/compat/wordpress-6.8/class-gutenberg-rest-post-counts-controller.php +++ b/lib/compat/wordpress-6.8/class-gutenberg-rest-post-counts-controller.php @@ -37,7 +37,7 @@ public function register_routes() { $this->namespace, '/' . $this->rest_base . '/(?P[\w-]+)', array( - 'args' => array( + 'args' => array( 'post_type' => array( 'description' => __( 'An alphanumeric identifier for the post type.' ), 'type' => 'string', @@ -96,7 +96,7 @@ public function get_item_permissions_check( $request ) { */ public function get_item( $request ) { $post_type = $request['post_type']; - $counts = wp_count_posts( $post_type ); + $counts = wp_count_posts( $post_type ); if ( ! $counts ) { return new WP_Error( @@ -120,7 +120,7 @@ public function get_item( $request ) { * @return WP_REST_Response Response object. */ public function prepare_item_for_response( $item, $request ) { - $data = array(); + $data = array(); $fields = $this->get_fields_for_response( $request ); foreach ( $fields as $field ) { @@ -130,8 +130,8 @@ public function prepare_item_for_response( $item, $request ) { } $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; - $data = $this->add_additional_fields_to_object( $data, $request ); - $data = $this->filter_response_by_context( $data, $context ); + $data = $this->add_additional_fields_to_object( $data, $request ); + $data = $this->filter_response_by_context( $data, $context ); $response = rest_ensure_response( $data ); diff --git a/phpunit/class-gutenberg-rest-post-counts-controller-test.php b/phpunit/class-gutenberg-rest-post-counts-controller-test.php index 0fae05522e3adb..0df45d3cd4006b 100644 --- a/phpunit/class-gutenberg-rest-post-counts-controller-test.php +++ b/phpunit/class-gutenberg-rest-post-counts-controller-test.php @@ -18,7 +18,7 @@ class Gutenberg_Test_REST_Post_Counts_Controller extends WP_Test_REST_Controller public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { self::$admin_id = $factory->user->create( array( - 'role' => 'administrator', + 'role' => 'administrator', ) ); @@ -74,9 +74,9 @@ public function test_context_param() { * @covers Gutenberg_REST_Post_Counts_Controller::et_item_schema */ public function test_get_item_schema() { - $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/counts/post' ); - $response = rest_get_server()->dispatch( $request ); - $data = $response->get_data(); + $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/counts/post' ); + $response = rest_get_server()->dispatch( $request ); + $data = $response->get_data(); $properties = $data['schema']['properties']; $this->assertCount( 7, $properties ); @@ -94,9 +94,9 @@ public function test_get_item_schema() { */ public function test_get_item_response() { wp_set_current_user( self::$admin_id ); - $request = new WP_REST_Request( 'GET', '/wp/v2/counts/post' ); + $request = new WP_REST_Request( 'GET', '/wp/v2/counts/post' ); $response = rest_get_server()->dispatch( $request ); - $data = $response->get_data(); + $data = $response->get_data(); $this->assertSame( 200, $response->get_status() ); $this->assertArrayHasKey( 'publish', $data ); @@ -115,10 +115,12 @@ public function test_get_item() { wp_set_current_user( self::$admin_id ); $published = self::factory()->post->create( array( 'post_status' => 'publish' ) ); - $future = self::factory()->post->create( array( - 'post_status' => 'future', - 'post_date' => date('Y-m-d H:i:s', strtotime('+1 day')) - ) ); + $future = self::factory()->post->create( + array( + 'post_status' => 'future', + 'post_date' => date( 'Y-m-d H:i:s', strtotime( '+1 day' ) ), + ) + ); $draft = self::factory()->post->create( array( 'post_status' => 'draft' ) ); $pending = self::factory()->post->create( array( 'post_status' => 'pending' ) ); $private = self::factory()->post->create( array( 'post_status' => 'private' ) ); @@ -126,7 +128,7 @@ public function test_get_item() { $request = new WP_REST_Request( 'GET', '/wp/v2/counts/post' ); $response = rest_get_server()->dispatch( $request ); - $data = $response->get_data(); + $data = $response->get_data(); $this->assertSame( 1, $data['publish'], 'Published post count mismatch.' ); $this->assertSame( 1, $data['future'], 'Future post count mismatch.' );