Changeset 53432
- Timestamp:
- 05/23/2022 02:04:23 PM (2 years ago)
- Location:
- branches/6.0
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/6.0
- Property svn:mergeinfo changed
/trunk merged: 53353,53430
- Property svn:mergeinfo changed
-
branches/6.0/tests/phpunit/includes/abstract-testcase.php
r53350 r53432 172 172 $current_screen_globals = array( 'current_screen', 'taxnow', 'typenow' ); 173 173 foreach ( $current_screen_globals as $global ) { 174 $GLOBALS[ $global ] = null; 175 } 176 177 // Reset comment globals. 178 $comment_globals = array( 'comment_alt', 'comment_depth', 'comment_thread_alt' ); 179 foreach ( $comment_globals as $global ) { 174 180 $GLOBALS[ $global ] = null; 175 181 } -
branches/6.0/tests/phpunit/tests/blocks/renderCommentTemplate.php
r53389 r53432 21 21 private static $per_page = 5; 22 22 23 /** 24 * Array of the comments options and their original values. 25 * Used to reset the options after each test. 26 * 27 * @var array 28 */ 29 private static $original_options; 30 31 public static function set_up_before_class() { 32 parent::set_up_before_class(); 33 34 // Store the original option values. 35 $options = array( 36 'comment_order', 37 'comments_per_page', 38 'default_comments_page', 39 'page_comments', 40 'previous_default_page', 41 'thread_comments_depth', 42 ); 43 foreach ( $options as $option ) { 44 static::$original_options[ $option ] = get_option( $option ); 45 } 46 47 // Reset comment globals. 48 $comment_globals = array( 'comment_alt', 'comment_depth', 'comment_thread_alt' ); 49 foreach ( $comment_globals as $global ) { 50 $GLOBALS[ $global ] = null; 51 } 52 } 53 54 public function tear_down() { 55 // Reset the comment options to their original values. 56 foreach ( static::$original_options as $option => $original_value ) { 57 update_option( $option, $original_value ); 58 } 59 60 // Reset comment globals. 61 $comment_globals = array( 'comment_alt', 'comment_depth', 'comment_thread_alt' ); 62 foreach ( $comment_globals as $global ) { 63 $GLOBALS[ $global ] = null; 64 } 65 66 parent::tear_down(); 67 } 68 23 69 public function set_up() { 24 70 parent::set_up(); … … 26 72 update_option( 'page_comments', true ); 27 73 update_option( 'comments_per_page', self::$per_page ); 28 update_option( 'comment_order', 'ASC' );29 74 30 75 self::$custom_post = self::factory()->post->create_and_get( … … 110 155 build_comment_query_vars_from_block( $block ) 111 156 ); 112 update_option( 'page_comments', true );113 157 } 114 158 … … 188 232 build_comment_query_vars_from_block( $block ) 189 233 ); 190 191 update_option( 'comments_per_page', $comments_per_page );192 update_option( 'default_comments_page', $default_comments_page );193 234 } 194 235 … … 262 303 * └─ comment 1 263 304 * └─ comment 2 264 * └─ comment 3265 305 * └─ comment 4 266 * └─ comment 5306 * └─ comment 3 267 307 * 268 308 * @ticket 55567 … … 310 350 <<<END 311 351 <ol class="wp-block-comment-template"> 312 <li id="comment-{$top_level_ids[0]}" class="comment odd alt thread-odd thread-altdepth-1">352 <li id="comment-{$top_level_ids[0]}" class="comment even thread-even depth-1"> 313 353 <div class="wp-block-comment-author-name"> 314 354 <a rel="external nofollow ugc" href="http://example.com/author-url/" target="_self" > … … 320 360 </div> 321 361 <ol> 322 <li id="comment-{$first_level_ids[0]}" class="comment evendepth-2">362 <li id="comment-{$first_level_ids[0]}" class="comment odd alt depth-2"> 323 363 <div class="wp-block-comment-author-name"> 324 364 <a rel="external nofollow ugc" href="http://example.com/author-url/" target="_self" > … … 330 370 </div> 331 371 <ol> 332 <li id="comment-{$second_level_ids[0]}" class="comment odd altdepth-3">372 <li id="comment-{$second_level_ids[0]}" class="comment even depth-3"> 333 373 <div class="wp-block-comment-author-name"> 334 374 <a rel="external nofollow ugc" href="http://example.com/author-url/" target="_self" > … … 342 382 </ol> 343 383 </li> 344 <li id="comment-{$first_level_ids[1]}" class="comment evendepth-2">384 <li id="comment-{$first_level_ids[1]}" class="comment odd alt depth-2"> 345 385 <div class="wp-block-comment-author-name"> 346 386 <a rel="external nofollow ugc" href="http://example.com/author-url/" target="_self" > … … 365 405 366 406 /** 407 * Test that line and paragraph breaks are converted to HTML tags in a comment. 408 * 409 * @ticket 55643 410 */ 411 function test_render_block_core_comment_content_converts_to_html() { 412 $comment_id = self::$comment_ids[0]; 413 $new_content = "Paragraph One\n\nP2L1\nP2L2\n\nhttps://example.com/"; 414 self::factory()->comment->update_object( 415 $comment_id, 416 array( 'comment_content' => $new_content ) 417 ); 418 419 $parsed_blocks = parse_blocks( 420 '<!-- wp:comment-template --><!-- wp:comment-content /--><!-- /wp:comment-template -->' 421 ); 422 423 $block = new WP_Block( 424 $parsed_blocks[0], 425 array( 426 'postId' => self::$custom_post->ID, 427 'comments/inherit' => true, 428 ) 429 ); 430 431 $expected_content = "<p>Paragraph One</p>\n<p>P2L1<br />\nP2L2</p>\n<p><a href=\"https://example.com/\" rel=\"nofollow ugc\">https://example.com/</a></p>\n"; 432 433 $this->assertSame( 434 '<ol class="wp-block-comment-template"><li id="comment-' . self::$comment_ids[0] . '" class="comment even thread-even depth-1"><div class="wp-block-comment-content">' . $expected_content . '</div></li></ol>', 435 $block->render() 436 ); 437 } 438 439 /** 367 440 * Test that unapproved comments are included if it is a preview. 368 441 * … … 405 478 ); 406 479 } 480 481 /** 482 * Test rendering an unapproved comment preview. 483 * 484 * @ticket 55643 485 */ 486 function test_rendering_comment_template_unmoderated_preview() { 487 $parsed_blocks = parse_blocks( 488 '<!-- wp:comment-template --><!-- wp:comment-author-name /--><!-- wp:comment-content /--><!-- /wp:comment-template -->' 489 ); 490 491 $unapproved_comment = self::factory()->comment->create_post_comments( 492 self::$custom_post->ID, 493 1, 494 array( 495 'comment_author' => 'Visitor', 496 'comment_author_email' => 'unapproved@example.org', 497 'comment_author_url' => 'http://example.com/unapproved/', 498 'comment_content' => 'Hi there! My comment needs moderation.', 499 'comment_approved' => 0, 500 ) 501 ); 502 503 $block = new WP_Block( 504 $parsed_blocks[0], 505 array( 506 'postId' => self::$custom_post->ID, 507 ) 508 ); 509 510 $commenter_filter = static function () { 511 return array( 512 'comment_author_email' => 'unapproved@example.org', 513 ); 514 }; 515 516 add_filter( 'wp_get_current_commenter', $commenter_filter ); 517 518 $this->assertSame( 519 '<ol class="wp-block-comment-template"><li id="comment-' . self::$comment_ids[0] . '" class="comment even thread-even depth-1"><div class="wp-block-comment-author-name"><a rel="external nofollow ugc" href="http://example.com/author-url/" target="_self" >Test</a></div><div class="wp-block-comment-content"><p>Hello world</p></div></li><li id="comment-' . $unapproved_comment[0] . '" class="comment odd alt thread-odd thread-alt depth-1"><div class="wp-block-comment-author-name">Visitor</div><div class="wp-block-comment-content"><p><em class="comment-awaiting-moderation">Your comment is awaiting moderation.</em></p>Hi there! My comment needs moderation.</div></li></ol>', 520 str_replace( array( "\n", "\t" ), '', $block->render() ), 521 'Should include unapproved comments when filter applied' 522 ); 523 524 remove_filter( 'wp_get_current_commenter', $commenter_filter ); 525 526 // Test it again and ensure the unmoderated comment doesn't leak out. 527 $this->assertSame( 528 '<ol class="wp-block-comment-template"><li id="comment-' . self::$comment_ids[0] . '" class="comment even thread-even depth-1"><div class="wp-block-comment-author-name"><a rel="external nofollow ugc" href="http://example.com/author-url/" target="_self" >Test</a></div><div class="wp-block-comment-content"><p>Hello world</p></div></li></ol>', 529 str_replace( array( "\n", "\t" ), '', $block->render() ), 530 'Should not include any unapproved comments after removing filter' 531 ); 532 } 407 533 }
Note: See TracChangeset
for help on using the changeset viewer.