Changeset 55847 for trunk/tests/phpunit/tests/query.php
- Timestamp:
- 05/22/2023 07:11:36 PM (17 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/query.php
r54891 r55847 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 58211 905 */ 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 58211 917 * 918 * @covers WP_Query::the_post 919 */ 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 58211 937 * 938 * @covers WP_Query::have_posts 939 */ 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 } 900 967 }
Note: See TracChangeset
for help on using the changeset viewer.