Make WordPress Core


Ignore:
Timestamp:
09/15/2015 04:22:34 PM (9 years ago)
Author:
wonderboymusic
Message:

Add parent__in and parent__not_in query vars to WP_Comment_Query.

Adds unit tests.

Fixes #33882.

File:
1 edited

Legend:

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

    r32911 r34205  
    17381738        $q->query_vars['meta_value'] = 'bar';
    17391739    }
     1740
     1741    /**
     1742     * @ticket 33882
     1743     */
     1744    public function test_parent__in() {
     1745        $c1 = $this->factory->comment->create( array( 'comment_post_ID' => $this->post_id, 'comment_approved' => '1' ) );
     1746        $c2 = $this->factory->comment->create( array(
     1747            'comment_post_ID' => $this->post_id,
     1748            'comment_approved' => '1',
     1749            'comment_parent' => $c1,
     1750        ) );
     1751
     1752        $ids = new WP_Comment_Query( array(
     1753            'comment_post_ID' => $this->post_id,
     1754            'fields' => 'ids',
     1755            'parent__in' => array( $c1 )
     1756        ) );
     1757
     1758        $this->assertEqualSets( array( $c2 ), $ids->comments );
     1759    }
     1760
     1761    /**
     1762     * @ticket 33882
     1763     */
     1764    public function test_parent__in_commas() {
     1765        $c1 = $this->factory->comment->create( array( 'comment_post_ID' => $this->post_id, 'comment_approved' => '1' ) );
     1766        $c2 = $this->factory->comment->create( array(
     1767            'comment_post_ID' => $this->post_id,
     1768            'comment_approved' => '1'
     1769        ) );
     1770        $c3 = $this->factory->comment->create( array(
     1771            'comment_post_ID' => $this->post_id,
     1772            'comment_approved' => '1',
     1773            'comment_parent' => $c1,
     1774        ) );
     1775        $c4 = $this->factory->comment->create( array(
     1776            'comment_post_ID' => $this->post_id,
     1777            'comment_approved' => '1',
     1778            'comment_parent' => $c2,
     1779        ) );
     1780
     1781        $ids = new WP_Comment_Query( array(
     1782            'comment_post_ID' => $this->post_id,
     1783            'fields' => 'ids',
     1784            'parent__in' => "$c1,$c2"
     1785        ) );
     1786
     1787        $this->assertEqualSets( array( $c3, $c4 ), $ids->comments );
     1788    }
     1789
     1790    /**
     1791     * @ticket 33882
     1792     */
     1793    public function test_parent__not_in() {
     1794        $c1 = $this->factory->comment->create( array( 'comment_post_ID' => $this->post_id, 'comment_approved' => '1' ) );
     1795
     1796        $this->factory->comment->create( array(
     1797            'comment_post_ID' => $this->post_id,
     1798            'comment_approved' => '1',
     1799            'comment_parent' => $c1,
     1800        ) );
     1801
     1802        $ids = new WP_Comment_Query( array(
     1803            'comment_post_ID' => $this->post_id,
     1804            'fields' => 'ids',
     1805            'parent__not_in' => array( $c1 )
     1806        ) );
     1807
     1808        $this->assertEqualSets( array( $c1 ), $ids->comments );
     1809    }
     1810
     1811    /**
     1812     * @ticket 33882
     1813     */
     1814    public function test_parent__not_in_commas() {
     1815        $c1 = $this->factory->comment->create( array( 'comment_post_ID' => $this->post_id, 'comment_approved' => '1' ) );
     1816        $c2 = $this->factory->comment->create( array(
     1817            'comment_post_ID' => $this->post_id,
     1818            'comment_approved' => '1'
     1819        ) );
     1820
     1821        $this->factory->comment->create( array(
     1822            'comment_post_ID' => $this->post_id,
     1823            'comment_approved' => '1',
     1824            'comment_parent' => $c1,
     1825        ) );
     1826        $this->factory->comment->create( array(
     1827            'comment_post_ID' => $this->post_id,
     1828            'comment_approved' => '1',
     1829            'comment_parent' => $c2,
     1830        ) );
     1831
     1832        $ids = new WP_Comment_Query( array(
     1833            'comment_post_ID' => $this->post_id,
     1834            'fields' => 'ids',
     1835            'parent__not_in' => "$c1,$c2"
     1836        ) );
     1837
     1838        $this->assertEqualSets( array( $c1, $c2 ), $ids->comments );
     1839    }
    17401840}
Note: See TracChangeset for help on using the changeset viewer.