WordPress.org

Make WordPress Core

Ticket #33065: post_name__in_tests.patch

File post_name__in_tests.patch, 1.5 KB (added by enshrined, 6 years ago)

Tests for post_namein

  • tests/phpunit/tests/post/query.php

     
    302302                $this->assertNotContains( 'DESC', $q5->request );
    303303                $this->assertNotContains( 'ASC', $q5->request );
    304304        }
     305
     306
     307        /**
     308         * Tests the post_name__in attribute of WP_Query
     309         */
     310        function test_post_name__in() {
     311                $q = new WP_Query();
     312
     313                $post_ids[0] = $this->factory->post->create( array( 'post_title' => 'woo', 'post_date' => '2015-07-23 00:00:00' ) );
     314                $post_ids[1] = $this->factory->post->create( array( 'post_title' => 'hoo', 'post_date' => '2015-07-23 00:00:00' ) );
     315                $post_ids[2] = $this->factory->post->create( array( 'post_title' => 'test', 'post_date' => '2015-07-23 00:00:00' ) );
     316                $post_ids[3] = $this->factory->post->create( array( 'post_title' => 'me', 'post_date' => '2015-07-23 00:00:00' ) );
     317
     318                $requested = array( $post_ids[0], $post_ids[3] );
     319                $q->query( array( 'post_name__in' => array( 'woo', 'me' ) ) );
     320                $actual_posts = $q->get_posts();
     321                $this->assertCount( 2,  $actual_posts);
     322                $this->assertEqualSets( $requested, wp_list_pluck(  $actual_posts, 'ID' ) );
     323
     324                $requested = array( $post_ids[1], $post_ids[2] );
     325                $q->query( array( 'post_name__in' => array( 'hoo', 'test' ) ) );
     326                $actual_posts = $q->get_posts();
     327                $this->assertCount( 2,  $actual_posts);
     328                $this->assertEqualSets( $requested, wp_list_pluck(  $actual_posts, 'ID' ) );
     329        }
    305330}