Changeset 42597 for branches/4.9
- Timestamp:
- 01/24/2018 09:43:17 PM (7 years ago)
- Location:
- branches/4.9
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/4.9
- Property svn:mergeinfo changed
/trunk merged: 42581,42585,42594
- Property svn:mergeinfo changed
-
branches/4.9/src/wp-includes/class-wp-query.php
r41688 r42597 3033 3033 $this->found_posts = $wpdb->get_var( apply_filters_ref_array( 'found_posts_query', array( 'SELECT FOUND_ROWS()', &$this ) ) ); 3034 3034 } else { 3035 $this->found_posts = count( $this->posts ); 3035 if ( is_array( $this->posts ) ) { 3036 $this->found_posts = count( $this->posts ); 3037 } else { 3038 if ( null === $this->posts ) { 3039 $this->found_posts = 0; 3040 } else { 3041 $this->found_posts = 1; 3042 } 3043 } 3036 3044 } 3037 3045 -
branches/4.9/tests/phpunit/tests/post/query.php
r40278 r42597 536 536 $this->assertEquals( 2, $q->max_num_pages ); 537 537 } 538 539 public function set_found_posts_provider() { 540 // count return 0 for null, but 1 for other data you may not expect 541 return array( 542 array( null, 0 ), 543 array( '', 1 ), 544 array( "To life, to life, l'chaim", 1 ), 545 array( false, 1 ), 546 ); 547 } 548 549 /** 550 * @ticket 42860 551 * 552 * @dataProvider set_found_posts_provider 553 */ 554 public function test_set_found_posts_not_posts_as_an_array( $posts, $expected ) { 555 if ( version_compare( PHP_VERSION, '5.3', '<' ) ) { 556 $this->markTestSkipped( 'ReflectionMethod::setAccessible is only available in PHP 5.3+' ); 557 return; 558 } 559 560 $q = new WP_Query( 561 array( 562 'post_type' => 'wptests_pt', 563 'posts_per_page' => 1, 564 ) 565 ); 566 567 $q->posts = $posts; 568 569 $methd = new \ReflectionMethod( 'WP_Query', 'set_found_posts' ); 570 $methd->setAccessible( true ); 571 $methd->invoke( $q, array( 'no_found_rows' => false ), array() ); 572 573 $this->assertEquals( $expected, $q->found_posts ); 574 } 575 538 576 }
Note: See TracChangeset
for help on using the changeset viewer.