Skip to content

Commit bc6eebb

Browse files
Tests: Update content ability REST permissions
1 parent 0cf6c36 commit bc6eebb

1 file changed

Lines changed: 42 additions & 2 deletions

File tree

tests/phpunit/tests/rest-api/wpRestAbilitiesContentController.php

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,50 @@ public function test_subscriber_requesting_drafts_receives_403(): void {
132132
$this->assertSame( 403, $response->get_status() );
133133
}
134134

135-
public function test_subscriber_requesting_published_posts_receives_403(): void {
135+
public function test_subscriber_requesting_published_posts_receives_readable_fields(): void {
136+
$post_id = self::factory()->post->create(
137+
array(
138+
'post_title' => 'Published for subscriber via REST',
139+
'post_content' => 'Subscriber REST body.',
140+
'post_status' => 'publish',
141+
)
142+
);
143+
136144
wp_set_current_user( self::$subscriber_id );
137145

138-
$response = $this->server->dispatch( $this->run_request( array( 'post_type' => 'post' ) ) );
146+
$response = $this->server->dispatch(
147+
$this->run_request(
148+
array(
149+
'post_type' => 'post',
150+
'fields' => array( 'id', 'title_rendered', 'content_rendered' ),
151+
)
152+
)
153+
);
154+
$data = $response->get_data();
155+
156+
$this->assertSame( 200, $response->get_status() );
157+
$this->assertContains( $post_id, wp_list_pluck( $data['posts'], 'id' ) );
158+
159+
$post_index = array_search( $post_id, wp_list_pluck( $data['posts'], 'id' ), true );
160+
$this->assertIsInt( $post_index );
161+
162+
$post = $data['posts'][ $post_index ];
163+
$this->assertSame( 'Published for subscriber via REST', $post['title_rendered'] );
164+
$this->assertStringContainsString( 'Subscriber REST body.', $post['content_rendered'] );
165+
$this->assertArrayNotHasKey( 'content_raw', $post );
166+
}
167+
168+
public function test_subscriber_requesting_raw_fields_receives_403(): void {
169+
wp_set_current_user( self::$subscriber_id );
170+
171+
$response = $this->server->dispatch(
172+
$this->run_request(
173+
array(
174+
'post_type' => 'post',
175+
'fields' => array( 'content_raw' ),
176+
)
177+
)
178+
);
139179

140180
$this->assertSame( 403, $response->get_status() );
141181
}

0 commit comments

Comments
 (0)