WordPress.org

Make WordPress Core

Ticket #25523: post-status-perm-with-test.25523.diff

File post-status-perm-with-test.25523.diff, 1.3 KB (added by oso96_2000, 8 years ago)

Been a loong week. Ok, after trying for a while I think I've come with a simple test with almost no overhead that just tests this fix. The way the code is now it doesn't even return any post, after the fix, it returns the posts created in the setUp method. Hope it works.

  • src/wp-includes/query.php

    diff --git src/wp-includes/query.php src/wp-includes/query.php
    index 417405d..fd1ae2e 100644
    class WP_Query { 
    27562756                                foreach ( $statuswheres as $index => $statuswhere )
    27572757                                        $statuswheres[$index] = "($statuswhere OR ($wpdb->posts.post_status = 'inherit' AND " . str_replace($wpdb->posts, 'p2', $statuswhere) . "))";
    27582758                        }
    2759                         foreach ( $statuswheres as $statuswhere )
    2760                                 $where .= " AND $statuswhere";
     2759                        $where_status = implode(' OR ', $statuswheres);
     2760                        if(!empty($where_status))
     2761                                $where .= " AND ($where_status)";
    27612762                } elseif ( !$this->is_singular ) {
    27622763                        $where .= " AND ($wpdb->posts.post_status = 'publish'";
    27632764
  • tests/phpunit/tests/query/results.php

    diff --git tests/phpunit/tests/query/results.php tests/phpunit/tests/query/results.php
    index 404aea6..992d1b9 100644
    class Tests_Query_Results extends WP_UnitTestCase { 
    533533                $this->assertFalse( $this->q->is_month );
    534534                $this->assertFalse( $this->q->is_year );
    535535        }
     536
     537        /**
     538         * @ticket 25523
     539         */
     540        function test_query_post_readable_perm() {
     541                $posts = $this->q->query( array(
     542                        'post_status'   =>      array('publish', 'private'),
     543                        'perm'                  =>      'readable'
     544                ) );
     545
     546                $this->assertTrue($this->q->found_posts > 0);
     547        }
    536548}