WordPress.org

Make WordPress Core

Changeset 35162


Ignore:
Timestamp:
10/14/2015 09:23:03 PM (5 years ago)
Author:
boonebgorges
Message:

Create fewer fixtures in some tests.

See #30017, #33968.

Location:
trunk/tests/phpunit/tests
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/category.php

    r33681 r35162  
    2222    function test_get_all_category_ids() {
    2323        // create categories
    24         $this->factory->category->create_many(15);
     24        $this->factory->category->create_many( 2 );
    2525
    2626        // create new taxonomy to ensure not included
    2727        register_taxonomy( 'test_tax_cat', 'post' );
    2828        wp_insert_term( "test1", 'test_tax_cat' );
    29         wp_insert_term( "test2", 'test_tax_cat' );
    30         wp_insert_term( "test3", 'test_tax_cat' );
    3129
    3230        // Validate length is 1 + created due to uncategorized
    3331        $cat_ids = get_all_category_ids();
    34         $this->assertEquals( 16, count($cat_ids));
     32        $this->assertEquals( 3, count($cat_ids));
    3533    }
    3634
  • trunk/tests/phpunit/tests/customize/nav-menus.php

    r34857 r35162  
    125125
    126126        // Create pages.
    127         $this->factory->post->create_many( 15, array( 'post_type' => 'page' ) );
     127        $this->factory->post->create_many( 12, array( 'post_type' => 'page' ) );
    128128
    129129        // Home is included in menu items when page is zero.
  • trunk/tests/phpunit/tests/feed/rss2.php

    r34802 r35162  
    1717
    1818        self::$user = $factory->user->create();
    19         self::$posts = $factory->post->create_many( 25, array(
     19        self::$posts = $factory->post->create_many( 5, array(
    2020            'post_author' => self::$user,
    2121        ) );
  • trunk/tests/phpunit/tests/general/archives.php

    r34828 r35162  
    1717        global $wpdb;
    1818
    19         $this->factory->post->create_many( 15, array( 'post_type' => 'post' ) );
     19        $this->factory->post->create_many( 3, array( 'post_type' => 'post' ) );
    2020        wp_cache_delete( 'last_changed', 'posts' );
    2121        $this->assertFalse( wp_cache_get( 'last_changed', 'posts' ) );
  • trunk/tests/phpunit/tests/post.php

    r34810 r35162  
    805805        $post_type = rand_str(20);
    806806        register_post_type( $post_type );
    807         $this->factory->post->create_many( 10, array(
     807        $this->factory->post->create_many( 3, array(
    808808            'post_type' => $post_type,
    809809            'post_author' => $this->author_id
    810810        ) );
    811811        $count1 = wp_count_posts( $post_type, 'readable' );
    812         $this->assertEquals( 10, $count1->publish );
     812        $this->assertEquals( 3, $count1->publish );
    813813        add_filter( 'wp_count_posts', array( $this, 'filter_wp_count_posts' ) );
    814814
    815815        $count2 = wp_count_posts( $post_type, 'readable' );
    816         $this->assertEquals( 7, $count2->publish );
     816        $this->assertEquals( 2, $count2->publish );
    817817
    818818        remove_filter( 'wp_count_posts', array( $this, 'filter_wp_count_posts' ) );
     
    820820
    821821    function filter_wp_count_posts( $counts ) {
    822         $counts->publish = 7;
     822        $counts->publish = 2;
    823823        return $counts;
    824824    }
    825825
    826826    function test_wp_count_posts_insert_invalidation() {
    827         $post_ids = $this->factory->post->create_many( 10 );
     827        $post_ids = $this->factory->post->create_many( 3 );
    828828        $initial_counts = wp_count_posts();
    829829
     
    838838        $after_draft_counts = wp_count_posts();
    839839        $this->assertEquals( 1, $after_draft_counts->draft );
    840         $this->assertEquals( 9, $after_draft_counts->publish );
     840        $this->assertEquals( 2, $after_draft_counts->publish );
    841841        $this->assertNotEquals( $initial_counts->publish, $after_draft_counts->publish );
    842842    }
    843843
    844844    function test_wp_count_posts_trash_invalidation() {
    845         $post_ids = $this->factory->post->create_many( 10 );
     845        $post_ids = $this->factory->post->create_many( 3 );
    846846        $initial_counts = wp_count_posts();
    847847
     
    856856        $after_trash_counts = wp_count_posts();
    857857        $this->assertEquals( 1, $after_trash_counts->trash );
    858         $this->assertEquals( 9, $after_trash_counts->publish );
     858        $this->assertEquals( 2, $after_trash_counts->publish );
    859859        $this->assertNotEquals( $initial_counts->publish, $after_trash_counts->publish );
    860860    }
  • trunk/tests/phpunit/tests/post/getPages.php

    r34699 r35162  
    1616        global $wpdb;
    1717
    18         $this->factory->post->create_many( 15, array( 'post_type' => 'page' ) );
     18        $this->factory->post->create_many( 3, array( 'post_type' => 'page' ) );
    1919        wp_cache_delete( 'last_changed', 'posts' );
    2020        $this->assertFalse( wp_cache_get( 'last_changed', 'posts' ) );
    2121
    2222        $pages = get_pages();
    23         $this->assertEquals( 15, count( $pages ) );
     23        $this->assertEquals( 3, count( $pages ) );
    2424        $this->assertNotEmpty( $time1 = wp_cache_get( 'last_changed', 'posts' ) );
    2525        $num_queries = $wpdb->num_queries;
     
    2929        // Again. num_queries and last_changed should remain the same.
    3030        $pages = get_pages();
    31         $this->assertEquals( 15, count( $pages ) );
     31        $this->assertEquals( 3, count( $pages ) );
    3232        $this->assertEquals( $time1, wp_cache_get( 'last_changed', 'posts' ) );
    3333        $this->assertEquals( $num_queries, $wpdb->num_queries );
     
    3737        // Again with different args. last_changed should not increment because of
    3838        // different args to get_pages(). num_queries should bump by 1.
    39         $pages = get_pages( array( 'number' => 10 ) );
    40         $this->assertEquals( 10, count( $pages ) );
     39        $pages = get_pages( array( 'number' => 2 ) );
     40        $this->assertEquals( 2, count( $pages ) );
    4141        $this->assertEquals( $time1, wp_cache_get( 'last_changed', 'posts' ) );
    4242        $this->assertEquals( $num_queries + 1, $wpdb->num_queries );
     
    4747
    4848        // Again. num_queries and last_changed should remain the same.
    49         $pages = get_pages( array( 'number' => 10 ) );
    50         $this->assertEquals( 10, count( $pages ) );
     49        $pages = get_pages( array( 'number' => 2 ) );
     50        $this->assertEquals( 2, count( $pages ) );
    5151        $this->assertEquals( $time1, wp_cache_get( 'last_changed', 'posts' ) );
    5252        $this->assertEquals( $num_queries, $wpdb->num_queries );
     
    5656        // Do the first query again. The interim queries should not affect it.
    5757        $pages = get_pages();
    58         $this->assertEquals( 15, count( $pages ) );
     58        $this->assertEquals( 3, count( $pages ) );
    5959        $this->assertEquals( $time1, wp_cache_get( 'last_changed', 'posts' ) );
    6060        $this->assertEquals( $num_queries, $wpdb->num_queries );
     
    6969
    7070        // last_changed bumped so num_queries should increment.
    71         $pages = get_pages( array( 'number' => 10 ) );
    72         $this->assertEquals( 10, count( $pages ) );
     71        $pages = get_pages( array( 'number' => 2 ) );
     72        $this->assertEquals( 2, count( $pages ) );
    7373        $this->assertEquals( $time2, wp_cache_get( 'last_changed', 'posts' ) );
    7474        $this->assertEquals( $num_queries + 1, $wpdb->num_queries );
     
    8989        // num_queries should bump after wp_delete_post() bumps last_changed.
    9090        $pages = get_pages();
    91         $this->assertEquals( 14, count( $pages ) );
     91        $this->assertEquals( 2, count( $pages ) );
    9292        $this->assertEquals( $last_changed, wp_cache_get( 'last_changed', 'posts' ) );
    9393        $this->assertEquals( $num_queries + 1, $wpdb->num_queries );
  • trunk/tests/phpunit/tests/post/query.php

    r33653 r35162  
    7272    function test_the_posts_filter() {
    7373        // Create posts and clear their caches.
    74         $post_ids = $this->factory->post->create_many( 10 );
     74        $post_ids = $this->factory->post->create_many( 4 );
    7575        foreach ( $post_ids as $post_id )
    7676            clean_post_cache( $post_id );
     
    8080        $query = new WP_Query( array(
    8181            'post_type' => 'post',
    82             'posts_per_page' => 5,
    83         ) );
    84 
    85         // Sixth post added in filter
    86         $this->assertEquals( 6, count( $query->posts ) );
    87         $this->assertEquals( 6, $query->post_count );
     82            'posts_per_page' => 3,
     83        ) );
     84
     85        // Fourth post added in filter
     86        $this->assertEquals( 4, count( $query->posts ) );
     87        $this->assertEquals( 4, $query->post_count );
    8888
    8989        foreach ( $query->posts as $post ) {
  • trunk/tests/phpunit/tests/query/conditionals.php

    r34810 r35162  
    252252    // 'page/?([0-9]{1,})/?$' => 'index.php?&paged=$matches[1]',
    253253    function test_paged() {
    254         $this->factory->post->create_many( 15 );
     254        update_option( 'posts_per_page', 2 );
     255        $this->factory->post->create_many( 5 );
    255256        for ( $i = 2; $i <= 3; $i++ ) {
    256257            $this->go_to("/page/{$i}/");
     
    305306    // 'search/(.+)/page/?([0-9]{1,})/?$' => 'index.php?s=$matches[1]&paged=$matches[2]',
    306307    function test_search_paged() {
    307         $this->factory->post->create_many( 10, array( 'post_title' => 'test' ) );
     308        update_option( 'posts_per_page', 2 );
     309        $this->factory->post->create_many( 3, array( 'post_title' => 'test' ) );
    308310        $this->go_to('/search/test/page/2/');
    309311        $this->assertQueryTrue('is_search', 'is_paged');
     
    345347    // 'category/(.+?)/page/?([0-9]{1,})/?$' => 'index.php?category_name=$matches[1]&paged=$matches[2]',
    346348    function test_category_paged() {
    347         $this->factory->post->create_many( 10 );
     349        update_option( 'posts_per_page', 2 );
     350        $this->factory->post->create_many( 3 );
    348351        $this->go_to('/category/uncategorized/page/2/');
    349352        $this->assertQueryTrue('is_archive', 'is_category', 'is_paged');
     
    378381    // 'tag/(.+?)/page/?([0-9]{1,})/?$' => 'index.php?tag=$matches[1]&paged=$matches[2]',
    379382    function test_tag_paged() {
    380         $post_ids = $this->factory->post->create_many( 10 );
     383        update_option( 'posts_per_page', 2 );
     384        $post_ids = $this->factory->post->create_many( 3 );
    381385        foreach ( $post_ids as $post_id )
    382386            $this->factory->term->add_post_terms( $post_id, 'tag-a', 'post_tag' );
     
    424428    // 'author/([^/]+)/page/?([0-9]{1,})/?$' => 'index.php?author_name=$matches[1]&paged=$matches[2]',
    425429    function test_author_paged() {
     430        update_option( 'posts_per_page', 2 );
    426431        $user_id = $this->factory->user->create( array( 'user_login' => 'user-a' ) );
    427         $this->factory->post->create_many( 10, array( 'post_author' => $user_id ) );
     432        $this->factory->post->create_many( 3, array( 'post_author' => $user_id ) );
    428433        $this->go_to('/author/user-a/page/2/');
    429434        $this->assertQueryTrue('is_archive', 'is_author', 'is_paged');
     
    465470    // '([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/page/?([0-9]{1,})/?$' => 'index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&paged=$matches[4]',
    466471    function test_ymd_paged() {
    467         $this->factory->post->create_many( 10, array( 'post_date' => '2007-09-04 00:00:00' ) );
     472        update_option( 'posts_per_page', 2 );
     473        $this->factory->post->create_many( 3, array( 'post_date' => '2007-09-04 00:00:00' ) );
    468474        $this->go_to('/2007/09/04/page/2/');
    469475        $this->assertQueryTrue('is_archive', 'is_day', 'is_date', 'is_paged');
     
    498504    // '([0-9]{4})/([0-9]{1,2})/page/?([0-9]{1,})/?$' => 'index.php?year=$matches[1]&monthnum=$matches[2]&paged=$matches[3]',
    499505    function test_ym_paged() {
    500         $this->factory->post->create_many( 10, array( 'post_date' => '2007-09-04 00:00:00' ) );
     506        update_option( 'posts_per_page', 2 );
     507        $this->factory->post->create_many( 3, array( 'post_date' => '2007-09-04 00:00:00' ) );
    501508        $this->go_to('/2007/09/page/2/');
    502509        $this->assertQueryTrue('is_archive', 'is_date', 'is_month', 'is_paged');
     
    531538    // '([0-9]{4})/page/?([0-9]{1,})/?$' => 'index.php?year=$matches[1]&paged=$matches[2]',
    532539    function test_y_paged() {
    533         $this->factory->post->create_many( 10, array( 'post_date' => '2007-09-04 00:00:00' ) );
     540        update_option( 'posts_per_page', 2 );
     541        $this->factory->post->create_many( 3, array( 'post_date' => '2007-09-04 00:00:00' ) );
    534542        $this->go_to('/2007/page/2/');
    535543        $this->assertQueryTrue('is_archive', 'is_date', 'is_year', 'is_paged');
  • trunk/tests/phpunit/tests/query/taxQuery.php

    r31346 r35162  
    841841        // An empty tax query should return an empty array, not all posts.
    842842
    843         $this->factory->post->create_many( 10 );
     843        $this->factory->post->create_many( 2 );
    844844
    845845        $query = new WP_Query( array(
     
    874874        // An empty tax query should return an empty array, not all posts.
    875875
    876         $this->factory->post->create_many( 10 );
     876        $this->factory->post->create_many( 2 );
    877877
    878878        $query = new WP_Query( array(
Note: See TracChangeset for help on using the changeset viewer.