Ticket #50044: 50044.diff
File 50044.diff, 24.0 KB (added by , 17 months ago) |
---|
-
src/wp-admin/about.php
diff --git src/wp-admin/about.php src/wp-admin/about.php index 709670f9f0..b52873425d 100644
require_once ABSPATH . 'wp-admin/admin-header.php'; 280 280 281 281 <div class="return-to-dashboard"> 282 282 <?php if ( current_user_can( 'update_core' ) && isset( $_GET['updated'] ) ) : ?> 283 <a href="<?php echo esc_url( self_admin_url( 'update-core.php' ) ); ?>"><?php is_multisite() ? _e( 'Go to Updates' ) : _e( 'Go to Dashboard → Updates' ); ?></a> | 283 <a href="<?php echo esc_url( self_admin_url( 'update-core.php' ) ); ?>"> 284 <?php is_multisite() ? _e( 'Go to Updates' ) : _e( 'Go to Dashboard → Updates' ); ?> 285 </a> | 284 286 <?php endif; ?> 285 287 <a href="<?php echo esc_url( self_admin_url() ); ?>"><?php is_blog_admin() ? _e( 'Go to Dashboard → Home' ) : _e( 'Go to Dashboard' ); ?></a> 286 288 </div> -
src/wp-admin/admin-header.php
diff --git src/wp-admin/admin-header.php src/wp-admin/admin-header.php index eebe96f36b..3306c9125b 100644
unset( $error_get_last ); 242 242 $admin_body_classes = apply_filters( 'admin_body_class', '' ); 243 243 $admin_body_classes = ltrim( $admin_body_classes . ' ' . $admin_body_class ); 244 244 ?> 245 <body class="wp-admin wp-core-ui no-js <?php echo esc_attr( $admin_body_classes ); ?>">245 <body class="wp-admin wp-core-ui no-js <?php echo $admin_body_classes; ?>"> 246 246 <script type="text/javascript"> 247 247 document.body.className = document.body.className.replace('no-js','js'); 248 248 </script> -
src/wp-admin/includes/template.php
diff --git src/wp-admin/includes/template.php src/wp-admin/includes/template.php index da8c363571..21999bbfce 100644
var ajaxurl = '<?php echo esc_js( admin_url( 'admin-ajax.php', 'relative' ) ); ? 2178 2178 $admin_body_classes = apply_filters( 'admin_body_class', '' ); 2179 2179 $admin_body_classes = ltrim( $admin_body_classes . ' ' . $admin_body_class ); 2180 2180 ?> 2181 <body <?php echo $admin_body_id; ?>class="wp-admin wp-core-ui no-js iframe <?php echo esc_attr( $admin_body_classes ); ?>">2181 <body <?php echo $admin_body_id; ?>class="wp-admin wp-core-ui no-js iframe <?php echo $admin_body_classes; ?>"> 2182 2182 <script type="text/javascript"> 2183 2183 (function(){ 2184 2184 var c = document.body.className; -
src/wp-includes/class-wp-query.php
diff --git src/wp-includes/class-wp-query.php src/wp-includes/class-wp-query.php index 38b89601fb..6b9e9d0bb8 100644
class WP_Query { 108 108 */ 109 109 public $current_post = -1; 110 110 111 /**112 * Whether the caller is before the loop.113 *114 * @since 6.3.0115 * @var bool116 */117 public $before_loop = true;118 119 111 /** 120 112 * Whether the loop has started and the caller is in the loop. 121 113 * … … class WP_Query { 525 517 $this->post_count = 0; 526 518 $this->current_post = -1; 527 519 $this->in_the_loop = false; 528 $this->before_loop = true;529 520 unset( $this->request ); 530 521 unset( $this->post ); 531 522 unset( $this->comments ); … … class WP_Query { 3640 3631 } 3641 3632 3642 3633 $this->in_the_loop = true; 3643 $this->before_loop = false;3644 3634 3645 3635 if ( -1 == $this->current_post ) { // Loop has just started. 3646 3636 /** … … class WP_Query { 3681 3671 // Do some cleaning up after the loop. 3682 3672 $this->rewind_posts(); 3683 3673 } elseif ( 0 === $this->post_count ) { 3684 $this->before_loop = false;3685 3686 3674 /** 3687 3675 * Fires if no results are found in a post query. 3688 3676 * -
src/wp-includes/feed.php
diff --git src/wp-includes/feed.php src/wp-includes/feed.php index 7b91cbb70b..c703a05a3a 100644
function rss2_site_icon() { 658 658 * @return string Correct link for the atom:self element. 659 659 */ 660 660 function get_self_link() { 661 $host = parse_url( home_url() ); 662 return set_url_scheme( 'http://' . $host['host'] . wp_unslash( $_SERVER['REQUEST_URI'] ) ); 661 $host = parse_url( home_url() ); 662 $scheme = 'http://'; 663 if ( isset( $host['scheme'] ) ) { 664 $scheme = "{$host['scheme']}://"; 665 } 666 $port = ''; 667 if ( isset( $host['port'] ) ) { 668 $port = ":{$host['port']}"; 669 } 670 $request_uri = wp_unslash( $_SERVER['REQUEST_URI'] ); 671 return set_url_scheme( 672 sprintf( 673 '%1$s%2$s%3$s%4$s', 674 $scheme, 675 $host['host'], 676 $port, 677 $request_uri 678 ) 679 ); 663 680 } 664 681 665 682 /** -
src/wp-includes/media.php
diff --git src/wp-includes/media.php src/wp-includes/media.php index b7d525555b..3ea2863414 100644
function wp_get_webp_info( $filename ) { 5490 5490 * 5491 5491 * @since 5.9.0 5492 5492 * 5493 * @global WP_Query $wp_query WordPress Query object.5494 *5495 5493 * @param string $context Context for the element for which the `loading` attribute value is requested. 5496 5494 * @return string|bool The default `loading` attribute value. Either 'lazy', 'eager', or a boolean `false`, to indicate 5497 5495 * that the `loading` attribute should be skipped. 5498 5496 */ 5499 5497 function wp_get_loading_attr_default( $context ) { 5500 global $wp_query;5501 5502 5498 // Skip lazy-loading for the overall block template, as it is handled more granularly. 5503 5499 if ( 'template' === $context ) { 5504 5500 return false; 5505 5501 } 5506 5502 5507 5503 // Do not lazy-load images in the header block template part, as they are likely above the fold. 5508 // For classic themes, this is handled in the condition below using the 'get_header' action.5509 5504 $header_area = WP_TEMPLATE_PART_AREA_HEADER; 5510 5505 if ( "template_part_{$header_area}" === $context ) { 5511 5506 return false; 5512 5507 } 5513 5508 5514 // Special handling for programmatically created image tags. 5515 if ( ( 'the_post_thumbnail' === $context || 'wp_get_attachment_image' === $context ) ) { 5516 /* 5517 * Skip programmatically created images within post content as they need to be handled together with the other 5518 * images within the post content. 5519 * Without this clause, they would already be counted below which skews the number and can result in the first 5520 * post content image being lazy-loaded only because there are images elsewhere in the post content. 5521 */ 5522 if ( doing_filter( 'the_content' ) ) { 5523 return false; 5524 } 5525 5526 // Conditionally skip lazy-loading on images before the loop. 5527 if ( 5528 // Only apply for main query but before the loop. 5529 $wp_query->before_loop && $wp_query->is_main_query() 5530 /* 5531 * Any image before the loop, but after the header has started should not be lazy-loaded, 5532 * except when the footer has already started which can happen when the current template 5533 * does not include any loop. 5534 */ 5535 && did_action( 'get_header' ) && ! did_action( 'get_footer' ) 5536 ) { 5537 return false; 5538 } 5509 /* 5510 * Skip programmatically created images within post content as they need to be handled together with the other 5511 * images within the post content. 5512 * Without this clause, they would already be counted below which skews the number and can result in the first 5513 * post content image being lazy-loaded only because there are images elsewhere in the post content. 5514 */ 5515 if ( ( 'the_post_thumbnail' === $context || 'wp_get_attachment_image' === $context ) && doing_filter( 'the_content' ) ) { 5516 return false; 5539 5517 } 5540 5518 5541 5519 /* -
src/wp-includes/post.php
diff --git src/wp-includes/post.php src/wp-includes/post.php index fabd68edb2..77a1a49238 100644
function get_pages( $args = array() ) { 6031 6031 } 6032 6032 $post_author = $post_author->ID; 6033 6033 } 6034 $query_args['author__in'][] = (int)$post_author;6034 $query_args['author__in'][] = $post_author; 6035 6035 } 6036 6036 } 6037 6037 } … … function get_pages( $args = array() ) { 6060 6060 $query_args['posts_per_page'] = $number; 6061 6061 } 6062 6062 6063 /**6064 * Filters query arguments passed to WP_Query in get_pages.6065 *6066 * @since 6.3.06067 *6068 * @param array $query_args Array of arguments passed to WP_Query.6069 * @param array $parsed_args Array of get_pages() arguments.6070 */6071 $query_args = apply_filters( 'get_pages_query_args', $query_args, $parsed_args );6072 6073 6063 $query = new WP_Query( $query_args ); 6074 6064 $pages = $query->get_posts(); 6075 6065 -
tests/phpunit/tests/media.php
diff --git tests/phpunit/tests/media.php tests/phpunit/tests/media.php index c38a17d1cf..cf7c72b06d 100644
EOF; 3559 3559 * @param string $context 3560 3560 */ 3561 3561 public function test_wp_get_loading_attr_default( $context ) { 3562 global $wp_query, $wp_the_query; 3563 3562 3564 // Return 'lazy' by default. 3563 3565 $this->assertSame( 'lazy', wp_get_loading_attr_default( 'test' ) ); 3564 3566 $this->assertSame( 'lazy', wp_get_loading_attr_default( 'wp_get_attachment_image' ) ); … … EOF; 3566 3568 // Return 'lazy' if not in the loop or the main query. 3567 3569 $this->assertSame( 'lazy', wp_get_loading_attr_default( $context ) ); 3568 3570 3569 $ query = $this->get_new_wp_query_for_published_post();3571 $wp_query = new WP_Query( array( 'post__in' => array( self::$post_ids['publish'] ) ) ); 3570 3572 $this->reset_content_media_count(); 3571 3573 $this->reset_omit_loading_attr_filter(); 3572 3574 … … EOF; 3577 3579 $this->assertSame( 'lazy', wp_get_loading_attr_default( $context ) ); 3578 3580 3579 3581 // Set as main query. 3580 $ this->set_main_query( $query );3582 $wp_the_query = $wp_query; 3581 3583 3582 3584 // For contexts other than for the main content, still return 'lazy' even in the loop 3583 3585 // and in the main query, and do not increase the content media count. … … EOF; 3611 3613 * @ticket 53675 3612 3614 */ 3613 3615 public function test_wp_omit_loading_attr_threshold_filter() { 3614 $query = $this->get_new_wp_query_for_published_post(); 3615 $this->set_main_query( $query ); 3616 global $wp_query, $wp_the_query; 3617 3618 $wp_query = new WP_Query( array( 'post__in' => array( self::$post_ids['publish'] ) ) ); 3619 $wp_the_query = $wp_query; 3616 3620 $this->reset_content_media_count(); 3617 3621 $this->reset_omit_loading_attr_filter(); 3618 3622 … … EOF; 3636 3640 * @ticket 53675 3637 3641 */ 3638 3642 public function test_wp_filter_content_tags_with_wp_get_loading_attr_default() { 3643 global $wp_query, $wp_the_query; 3644 3639 3645 $img1 = get_image_tag( self::$large_id, '', '', '', 'large' ); 3640 3646 $iframe1 = '<iframe src="https://www.example.com" width="640" height="360"></iframe>'; 3641 3647 $img2 = get_image_tag( self::$large_id, '', '', '', 'medium' ); … … EOF; 3653 3659 $content_expected = $img1 . $iframe1 . $lazy_img2 . $lazy_img3 . $lazy_iframe2; 3654 3660 $content_expected = wp_img_tag_add_decoding_attr( $content_expected, 'the_content' ); 3655 3661 3656 $ query = $this->get_new_wp_query_for_published_post();3657 $ this->set_main_query( $query );3662 $wp_query = new WP_Query( array( 'post__in' => array( self::$post_ids['publish'] ) ) ); 3663 $wp_the_query = $wp_query; 3658 3664 $this->reset_content_media_count(); 3659 3665 $this->reset_omit_loading_attr_filter(); 3660 3666 … … EOF; 3692 3698 $this->assertSame( 1, $omit_threshold ); 3693 3699 } 3694 3700 3695 /**3696 * Tests that wp_get_loading_attr_default() returns the expected loading attribute value before loop but after get_header if not main query.3697 *3698 * @ticket 582113699 *3700 * @covers ::wp_get_loading_attr_default3701 *3702 * @dataProvider data_wp_get_loading_attr_default_before_and_no_loop3703 *3704 * @param string $context Context for the element for which the `loading` attribute value is requested.3705 */3706 public function test_wp_get_loading_attr_default_before_loop_if_not_main_query( $context ) {3707 global $wp_query;3708 3709 $wp_query = $this->get_new_wp_query_for_published_post();3710 $this->reset_content_media_count();3711 $this->reset_omit_loading_attr_filter();3712 3713 do_action( 'get_header' );3714 3715 // Lazy if not main query.3716 $this->assertSame( 'lazy', wp_get_loading_attr_default( $context ) );3717 }3718 3719 /**3720 * Tests that wp_get_loading_attr_default() returns the expected loading attribute value before loop but after get_header in main query but header was not called.3721 *3722 * @ticket 582113723 *3724 * @covers ::wp_get_loading_attr_default3725 *3726 * @dataProvider data_wp_get_loading_attr_default_before_and_no_loop3727 *3728 * @param string $context Context for the element for which the `loading` attribute value is requested.3729 */3730 public function test_wp_get_loading_attr_default_before_loop_in_main_query_but_header_not_called( $context ) {3731 global $wp_query;3732 3733 $wp_query = $this->get_new_wp_query_for_published_post();3734 $this->set_main_query( $wp_query );3735 $this->reset_content_media_count();3736 $this->reset_omit_loading_attr_filter();3737 3738 // Lazy if header not called.3739 $this->assertSame( 'lazy', wp_get_loading_attr_default( $context ) );3740 }3741 3742 /**3743 * Tests that wp_get_loading_attr_default() returns the expected loading attribute value before loop but after get_header for main query.3744 *3745 * @ticket 582113746 *3747 * @covers ::wp_get_loading_attr_default3748 *3749 * @dataProvider data_wp_get_loading_attr_default_before_and_no_loop3750 *3751 * @param string $context Context for the element for which the `loading` attribute value is requested.3752 */3753 public function test_wp_get_loading_attr_default_before_loop_if_main_query( $context ) {3754 global $wp_query;3755 3756 $wp_query = $this->get_new_wp_query_for_published_post();3757 $this->set_main_query( $wp_query );3758 $this->reset_content_media_count();3759 $this->reset_omit_loading_attr_filter();3760 3761 do_action( 'get_header' );3762 $this->assertFalse( wp_get_loading_attr_default( $context ) );3763 }3764 3765 /**3766 * Tests that wp_get_loading_attr_default() returns the expected loading attribute value after get_header and after loop.3767 *3768 * @ticket 582113769 *3770 * @covers ::wp_get_loading_attr_default3771 *3772 * @dataProvider data_wp_get_loading_attr_default_before_and_no_loop3773 *3774 * @param string $context Context for the element for which the `loading` attribute value is requested.3775 */3776 public function test_wp_get_loading_attr_default_after_loop( $context ) {3777 global $wp_query;3778 3779 $wp_query = $this->get_new_wp_query_for_published_post();3780 $this->set_main_query( $wp_query );3781 $this->reset_content_media_count();3782 $this->reset_omit_loading_attr_filter();3783 3784 do_action( 'get_header' );3785 3786 while ( have_posts() ) {3787 the_post();3788 }3789 $this->assertSame( 'lazy', wp_get_loading_attr_default( $context ) );3790 }3791 3792 /**3793 * Tests that wp_get_loading_attr_default() returns the expected loading attribute if no loop.3794 *3795 * @ticket 582113796 *3797 * @covers ::wp_get_loading_attr_default3798 *3799 * @dataProvider data_wp_get_loading_attr_default_before_and_no_loop3800 *3801 * @param string $context Context for the element for which the `loading` attribute value is requested.3802 */3803 public function test_wp_get_loading_attr_default_no_loop( $context ) {3804 global $wp_query;3805 3806 $wp_query = $this->get_new_wp_query_for_published_post();3807 $this->set_main_query( $wp_query );3808 $this->reset_content_media_count();3809 $this->reset_omit_loading_attr_filter();3810 3811 // Ensure header and footer is called.3812 do_action( 'get_header' );3813 do_action( 'get_footer' );3814 3815 // Load lazy if the there is no loop and footer was called.3816 $this->assertSame( 'lazy', wp_get_loading_attr_default( $context ) );3817 }3818 3819 /**3820 * Data provider.3821 *3822 * @return array[]3823 */3824 public function data_wp_get_loading_attr_default_before_and_no_loop() {3825 return array(3826 array( 'wp_get_attachment_image' ),3827 array( 'the_post_thumbnail' ),3828 );3829 }3830 3831 3701 /** 3832 3702 * Tests that wp_filter_content_tags() does not add loading="lazy" to the first 3833 3703 * image in the loop when using a block theme. … … EOF; 4296 4166 } 4297 4167 ); 4298 4168 } 4299 4300 /**4301 * Returns a new WP_Query.4302 *4303 * @global WP_Query $wp_query WordPress Query object.4304 *4305 * @return WP_Query a new query.4306 */4307 public function get_new_wp_query_for_published_post() {4308 global $wp_query;4309 4310 // New query to $wp_query. update global for the loop.4311 $wp_query = new WP_Query( array( 'post__in' => array( self::$post_ids['publish'] ) ) );4312 4313 return $wp_query;4314 }4315 4316 /**4317 * Sets a query as main query.4318 *4319 * @global WP_Query $wp_the_query WordPress Query object.4320 *4321 * @param WP_Query $query query to be set as main query.4322 */4323 public function set_main_query( $query ) {4324 global $wp_the_query;4325 $wp_the_query = $query;4326 }4327 4169 } 4328 4170 4329 4171 /** -
tests/phpunit/tests/post/getPages.php
diff --git tests/phpunit/tests/post/getPages.php tests/phpunit/tests/post/getPages.php index 92de3356fa..904de785d9 100644
class Tests_Post_GetPages extends WP_UnitTestCase { 325 325 $this->assertSame( $inc, $exc_result ); 326 326 } 327 327 328 /**329 * @ticket 12821330 * @covers ::get_pages331 */332 public function test_get_pages_test_filter() {333 register_post_type( 'wptests_pt', array( 'hierarchical' => true ) );334 335 $posts = self::factory()->post->create_many(336 2,337 array(338 'post_type' => 'wptests_pt',339 )340 );341 $query_args_values = array();342 $parsed_args_values = array();343 344 // Filter the query to return the wptests_pt post type.345 add_filter(346 'get_pages_query_args',347 static function( $query_args, $parsed_args ) use ( &$query_args_values, &$parsed_args_values ) {348 $query_args['post_type'] = 'wptests_pt';349 $query_args_values = $query_args;350 $parsed_args_values = $parsed_args;351 return $query_args;352 },353 10,354 2355 );356 357 $pages = get_pages();358 $page_ids = wp_list_pluck( $pages, 'ID' );359 $this->assertSameSets( $posts, $page_ids, 'The return post ids should match the post type wptests_pt.' );360 361 $query_args = array(362 'orderby' => array( 'post_title' => 'ASC' ),363 'order' => 'ASC',364 'post__not_in' => array(),365 'meta_key' => '',366 'meta_value' => '',367 'posts_per_page' => -1,368 'offset' => 0,369 'post_type' => 'wptests_pt',370 'post_status' => array( 'publish' ),371 'update_post_term_cache' => false,372 'update_post_meta_cache' => false,373 'ignore_sticky_posts' => true,374 'no_found_rows' => true,375 );376 377 $this->assertSameSets( $query_args, $query_args_values, 'Query arguments should match expected values' );378 379 $parsed_args = array(380 'child_of' => 0,381 'sort_order' => 'ASC',382 'sort_column' => 'post_title',383 'hierarchical' => 1,384 'exclude' => array(),385 'include' => array(),386 'meta_key' => '',387 'meta_value' => '',388 'authors' => '',389 'parent' => -1,390 'exclude_tree' => array(),391 'number' => '',392 'offset' => 0,393 'post_type' => 'page',394 'post_status' => 'publish',395 );396 397 $this->assertSameSets( $parsed_args, $parsed_args_values, 'Parsed arguments should match expected values' );398 }399 400 /**401 * @ticket 12821402 * @covers ::get_pages403 * @dataProvider data_get_pages_args404 */405 public function test_get_pages_args_test_filter( $args, $expected_query_args ) {406 $filter = new MockAction();407 add_filter( 'get_pages_query_args', array( $filter, 'filter' ), 10, 2 );408 409 $results = get_pages( $args );410 411 $this->assertIsArray( $results, 'get_pages should result an array' );412 413 $filter_args = $filter->get_args();414 415 $default_args = array(416 'orderby' => array( 'post_title' => 'ASC' ),417 'order' => 'ASC',418 'post__not_in' => array(),419 'meta_key' => '',420 'meta_value' => '',421 'posts_per_page' => -1,422 'offset' => 0,423 'post_type' => 'page',424 'post_status' => array( 'publish' ),425 'update_post_term_cache' => false,426 'update_post_meta_cache' => false,427 'ignore_sticky_posts' => true,428 'no_found_rows' => true,429 );430 431 $query_args = wp_parse_args( $expected_query_args, $default_args );432 433 $this->assertSameSets( $query_args, $filter_args[0][0], 'Unexpected $query_args for get_pages_query_args filter' );434 435 $defaults = array(436 'child_of' => 0,437 'sort_order' => 'ASC',438 'sort_column' => 'post_title',439 'hierarchical' => 1,440 'exclude' => array(),441 'include' => array(),442 'meta_key' => '',443 'meta_value' => '',444 'authors' => '',445 'parent' => -1,446 'exclude_tree' => array(),447 'number' => '',448 'offset' => 0,449 'post_type' => 'page',450 'post_status' => 'publish',451 );452 453 $parsed_args = wp_parse_args( $args, $defaults );454 $this->assertSameSets( $parsed_args, $filter_args[0][1], 'Unexpected $parsed_args for get_pages_query_args filter' );455 }456 457 public function data_get_pages_args() {458 return array(459 'default' => array(460 'args' => array(),461 'expected_query_args' => array(),462 ),463 'exclude' => array(464 'args' => array( 'exclude' => array( 1, 2, 4 ) ),465 'expected_query_args' => array( 'post__not_in' => array( 1, 2, 4 ) ),466 ),467 'post status' => array(468 'args' => array( 'post_status' => 'draft' ),469 'expected_query_args' => array( 'post_status' => array( 'draft' ) ),470 ),471 'number' => array(472 'args' => array( 'number' => 99 ),473 'expected_query_args' => array( 'posts_per_page' => 99 ),474 ),475 'meta query' => array(476 'args' => array(477 'meta_key' => 'foo',478 'meta_value' => 'bar',479 ),480 'expected_query_args' => array(481 'meta_key' => 'foo',482 'meta_value' => 'bar',483 ),484 ),485 'post parent number' => array(486 'args' => array( 'parent' => 5 ),487 'expected_query_args' => array( 'post_parent' => 5 ),488 ),489 'post parent array' => array(490 'args' => array( 'parent' => array( 5 ) ),491 'expected_query_args' => array( 'post_parent__in' => array( 5 ) ),492 ),493 'offset' => array(494 'args' => array( 'offset' => 2 ),495 'expected_query_args' => array( 'offset' => 2 ),496 ),497 'authors' => array(498 'args' => array( 'authors' => 2 ),499 'expected_query_args' => array( 'author__in' => array( 2 ) ),500 ),501 'sort order' => array(502 'args' => array( 'sort_order' => 'DESC' ),503 'expected_query_args' => array(504 'order' => 'DESC',505 'orderby' => array( 'post_title' => 'DESC' ),506 ),507 ),508 );509 }510 511 328 /** 512 329 * @ticket 12821 513 330 */ -
tests/phpunit/tests/query.php
diff --git tests/phpunit/tests/query.php tests/phpunit/tests/query.php index 52c6ebfc12..9c4ca439a5 100644
class Tests_Query extends WP_UnitTestCase { 897 897 $this->assertFalse( $q->is_tax() ); 898 898 $this->assertFalse( $q->is_tag( 'non-existent-tag' ) ); 899 899 } 900 901 /**902 * Test if $before_loop is true before loop.903 *904 * @ticket 58211905 */906 public function test_before_loop_value_set_true_before_the_loop() {907 // Get a new query with 3 posts.908 $query = $this->get_new_wp_query_with_posts( 3 );909 910 $this->assertTrue( $query->before_loop );911 }912 913 /**914 * Test $before_loop value is set to false when the loop starts.915 *916 * @ticket 58211917 *918 * @covers WP_Query::the_post919 */920 public function test_before_loop_value_set_to_false_in_loop_with_post() {921 // Get a new query with 2 posts.922 $query = $this->get_new_wp_query_with_posts( 2 );923 924 while ( $query->have_posts() ) {925 // $before_loop should be set false as soon as the_post is called for the first time.926 $query->the_post();927 928 $this->assertFalse( $query->before_loop );929 break;930 }931 }932 933 /**934 * Test $before_loop value is set to false when there is no post in the loop.935 *936 * @ticket 58211937 *938 * @covers WP_Query::have_posts939 */940 public function test_before_loop_set_false_after_loop_with_no_post() {941 // New query without any posts in the result.942 $query = new WP_Query(943 array(944 'category_name' => 'non-existent-category',945 )946 );947 948 // There will not be any posts, so the loop will never actually enter.949 while ( $query->have_posts() ) {950 $query->the_post();951 }952 953 // Still, this should be false as there are no results and entering the loop was attempted.954 $this->assertFalse( $query->before_loop );955 }956 957 /**958 * Get a new query with a given number of posts.959 *960 * @param int $no_of_posts Number of posts to be added in the query.961 */962 public function get_new_wp_query_with_posts( $no_of_posts ) {963 $post_ids = self::factory()->post->create_many( $no_of_posts );964 $query = new WP_Query( array( 'post__in' => $post_ids ) );965 return $query;966 }967 900 }