WordPress.org

Make WordPress Core

Changeset 878 in tests


Ignore:
Timestamp:
07/03/12 19:14:58 (22 months ago)
Author:
nacin
Message:

We are now 100% ported to the new test runner. Port over test_query_results.php.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/phpunit.xml

    r875 r878  
    99            <directory suffix=".php">tests</directory> 
    1010            <file phpVersion="5.3.0">tests/test_actions_closures.php</file> 
    11             <exclude>tests/test_query_results.php</exclude> 
    1211        </testsuite> 
    1312    </testsuites> 
  • trunk/tests/test_query_results.php

    r828 r878  
    44// We're testing against a known data set, so we can check that specific posts are included in the output. 
    55 
    6 class TestWPQueryPosts extends _WPDataset1 { 
     6class TestWPQueryPosts extends WP_UnitTestCase { 
     7    protected $q; 
     8 
    79    function setUp() { 
    810        parent::setUp(); 
     11 
     12        $cat_a = $this->factory->term->create( array( 'taxonomy' => 'category', 'name' => 'cat-a' ) ); 
     13        $cat_b = $this->factory->term->create( array( 'taxonomy' => 'category', 'name' => 'cat-b' ) ); 
     14        $cat_c = $this->factory->term->create( array( 'taxonomy' => 'category', 'name' => 'cat-c' ) ); 
     15 
     16        $this->factory->post->create( array( 'post_title' => 'cats-a-b-c', 'post_date' => '2008-12-01 00:00:00', 'post_category' => array( $cat_a, $cat_b, $cat_c ) ) ); 
     17        $this->factory->post->create( array( 'post_title' => 'cats-a-and-b', 'post_date' => '2009-01-01 00:00:00', 'post_category' => array( $cat_a, $cat_b ) ) ); 
     18        $this->factory->post->create( array( 'post_title' => 'cats-b-and-c', 'post_date' => '2009-02-01 00:00:00', 'post_category' => array( $cat_b, $cat_c ) ) ); 
     19        $this->factory->post->create( array( 'post_title' => 'cats-a-and-c', 'post_date' => '2009-03-01 00:00:00', 'post_category' => array( $cat_a, $cat_c ) ) ); 
     20        $this->factory->post->create( array( 'post_title' => 'cat-a', 'post_date' => '2009-04-01 00:00:00', 'post_category' => array( $cat_a ) ) );      
     21        $this->factory->post->create( array( 'post_title' => 'cat-b', 'post_date' => '2009-05-01 00:00:00', 'post_category' => array( $cat_b ) ) ); 
     22        $this->factory->post->create( array( 'post_title' => 'cat-c', 'post_date' => '2009-06-01 00:00:00', 'post_category' => array( $cat_c ) ) ); 
     23        $this->factory->post->create( array( 'post_title' => 'lorem-ipsum', 'post_date' => '2009-07-01 00:00:00' ) ); 
     24        $this->factory->post->create( array( 'post_title' => 'comment-test', 'post_date' => '2009-08-01 00:00:00' ) ); 
     25        $this->factory->post->create( array( 'post_title' => 'one-trackback', 'post_date' => '2009-09-01 00:00:00' ) ); 
     26        $this->factory->post->create( array( 'post_title' => 'many-trackbacks', 'post_date' => '2009-10-01 00:00:00' ) ); 
     27        $this->factory->post->create( array( 'post_title' => 'no-comments', 'post_date' => '2009-10-01 00:00:00' ) ); 
     28        $this->factory->post->create( array( 'post_title' => 'one-comment', 'post_date' => '2009-11-01 00:00:00' ) ); 
     29        $this->factory->post->create( array( 'post_title' => 'contributor-post-approved', 'post_date' => '2009-12-01 00:00:00' ) ); 
     30        $this->factory->post->create( array( 'post_title' => 'embedded-video', 'post_date' => '2010-01-01 00:00:00' ) ); 
     31        $this->factory->post->create( array( 'post_title' => 'simple-markup-test', 'post_date' => '2010-02-01 00:00:00' ) ); 
     32        $this->factory->post->create( array( 'post_title' => 'raw-html-code', 'post_date' => '2010-03-01 00:00:00' ) ); 
     33        $this->factory->post->create( array( 'post_title' => 'tags-a-b-c', 'tags_input' => array( 'tag-a', 'tag-b', 'tag-c' ), 'post_date' => '2010-04-01 00:00:00' ) ); 
     34        $this->factory->post->create( array( 'post_title' => 'tag-a', 'tags_input' => array( 'tag-a' ), 'post_date' => '2010-05-01 00:00:00' ) ); 
     35        $this->factory->post->create( array( 'post_title' => 'tag-b', 'tags_input' => array( 'tag-b' ), 'post_date' => '2010-06-01 00:00:00' ) ); 
     36        $this->factory->post->create( array( 'post_title' => 'tag-c', 'tags_input' => array( 'tag-c' ), 'post_date' => '2010-07-01 00:00:00' ) ); 
     37        $this->factory->post->create( array( 'post_title' => 'tags-a-and-b', 'tags_input' => array( 'tag-a', 'tag-b' ), 'post_date' => '2010-08-01 00:00:00' ) ); 
     38        $this->factory->post->create( array( 'post_title' => 'tags-b-and-c', 'tags_input' => array( 'tag-b', 'tag-c' ), 'post_date' => '2010-09-01 00:00:00' ) ); 
     39        $this->factory->post->create( array( 'post_title' => 'tags-a-and-c', 'tags_input' => array( 'tag-a', 'tag-c' ), 'post_date' => '2010-10-01 00:00:00' ) ); 
     40 
     41        unset( $this->q ); 
    942        $this->q = new WP_Query(); 
    10     } 
    11  
    12     function tearDown() { 
    13         parent::tearDown(); 
    14         unset($this->q); 
    15     } 
    16  
    17     function post_slugs($posts) { 
    18         $out = array(); 
    19         foreach ($posts as $post) 
    20             $out[] = $post->post_name; 
    21         return $out; 
    2243    } 
    2344 
     
    2647 
    2748        // the output should be the most recent 10 posts as listed here 
    28         $expected = array ( 
     49        $expected = array( 
    2950            0 => 'tags-a-and-c', 
    3051            1 => 'tags-b-and-c', 
     
    3960        ); 
    4061 
    41         $this->assertEquals( $expected, $this->post_slugs($posts) ); 
     62        $this->assertEquals( $expected, wp_list_pluck( $posts, 'post_name' ) ); 
    4263    } 
    4364 
     
    4667 
    4768        // there are 4 posts with Tag A 
    48         $this->assertEquals( 4, count($posts) ); 
     69        $this->assertCount( 4, $posts ); 
    4970        $this->assertEquals( 'tags-a-and-c', $posts[0]->post_name ); 
    5071        $this->assertEquals( 'tags-a-and-b', $posts[1]->post_name ); 
     
    5778 
    5879        // there are 4 posts with Tag A 
    59         $this->assertEquals( 4, count($posts) ); 
     80        $this->assertCount( 4, $posts ); 
    6081        $this->assertEquals( 'tags-b-and-c', $posts[0]->post_name ); 
    6182        $this->assertEquals( 'tags-a-and-b', $posts[1]->post_name ); 
     
    6990 
    7091        // there are 4 posts with Tag A 
    71         $this->assertEquals( 4, count($posts) ); 
     92        $this->assertCount( 4, $posts ); 
    7293        $this->assertEquals( 'tags-a-and-c', $posts[0]->post_name ); 
    7394        $this->assertEquals( 'tags-a-and-b', $posts[1]->post_name ); 
     
    80101 
    81102        // there are 4 posts with either Tag B or Tag C 
    82         $this->assertEquals( 6, count($posts) ); 
     103        $this->assertCount( 6, $posts ); 
    83104        $this->assertEquals( 'tags-a-and-c', $posts[0]->post_name ); 
    84105        $this->assertEquals( 'tags-b-and-c', $posts[1]->post_name ); 
     
    96117 
    97118        // there are 6 posts with either Tag A or Tag B 
    98         $this->assertEquals( 6, count($posts) ); 
     119        $this->assertCount( 6, $posts ); 
    99120        $this->assertEquals( 'tags-a-and-c', $posts[0]->post_name ); 
    100121        $this->assertEquals( 'tags-b-and-c', $posts[1]->post_name ); 
     
    124145        ); 
    125146 
    126         $this->assertEquals( $expected, $this->post_slugs($posts) ); 
     147        $this->assertEquals( $expected, wp_list_pluck( $posts, 'post_name' ) ); 
    127148    } 
    128149 
     
    133154 
    134155        // there are 4 posts with Tag A, only 2 when we exclude Tag B 
    135         $this->assertEquals( 2, count($posts) ); 
     156        $this->assertCount( 2, $posts ); 
    136157        $this->assertEquals( 'tags-a-and-c', $posts[0]->post_name ); 
    137158        $this->assertEquals( 'tag-a', $posts[1]->post_name ); 
     
    144165 
    145166        // there are 4 posts with Cat A, we'll check for them by name 
    146         $this->assertEquals( 4, count($posts) ); 
     167        $this->assertCount( 4, $posts ); 
    147168        $this->assertEquals( 'cat-a', $posts[0]->post_name ); 
    148169        $this->assertEquals( 'cats-a-and-c', $posts[1]->post_name ); 
     
    156177 
    157178        // there are 4 posts with Cat B 
    158         $this->assertEquals( 4, count($posts) ); 
     179        $this->assertCount( 4, $posts ); 
    159180        $this->assertEquals( 'cat-b', $posts[0]->post_name ); 
    160181        $this->assertEquals( 'cats-b-and-c', $posts[1]->post_name ); 
     
    174195        ); 
    175196 
    176         $this->assertEquals( 5, count($posts) ); 
    177         $this->assertEquals( $expected, $this->post_slugs($posts) ); 
     197        $this->assertCount( 5, $posts ); 
     198        $this->assertEquals( $expected, wp_list_pluck( $posts, 'post_name' ) ); 
    178199    } 
    179200 
     
    194215        ); 
    195216 
    196         $this->assertEquals( 10, count($posts) ); 
    197         $this->assertEquals( $expected, $this->post_slugs($posts) ); 
     217        $this->assertCount( 10, $posts ); 
     218        $this->assertEquals( $expected, wp_list_pluck( $posts, 'post_name' ) ); 
    198219    } 
    199220 
     
    214235        ); 
    215236 
    216         $this->assertEquals( 10, count($posts) ); 
     237        $this->assertCount( 10, $posts ); 
    217238        $this->assertTrue( $this->q->is_paged() ); 
    218         $this->assertEquals( $expected, $this->post_slugs($posts) ); 
     239        $this->assertEquals( $expected, wp_list_pluck( $posts, 'post_name' ) ); 
    219240    } 
    220241 
     
    229250        ); 
    230251 
    231         $this->assertEquals( 4, count($posts) ); 
     252        $this->assertCount( 4, $posts ); 
    232253        $this->assertTrue( $this->q->is_paged() ); 
    233         $this->assertEquals( $expected, $this->post_slugs($posts) ); 
     254        $this->assertEquals( $expected, wp_list_pluck( $posts, 'post_name' ) ); 
    234255    } 
    235256 
     
    252273        ); 
    253274 
    254         $this->assertEquals( 10, count($posts) ); 
     275        $this->assertCount( 10, $posts ); 
    255276        $this->assertTrue( $this->q->is_paged() ); 
    256         $this->assertEquals( $expected, $this->post_slugs($posts) ); 
     277        $this->assertEquals( $expected, wp_list_pluck( $posts, 'post_name' ) ); 
    257278    } 
    258279 
Note: See TracChangeset for help on using the changeset viewer.