Skip to content

Commit 0ab9307

Browse files
Apply suggestions from code review
Co-authored-by: Weston Ruter <westonruter@gmail.com>
1 parent 89a755c commit 0ab9307

3 files changed

Lines changed: 26 additions & 22 deletions

File tree

src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1921,7 +1921,7 @@ protected function check_read_permission( $comment, $request ) {
19211921
}
19221922

19231923
/*
1924-
* Notes can be read by any user who can edit the parent post.
1924+
* Notes can be read by any user who can edit the associated post.
19251925
* This is separate from the edit_comment capability, which controls
19261926
* whether a user can modify or delete the note.
19271927
*

tests/phpunit/tests/rest-api/rest-comments-controller.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4139,7 +4139,7 @@ public function test_get_note_with_children_link() {
41394139
*
41404140
* @ticket 64779
41414141
*/
4142-
public function test_contributor_cannot_update_others_note() {
4142+
public function test_contributor_cannot_update_others_note(): void {
41434143
$post_id = self::factory()->post->create(
41444144
array(
41454145
'post_author' => self::$contributor_id,
@@ -4154,6 +4154,7 @@ public function test_contributor_cannot_update_others_note() {
41544154
'comment_content' => 'Admin note',
41554155
)
41564156
);
4157+
assert( is_int( $note_id ) );
41574158

41584159
wp_set_current_user( self::$contributor_id );
41594160

@@ -4169,7 +4170,7 @@ public function test_contributor_cannot_update_others_note() {
41694170
*
41704171
* @ticket 64779
41714172
*/
4172-
public function test_contributor_cannot_delete_others_note() {
4173+
public function test_contributor_cannot_delete_others_note(): void {
41734174
$post_id = self::factory()->post->create(
41744175
array(
41754176
'post_author' => self::$contributor_id,
@@ -4184,6 +4185,7 @@ public function test_contributor_cannot_delete_others_note() {
41844185
'comment_content' => 'Admin note',
41854186
)
41864187
);
4188+
assert( is_int( $note_id ) );
41874189

41884190
wp_set_current_user( self::$contributor_id );
41894191

@@ -4206,31 +4208,32 @@ public function test_note_author_can_update_own_note() {
42064208
'post_status' => 'draft',
42074209
)
42084210
);
4209-
$note_id = self::factory()->comment->create(
4211+
$note = self::factory()->comment->create_and_get(
42104212
array(
42114213
'comment_post_ID' => $post_id,
42124214
'comment_type' => 'note',
42134215
'user_id' => self::$contributor_id,
42144216
'comment_content' => 'Original content',
42154217
)
42164218
);
4219+
assert( $note instanceof WP_Comment );
42174220

42184221
wp_set_current_user( self::$contributor_id );
42194222

4220-
$request = new WP_REST_Request( 'PUT', '/wp/v2/comments/' . $note_id );
4223+
$request = new WP_REST_Request( 'PUT', '/wp/v2/comments/' . $note->comment_ID);
42214224
$request->set_param( 'content', 'Updated content' );
42224225
$response = rest_get_server()->dispatch( $request );
42234226

42244227
$this->assertSame( 200, $response->get_status() );
4225-
$this->assertSame( 'Updated content', get_comment( $note_id )->comment_content );
4228+
$this->assertSame( 'Updated content', $note->comment_content );
42264229
}
42274230

42284231
/**
42294232
* Tests that an editor can update another user's note via the REST API.
42304233
*
42314234
* @ticket 64779
42324235
*/
4233-
public function test_editor_can_update_others_note() {
4236+
public function test_editor_can_update_others_note(): void {
42344237
$post_id = self::factory()->post->create(
42354238
array(
42364239
'post_author' => self::$contributor_id,
@@ -4245,6 +4248,7 @@ public function test_editor_can_update_others_note() {
42454248
'comment_content' => 'Contributor note',
42464249
)
42474250
);
4251+
assert( is_int( $note_id ) );
42484252

42494253
wp_set_current_user( self::$editor_id );
42504254

@@ -4260,7 +4264,7 @@ public function test_editor_can_update_others_note() {
42604264
*
42614265
* @ticket 64779
42624266
*/
4263-
public function test_contributor_can_read_others_notes_on_own_post() {
4267+
public function test_contributor_can_read_others_notes_on_own_post(): void {
42644268
$post_id = self::factory()->post->create(
42654269
array(
42664270
'post_author' => self::$contributor_id,

tests/phpunit/tests/user/capabilities.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2601,7 +2601,7 @@ public function test_role_capabilities_updated_correctly_via_update_option() {
26012601
* @ticket 64779
26022602
* @covers ::map_meta_cap
26032603
*/
2604-
public function test_note_author_can_edit_own_note() {
2604+
public function test_note_author_can_edit_own_note(): void {
26052605
$contributor = self::$users['contributor'];
26062606
$post_id = self::factory()->post->create( array( 'post_author' => $contributor->ID ) );
26072607
$note_id = self::factory()->comment->create(
@@ -2621,7 +2621,7 @@ public function test_note_author_can_edit_own_note() {
26212621
* @ticket 64779
26222622
* @covers ::map_meta_cap
26232623
*/
2624-
public function test_note_author_can_delete_own_note() {
2624+
public function test_note_author_can_delete_own_note(): void {
26252625
$contributor = self::$users['contributor'];
26262626
$post_id = self::factory()->post->create( array( 'post_author' => $contributor->ID ) );
26272627
$note_id = self::factory()->comment->create(
@@ -2641,7 +2641,7 @@ public function test_note_author_can_delete_own_note() {
26412641
* @ticket 64779
26422642
* @covers ::map_meta_cap
26432643
*/
2644-
public function test_non_author_cannot_edit_others_note() {
2644+
public function test_non_author_cannot_edit_others_note(): void {
26452645
$contributor = self::$users['contributor'];
26462646
$admin = self::$users['administrator'];
26472647
$post_id = self::factory()->post->create( array( 'post_author' => $contributor->ID ) );
@@ -2665,7 +2665,7 @@ public function test_non_author_cannot_edit_others_note() {
26652665
* @ticket 64779
26662666
* @covers ::map_meta_cap
26672667
*/
2668-
public function test_non_author_cannot_delete_others_note() {
2668+
public function test_non_author_cannot_delete_others_note(): void {
26692669
$contributor = self::$users['contributor'];
26702670
$admin = self::$users['administrator'];
26712671
$post_id = self::factory()->post->create( array( 'post_author' => $contributor->ID ) );
@@ -2689,7 +2689,7 @@ public function test_non_author_cannot_delete_others_note() {
26892689
* @ticket 64779
26902690
* @covers ::map_meta_cap
26912691
*/
2692-
public function test_moderator_can_edit_others_note() {
2692+
public function test_moderator_can_edit_others_note(): void {
26932693
$editor = self::$users['editor'];
26942694
$contributor = self::$users['contributor'];
26952695
$post_id = self::factory()->post->create( array( 'post_author' => $contributor->ID ) );
@@ -2713,7 +2713,7 @@ public function test_moderator_can_edit_others_note() {
27132713
* @ticket 64779
27142714
* @covers ::map_meta_cap
27152715
*/
2716-
public function test_moderator_can_delete_others_note() {
2716+
public function test_moderator_can_delete_others_note(): void {
27172717
$editor = self::$users['editor'];
27182718
$contributor = self::$users['contributor'];
27192719
$post_id = self::factory()->post->create( array( 'post_author' => $contributor->ID ) );
@@ -2737,7 +2737,7 @@ public function test_moderator_can_delete_others_note() {
27372737
* @ticket 64779
27382738
* @covers ::map_meta_cap
27392739
*/
2740-
public function test_author_cannot_edit_others_note() {
2740+
public function test_author_cannot_edit_others_note(): void {
27412741
$author = self::$users['author'];
27422742
$editor = self::$users['editor'];
27432743
$post_id = self::factory()->post->create( array( 'post_author' => $author->ID ) );
@@ -2763,7 +2763,7 @@ public function test_author_cannot_edit_others_note() {
27632763
* @ticket 64779
27642764
* @covers ::map_meta_cap
27652765
*/
2766-
public function test_subscriber_cannot_edit_own_note() {
2766+
public function test_subscriber_cannot_edit_own_note(): void {
27672767
$subscriber = self::$users['subscriber'];
27682768
$post_id = self::factory()->post->create();
27692769
$note_id = self::factory()->comment->create(
@@ -2786,7 +2786,7 @@ public function test_subscriber_cannot_edit_own_note() {
27862786
* @ticket 64779
27872787
* @covers ::map_meta_cap
27882788
*/
2789-
public function test_edit_regular_comment_unchanged() {
2789+
public function test_edit_regular_comment_unchanged(): void {
27902790
$contributor = self::$users['contributor'];
27912791
$admin = self::$users['administrator'];
27922792
$post_id = self::factory()->post->create(
@@ -2815,7 +2815,7 @@ public function test_edit_regular_comment_unchanged() {
28152815
* @ticket 64779
28162816
* @covers ::map_meta_cap
28172817
*/
2818-
public function test_delete_regular_comment_maps_to_edit_post() {
2818+
public function test_delete_regular_comment_maps_to_edit_post(): void {
28192819
$contributor = self::$users['contributor'];
28202820
$admin = self::$users['administrator'];
28212821
$post_id = self::factory()->post->create(
@@ -2844,7 +2844,7 @@ public function test_delete_regular_comment_maps_to_edit_post() {
28442844
* @ticket 64779
28452845
* @covers ::map_meta_cap
28462846
*/
2847-
public function test_edit_comment_nonexistent_comment() {
2847+
public function test_edit_comment_nonexistent_comment(): void {
28482848
$admin = self::$users['administrator'];
28492849

28502850
$this->assertFalse( user_can( $admin->ID, 'edit_comment', PHP_INT_MAX ) );
@@ -2856,7 +2856,7 @@ public function test_edit_comment_nonexistent_comment() {
28562856
* @ticket 64779
28572857
* @covers ::map_meta_cap
28582858
*/
2859-
public function test_delete_comment_nonexistent_comment() {
2859+
public function test_delete_comment_nonexistent_comment(): void {
28602860
$admin = self::$users['administrator'];
28612861

28622862
$this->assertFalse( user_can( $admin->ID, 'delete_comment', PHP_INT_MAX ) );
@@ -2869,7 +2869,7 @@ public function test_delete_comment_nonexistent_comment() {
28692869
* @covers ::map_meta_cap
28702870
* @expectedIncorrectUsage map_meta_cap
28712871
*/
2872-
public function test_edit_comment_without_argument() {
2872+
public function test_edit_comment_without_argument(): void {
28732873
$admin = self::$users['administrator'];
28742874

28752875
$this->assertFalse( user_can( $admin->ID, 'edit_comment' ) );
@@ -2882,7 +2882,7 @@ public function test_edit_comment_without_argument() {
28822882
* @covers ::map_meta_cap
28832883
* @expectedIncorrectUsage map_meta_cap
28842884
*/
2885-
public function test_delete_comment_without_argument() {
2885+
public function test_delete_comment_without_argument(): void {
28862886
$admin = self::$users['administrator'];
28872887

28882888
$this->assertFalse( user_can( $admin->ID, 'delete_comment' ) );

0 commit comments

Comments
 (0)