Make WordPress Core

Ticket #37966: 37966.unit-test.diff

File 37966.unit-test.diff, 2.4 KB (added by dd32, 8 years ago)
  • tests/phpunit/tests/comment/query.php

     
    55/**
    66 * @group comment
    77 */
    88class Tests_Comment_Query extends WP_UnitTestCase {
    99        protected static $post_id;
    1010        protected $comment_id;
    1111
    1212        public static function wpSetUpBeforeClass( $factory ) {
    1313                self::$post_id = $factory->post->create();
    1414        }
    1515
    1616        function setUp() {
    1717                parent::setUp();
    1818        }
    1919
     20        /**
     21         * @group 37966
     22         */
     23        public function test_children_present() {
     24                $c1 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1' ) );
     25                $c2 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_parent' => $c1 ) );
     26                $c3 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1' ) );
     27                $c4 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_parent' => $c3 ) );
     28
     29                $q = new WP_Comment_Query();
     30                $found = $q->query( array(
     31                        'orderby' => 'comment_date_gmt',
     32                        'order' => 'ASC',
     33                        'status' => 'approve',
     34                        'post_id' => self::$post_id,
     35                        'no_found_rows' => false,
     36                        'hierarchical' => 'threaded',
     37                        'number' => 1,
     38                        'offset' => 1,
     39                ) );
     40
     41                $this->assertNotEmpty( $found );
     42
     43                $comment = array_shift( $found );
     44
     45                $this->assertNotEmpty( $comment->get_children() );
     46
     47        }
     48
    2049        public function test_query() {
    2150                $c1 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1' ) );
    2251                $c2 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'pingback' ) );
    2352                $c3 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'trackback' ) );
    2453                $c4 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'mario' ) );
    2554                $c5 = self::factory()->comment->create( array( 'comment_post_ID' => self::$post_id, 'comment_approved' => '1', 'comment_type' => 'luigi' ) );
    2655
    2756                $q = new WP_Comment_Query();
    2857                $found = $q->query( array(
    2958                        'fields' => 'ids',
    3059                ) );
    3160
    3261                $this->assertEqualSets( array( $c1, $c2, $c3, $c4, $c5 ), $found );
    3362        }
    3463