Make WordPress Core


Ignore:
Timestamp:
02/06/2016 04:50:05 AM (11 years ago)
Author:
boonebgorges
Message:

Allow comments to be queried by 'any' post_type or post_status.

Props kouratoras.
Fixes #35512.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/comment/query.php

    r36480 r36486  
    17511751
    17521752        /**
     1753         * @ticket 35512
     1754         */
     1755        public function test_post_type_any_should_override_other_post_types() {
     1756                register_post_type( 'post-type-1', array( 'exclude_from_search' => false ) );
     1757                register_post_type( 'post-type-2', array( 'exclude_from_search' => false ) );
     1758
     1759                $p1 = self::factory()->post->create( array( 'post_type' => 'post-type-1' ) );
     1760                $p2 = self::factory()->post->create( array( 'post_type' => 'post-type-2' ) );
     1761
     1762                $c1 = self::factory()->comment->create_post_comments( $p1, 1 );
     1763                $c2 = self::factory()->comment->create_post_comments( $p2, 1 );
     1764
     1765                $q = new WP_Comment_Query();
     1766                $found = $q->query( array(
     1767                        'fields' => 'ids',
     1768                        'post_type' => array( 'any', 'post-type-1' ),
     1769                ) );
     1770                $this->assertEqualSets( array_merge( $c1, $c2 ), $found );
     1771        }
     1772
     1773        /**
     1774         * @ticket 35512
     1775         */
     1776        public function test_post_type_any_as_part_of_an_array_of_post_types() {
     1777                register_post_type( 'post-type-1', array( 'exclude_from_search' => false ) );
     1778                register_post_type( 'post-type-2', array( 'exclude_from_search' => false ) );
     1779
     1780                $p1 = self::factory()->post->create( array( 'post_type' => 'post-type-1' ) );
     1781                $p2 = self::factory()->post->create( array( 'post_type' => 'post-type-2' ) );
     1782
     1783                $c1 = self::factory()->comment->create_post_comments( $p1, 1 );
     1784                $c2 = self::factory()->comment->create_post_comments( $p2, 1 );
     1785
     1786                $q = new WP_Comment_Query();
     1787                $found = $q->query( array(
     1788                        'fields' => 'ids',
     1789                        'post_type' => array( 'any' ),
     1790                ) );
     1791                $this->assertEqualSets( array_merge( $c1, $c2 ), $found );
     1792        }
     1793
     1794        /**
     1795         * @ticket 35512
     1796         */
     1797        public function test_post_status_any_should_override_other_post_statuses() {
     1798                $p1 = self::factory()->post->create( array( 'post_status' => 'publish' ) );
     1799                $p2 = self::factory()->post->create( array( 'post_status' => 'draft' ) );
     1800
     1801                $c1 = self::factory()->comment->create_post_comments( $p1, 1 );
     1802                $c2 = self::factory()->comment->create_post_comments( $p2, 1 );
     1803
     1804                $q = new WP_Comment_Query();
     1805                $found = $q->query( array(
     1806                        'fields' => 'ids',
     1807                        'post_status' => array( 'any', 'draft' ),
     1808                ) );
     1809                $this->assertEqualSets( array_merge( $c1, $c2 ), $found );
     1810        }
     1811
     1812        /**
     1813         * @ticket 35512
     1814         */
     1815        public function test_post_status_any_as_part_of_an_array_of_post_statuses() {
     1816                $p1 = self::factory()->post->create( array( 'post_status' => 'publish' ) );
     1817                $p2 = self::factory()->post->create( array( 'post_status' => 'draft' ) );
     1818
     1819                $c1 = self::factory()->comment->create_post_comments( $p1, 1 );
     1820                $c2 = self::factory()->comment->create_post_comments( $p2, 1 );
     1821
     1822                $q = new WP_Comment_Query();
     1823                $found = $q->query( array(
     1824                        'fields' => 'ids',
     1825                        'post_status' => array( 'any' ),
     1826                ) );
     1827                $this->assertEqualSets( array_merge( $c1, $c2 ), $found );
     1828        }
     1829
     1830        /**
    17531831         * @ticket 24826
    17541832         */
Note: See TracChangeset for help on using the changeset viewer.