From 37c4f28390c0ad2d4fb506d3dca078d2d83ff54b Mon Sep 17 00:00:00 2001
From: Himani <himaniwork3010@gmail.com>
Date: Mon, 25 Nov 2019 12:14:07 +0530
Subject: [PATCH] #42238 Unit test case

---
 .../rest-api/rest-comments-controller.php     | 41 +++++++++++++++++++
 1 file changed, 41 insertions(+)

diff --git a/tests/phpunit/tests/rest-api/rest-comments-controller.php b/tests/phpunit/tests/rest-api/rest-comments-controller.php
index da2d372a54..b85177f7f3 100644
--- a/tests/phpunit/tests/rest-api/rest-comments-controller.php
+++ b/tests/phpunit/tests/rest-api/rest-comments-controller.php
@@ -3240,4 +3240,45 @@ class WP_Test_REST_Comments_Controller extends WP_Test_REST_Controller_Testcase
 			$this->assertArrayNotHasKey( 'raw', $data['content'] );
 		}
 	}
+
+	/**
+	 * @ticket 42238
+	 */
+	public function test_check_read_post_permission_with_invalid_post_type() {
+		regisrer_post_type(
+			'bug-post',
+			array(
+				'label'				=>	'Bug Posts',
+				'supports'			=>	array( 'title', 'editor', 'author', 'excerpt', 'comments', 'revisions' ),
+				'show_in_rest'		=>	true,
+				'public'			=>	true,
+				'has_archive'		=>	true,
+			)
+		);
+		create_initial_rest_routes();
+
+		wp_set_current_user( self::$admin_id );
+
+		self::$post_id     = $factory->post->create(
+			array(
+				'post_title'  => 'Bug Post',
+				'post_type'   => 'bug-post',
+				'post_status' => 'publish',
+			)
+		);
+
+		$this->factory->comment->create_post_comments( self::$post_id, 2 );
+		
+		$request = new WP_REST_REQUEST( 'GET', '/wp/v2/comments' );
+
+		$response = rest_get_server()->dispatch( $request );
+		$this->assertEquals( 200, $response->get_status() );
+
+		_unregister_post_type( 'bug-post' );
+
+		$request = new WP_REST_REQUEST( 'GET', '/wp/v2/comments' );
+		$response = rest_get_server()->dispatch( $request );
+		$this->assertEquals( 200, $response->get_status() );
+
+	}
 }
-- 
2.20.0.windows.1

