@@ -40,6 +40,13 @@ class REST_Block_Renderer_Controller_Test extends WP_Test_REST_Controller_Testca
4040 */
4141 protected static $ post_id ;
4242
43+ /**
44+ * Author test user ID.
45+ *
46+ * @var int
47+ */
48+ protected static $ author_id ;
49+
4350 /**
4451 * Create test data before the tests run.
4552 *
@@ -52,6 +59,12 @@ public static function wpSetUpBeforeClass( $factory ) {
5259 )
5360 );
5461
62+ self ::$ author_id = $ factory ->user ->create (
63+ array (
64+ 'role ' => 'author ' ,
65+ )
66+ );
67+
5568 self ::$ post_id = $ factory ->post ->create ( array (
5669 'post_title ' => 'Test Post ' ,
5770 ) );
@@ -316,6 +329,38 @@ public function test_get_item_with_post_context() {
316329 $ this ->assertEquals ( $ expected_title , $ data ['rendered ' ] );
317330 }
318331
332+ /**
333+ * Test getting item with invalid post ID.
334+ */
335+ public function test_get_item_without_permissions_invalid_post () {
336+ wp_set_current_user ( self ::$ user_id );
337+
338+ $ request = new WP_REST_Request ( 'GET ' , '/gutenberg/v1/block-renderer/ ' . self ::$ context_block_name );
339+ $ request ->set_param ( 'context ' , 'edit ' );
340+
341+ // Test with invalid post ID.
342+ $ request ->set_param ( 'post_id ' , PHP_INT_MAX );
343+ $ response = $ this ->server ->dispatch ( $ request );
344+
345+ $ this ->assertErrorResponse ( 'gutenberg_block_cannot_read ' , $ response , 403 );
346+ }
347+
348+ /**
349+ * Test getting item without permissions to edit context post.
350+ */
351+ public function test_get_item_without_permissions_cannot_edit_post () {
352+ wp_set_current_user ( self ::$ author_id );
353+
354+ $ request = new WP_REST_Request ( 'GET ' , '/gutenberg/v1/block-renderer/ ' . self ::$ context_block_name );
355+ $ request ->set_param ( 'context ' , 'edit ' );
356+
357+ // Test with private post ID.
358+ $ request ->set_param ( 'post_id ' , self ::$ post_id );
359+ $ response = $ this ->server ->dispatch ( $ request );
360+
361+ $ this ->assertErrorResponse ( 'gutenberg_block_cannot_read ' , $ response , 403 );
362+ }
363+
319364 /**
320365 * Get item schema.
321366 *
0 commit comments