Changeset 35745
- Timestamp:
- 11/28/2015 06:28:54 PM (8 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/comment.php
r35725 r35745 2671 2671 $status = get_post_status( $post ); 2672 2672 2673 if ( ( 'private' == $status ) && ! current_user_can( 'read_post', $comment_post_ID ) ) { 2674 return new WP_Error( 'comment_id_not_found' ); 2675 } 2676 2673 2677 $status_obj = get_post_status_object( $status ); 2674 2678 … … 2757 2761 } 2758 2762 } else { 2759 if ( get_option( 'comment_registration' ) || 'private' == $status) {2763 if ( get_option( 'comment_registration' ) ) { 2760 2764 return new WP_Error( 'not_logged_in', __( 'Sorry, you must be logged in to post a comment.' ), 403 ); 2761 2765 } -
trunk/tests/phpunit/tests/comment-submission.php
r35435 r35745 231 231 public function test_submitting_comment_anonymously_to_private_post_returns_error() { 232 232 233 $error = ' not_logged_in';233 $error = 'comment_id_not_found'; 234 234 235 235 $post = self::factory()->post->create_and_get( array( … … 242 242 243 243 $this->assertFalse( is_user_logged_in() ); 244 $this->assertWPError( $comment ); 245 $this->assertSame( $error, $comment->get_error_code() ); 246 247 } 248 249 public function test_submitting_comment_as_logged_in_user_to_inaccessible_private_post_returns_error() { 250 251 $error = 'comment_id_not_found'; 252 253 $author = self::factory()->user->create_and_get( array( 254 'role' => 'author', 255 ) ); 256 $user = self::factory()->user->create_and_get( array( 257 'role' => 'author', 258 ) ); 259 260 wp_set_current_user( $user->ID ); 261 262 $post = self::factory()->post->create_and_get( array( 263 'post_status' => 'private', 264 'post_author' => $author->ID, 265 ) ); 266 $data = array( 267 'comment_post_ID' => $post->ID, 268 ); 269 $comment = wp_handle_comment_submission( $data ); 270 271 $this->assertFalse( current_user_can( 'read_post', $post->ID ) ); 272 $this->assertWPError( $comment ); 273 $this->assertSame( $error, $comment->get_error_code() ); 274 275 } 276 277 public function test_submitting_comment_to_private_post_with_closed_comments_returns_correct_error() { 278 279 $error = 'comment_id_not_found'; 280 281 $author = self::factory()->user->create_and_get( array( 282 'role' => 'author', 283 ) ); 284 $user = self::factory()->user->create_and_get( array( 285 'role' => 'author', 286 ) ); 287 288 wp_set_current_user( $user->ID ); 289 290 $post = self::factory()->post->create_and_get( array( 291 'post_status' => 'private', 292 'post_author' => $author->ID, 293 'comment_status' => 'closed', 294 ) ); 295 $data = array( 296 'comment_post_ID' => $post->ID, 297 ); 298 $comment = wp_handle_comment_submission( $data ); 299 300 $this->assertFalse( current_user_can( 'read_post', $post->ID ) ); 244 301 $this->assertWPError( $comment ); 245 302 $this->assertSame( $error, $comment->get_error_code() );
Note: See TracChangeset
for help on using the changeset viewer.