From 6c28fe3853f57d7e185d6b3731d6391411abc62c Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Wed, 14 Oct 2015 21:23:03 +0000 Subject: [PATCH] Create fewer fixtures in some tests. See #30017, #33968. git-svn-id: https://develop.svn.wordpress.org/trunk@35162 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/category.php | 6 ++---- tests/phpunit/tests/customize/nav-menus.php | 2 +- tests/phpunit/tests/feed/rss2.php | 2 +- tests/phpunit/tests/general/archives.php | 2 +- tests/phpunit/tests/post.php | 16 +++++++------- tests/phpunit/tests/post/getPages.php | 22 +++++++++---------- tests/phpunit/tests/post/query.php | 10 ++++----- tests/phpunit/tests/query/conditionals.php | 24 ++++++++++++++------- tests/phpunit/tests/query/taxQuery.php | 4 ++-- 9 files changed, 47 insertions(+), 41 deletions(-) diff --git a/tests/phpunit/tests/category.php b/tests/phpunit/tests/category.php index 470f0e4f9f..85cdf0aadf 100644 --- a/tests/phpunit/tests/category.php +++ b/tests/phpunit/tests/category.php @@ -21,17 +21,15 @@ class Tests_Category extends WP_UnitTestCase { */ function test_get_all_category_ids() { // create categories - $this->factory->category->create_many(15); + $this->factory->category->create_many( 2 ); // create new taxonomy to ensure not included register_taxonomy( 'test_tax_cat', 'post' ); wp_insert_term( "test1", 'test_tax_cat' ); - wp_insert_term( "test2", 'test_tax_cat' ); - wp_insert_term( "test3", 'test_tax_cat' ); // Validate length is 1 + created due to uncategorized $cat_ids = get_all_category_ids(); - $this->assertEquals( 16, count($cat_ids)); + $this->assertEquals( 3, count($cat_ids)); } /** diff --git a/tests/phpunit/tests/customize/nav-menus.php b/tests/phpunit/tests/customize/nav-menus.php index 3649b88b6f..7e85c76d15 100644 --- a/tests/phpunit/tests/customize/nav-menus.php +++ b/tests/phpunit/tests/customize/nav-menus.php @@ -124,7 +124,7 @@ class Test_WP_Customize_Nav_Menus extends WP_UnitTestCase { ); // Create pages. - $this->factory->post->create_many( 15, array( 'post_type' => 'page' ) ); + $this->factory->post->create_many( 12, array( 'post_type' => 'page' ) ); // Home is included in menu items when page is zero. $items = $menus->load_available_items_query( 'post_type', 'page', 0 ); diff --git a/tests/phpunit/tests/feed/rss2.php b/tests/phpunit/tests/feed/rss2.php index 37ace0ff50..930c160da9 100644 --- a/tests/phpunit/tests/feed/rss2.php +++ b/tests/phpunit/tests/feed/rss2.php @@ -16,7 +16,7 @@ class Tests_Feed_RSS2 extends WP_UnitTestCase { $factory = new WP_UnitTest_Factory(); self::$user = $factory->user->create(); - self::$posts = $factory->post->create_many( 25, array( + self::$posts = $factory->post->create_many( 5, array( 'post_author' => self::$user, ) ); diff --git a/tests/phpunit/tests/general/archives.php b/tests/phpunit/tests/general/archives.php index b70b5e3e3e..0c5642ac6a 100644 --- a/tests/phpunit/tests/general/archives.php +++ b/tests/phpunit/tests/general/archives.php @@ -16,7 +16,7 @@ class Tests_General_Archives extends WP_UnitTestCase { function test_get_archives_cache() { global $wpdb; - $this->factory->post->create_many( 15, array( 'post_type' => 'post' ) ); + $this->factory->post->create_many( 3, array( 'post_type' => 'post' ) ); wp_cache_delete( 'last_changed', 'posts' ); $this->assertFalse( wp_cache_get( 'last_changed', 'posts' ) ); diff --git a/tests/phpunit/tests/post.php b/tests/phpunit/tests/post.php index 98fea84ec5..313aa4355b 100644 --- a/tests/phpunit/tests/post.php +++ b/tests/phpunit/tests/post.php @@ -804,27 +804,27 @@ class Tests_Post extends WP_UnitTestCase { function test_wp_count_posts_filtered() { $post_type = rand_str(20); register_post_type( $post_type ); - $this->factory->post->create_many( 10, array( + $this->factory->post->create_many( 3, array( 'post_type' => $post_type, 'post_author' => $this->author_id ) ); $count1 = wp_count_posts( $post_type, 'readable' ); - $this->assertEquals( 10, $count1->publish ); + $this->assertEquals( 3, $count1->publish ); add_filter( 'wp_count_posts', array( $this, 'filter_wp_count_posts' ) ); $count2 = wp_count_posts( $post_type, 'readable' ); - $this->assertEquals( 7, $count2->publish ); + $this->assertEquals( 2, $count2->publish ); remove_filter( 'wp_count_posts', array( $this, 'filter_wp_count_posts' ) ); } function filter_wp_count_posts( $counts ) { - $counts->publish = 7; + $counts->publish = 2; return $counts; } function test_wp_count_posts_insert_invalidation() { - $post_ids = $this->factory->post->create_many( 10 ); + $post_ids = $this->factory->post->create_many( 3 ); $initial_counts = wp_count_posts(); $key = array_rand( $post_ids ); @@ -837,12 +837,12 @@ class Tests_Post extends WP_UnitTestCase { $after_draft_counts = wp_count_posts(); $this->assertEquals( 1, $after_draft_counts->draft ); - $this->assertEquals( 9, $after_draft_counts->publish ); + $this->assertEquals( 2, $after_draft_counts->publish ); $this->assertNotEquals( $initial_counts->publish, $after_draft_counts->publish ); } function test_wp_count_posts_trash_invalidation() { - $post_ids = $this->factory->post->create_many( 10 ); + $post_ids = $this->factory->post->create_many( 3 ); $initial_counts = wp_count_posts(); $key = array_rand( $post_ids ); @@ -855,7 +855,7 @@ class Tests_Post extends WP_UnitTestCase { $after_trash_counts = wp_count_posts(); $this->assertEquals( 1, $after_trash_counts->trash ); - $this->assertEquals( 9, $after_trash_counts->publish ); + $this->assertEquals( 2, $after_trash_counts->publish ); $this->assertNotEquals( $initial_counts->publish, $after_trash_counts->publish ); } diff --git a/tests/phpunit/tests/post/getPages.php b/tests/phpunit/tests/post/getPages.php index b1f676e497..d6932812b4 100644 --- a/tests/phpunit/tests/post/getPages.php +++ b/tests/phpunit/tests/post/getPages.php @@ -15,12 +15,12 @@ class Tests_Post_getPages extends WP_UnitTestCase { function test_get_pages_cache() { global $wpdb; - $this->factory->post->create_many( 15, array( 'post_type' => 'page' ) ); + $this->factory->post->create_many( 3, array( 'post_type' => 'page' ) ); wp_cache_delete( 'last_changed', 'posts' ); $this->assertFalse( wp_cache_get( 'last_changed', 'posts' ) ); $pages = get_pages(); - $this->assertEquals( 15, count( $pages ) ); + $this->assertEquals( 3, count( $pages ) ); $this->assertNotEmpty( $time1 = wp_cache_get( 'last_changed', 'posts' ) ); $num_queries = $wpdb->num_queries; foreach ( $pages as $page ) @@ -28,7 +28,7 @@ class Tests_Post_getPages extends WP_UnitTestCase { // Again. num_queries and last_changed should remain the same. $pages = get_pages(); - $this->assertEquals( 15, count( $pages ) ); + $this->assertEquals( 3, count( $pages ) ); $this->assertEquals( $time1, wp_cache_get( 'last_changed', 'posts' ) ); $this->assertEquals( $num_queries, $wpdb->num_queries ); foreach ( $pages as $page ) @@ -36,8 +36,8 @@ class Tests_Post_getPages extends WP_UnitTestCase { // Again with different args. last_changed should not increment because of // different args to get_pages(). num_queries should bump by 1. - $pages = get_pages( array( 'number' => 10 ) ); - $this->assertEquals( 10, count( $pages ) ); + $pages = get_pages( array( 'number' => 2 ) ); + $this->assertEquals( 2, count( $pages ) ); $this->assertEquals( $time1, wp_cache_get( 'last_changed', 'posts' ) ); $this->assertEquals( $num_queries + 1, $wpdb->num_queries ); foreach ( $pages as $page ) @@ -46,8 +46,8 @@ class Tests_Post_getPages extends WP_UnitTestCase { $num_queries = $wpdb->num_queries; // Again. num_queries and last_changed should remain the same. - $pages = get_pages( array( 'number' => 10 ) ); - $this->assertEquals( 10, count( $pages ) ); + $pages = get_pages( array( 'number' => 2 ) ); + $this->assertEquals( 2, count( $pages ) ); $this->assertEquals( $time1, wp_cache_get( 'last_changed', 'posts' ) ); $this->assertEquals( $num_queries, $wpdb->num_queries ); foreach ( $pages as $page ) @@ -55,7 +55,7 @@ class Tests_Post_getPages extends WP_UnitTestCase { // Do the first query again. The interim queries should not affect it. $pages = get_pages(); - $this->assertEquals( 15, count( $pages ) ); + $this->assertEquals( 3, count( $pages ) ); $this->assertEquals( $time1, wp_cache_get( 'last_changed', 'posts' ) ); $this->assertEquals( $num_queries, $wpdb->num_queries ); foreach ( $pages as $page ) @@ -68,8 +68,8 @@ class Tests_Post_getPages extends WP_UnitTestCase { $num_queries = $wpdb->num_queries; // last_changed bumped so num_queries should increment. - $pages = get_pages( array( 'number' => 10 ) ); - $this->assertEquals( 10, count( $pages ) ); + $pages = get_pages( array( 'number' => 2 ) ); + $this->assertEquals( 2, count( $pages ) ); $this->assertEquals( $time2, wp_cache_get( 'last_changed', 'posts' ) ); $this->assertEquals( $num_queries + 1, $wpdb->num_queries ); foreach ( $pages as $page ) @@ -88,7 +88,7 @@ class Tests_Post_getPages extends WP_UnitTestCase { // num_queries should bump after wp_delete_post() bumps last_changed. $pages = get_pages(); - $this->assertEquals( 14, count( $pages ) ); + $this->assertEquals( 2, count( $pages ) ); $this->assertEquals( $last_changed, wp_cache_get( 'last_changed', 'posts' ) ); $this->assertEquals( $num_queries + 1, $wpdb->num_queries ); foreach ( $pages as $page ) diff --git a/tests/phpunit/tests/post/query.php b/tests/phpunit/tests/post/query.php index cc70caf749..904ab9f3cf 100644 --- a/tests/phpunit/tests/post/query.php +++ b/tests/phpunit/tests/post/query.php @@ -71,7 +71,7 @@ class Tests_Post_Query extends WP_UnitTestCase { */ function test_the_posts_filter() { // Create posts and clear their caches. - $post_ids = $this->factory->post->create_many( 10 ); + $post_ids = $this->factory->post->create_many( 4 ); foreach ( $post_ids as $post_id ) clean_post_cache( $post_id ); @@ -79,12 +79,12 @@ class Tests_Post_Query extends WP_UnitTestCase { $query = new WP_Query( array( 'post_type' => 'post', - 'posts_per_page' => 5, + 'posts_per_page' => 3, ) ); - // Sixth post added in filter - $this->assertEquals( 6, count( $query->posts ) ); - $this->assertEquals( 6, $query->post_count ); + // Fourth post added in filter + $this->assertEquals( 4, count( $query->posts ) ); + $this->assertEquals( 4, $query->post_count ); foreach ( $query->posts as $post ) { diff --git a/tests/phpunit/tests/query/conditionals.php b/tests/phpunit/tests/query/conditionals.php index 4c91ecf466..6eeb571e6c 100644 --- a/tests/phpunit/tests/query/conditionals.php +++ b/tests/phpunit/tests/query/conditionals.php @@ -251,7 +251,8 @@ class Tests_Query_Conditionals extends WP_UnitTestCase { // 'page/?([0-9]{1,})/?$' => 'index.php?&paged=$matches[1]', function test_paged() { - $this->factory->post->create_many( 15 ); + update_option( 'posts_per_page', 2 ); + $this->factory->post->create_many( 5 ); for ( $i = 2; $i <= 3; $i++ ) { $this->go_to("/page/{$i}/"); $this->assertQueryTrue('is_home', 'is_paged'); @@ -304,7 +305,8 @@ class Tests_Query_Conditionals extends WP_UnitTestCase { // 'search/(.+)/page/?([0-9]{1,})/?$' => 'index.php?s=$matches[1]&paged=$matches[2]', function test_search_paged() { - $this->factory->post->create_many( 10, array( 'post_title' => 'test' ) ); + update_option( 'posts_per_page', 2 ); + $this->factory->post->create_many( 3, array( 'post_title' => 'test' ) ); $this->go_to('/search/test/page/2/'); $this->assertQueryTrue('is_search', 'is_paged'); } @@ -344,7 +346,8 @@ class Tests_Query_Conditionals extends WP_UnitTestCase { // 'category/(.+?)/page/?([0-9]{1,})/?$' => 'index.php?category_name=$matches[1]&paged=$matches[2]', function test_category_paged() { - $this->factory->post->create_many( 10 ); + update_option( 'posts_per_page', 2 ); + $this->factory->post->create_many( 3 ); $this->go_to('/category/uncategorized/page/2/'); $this->assertQueryTrue('is_archive', 'is_category', 'is_paged'); } @@ -377,7 +380,8 @@ class Tests_Query_Conditionals extends WP_UnitTestCase { // 'tag/(.+?)/page/?([0-9]{1,})/?$' => 'index.php?tag=$matches[1]&paged=$matches[2]', function test_tag_paged() { - $post_ids = $this->factory->post->create_many( 10 ); + update_option( 'posts_per_page', 2 ); + $post_ids = $this->factory->post->create_many( 3 ); foreach ( $post_ids as $post_id ) $this->factory->term->add_post_terms( $post_id, 'tag-a', 'post_tag' ); $this->go_to('/tag/tag-a/page/2/'); @@ -423,8 +427,9 @@ class Tests_Query_Conditionals extends WP_UnitTestCase { // 'author/([^/]+)/page/?([0-9]{1,})/?$' => 'index.php?author_name=$matches[1]&paged=$matches[2]', function test_author_paged() { + update_option( 'posts_per_page', 2 ); $user_id = $this->factory->user->create( array( 'user_login' => 'user-a' ) ); - $this->factory->post->create_many( 10, array( 'post_author' => $user_id ) ); + $this->factory->post->create_many( 3, array( 'post_author' => $user_id ) ); $this->go_to('/author/user-a/page/2/'); $this->assertQueryTrue('is_archive', 'is_author', 'is_paged'); } @@ -464,7 +469,8 @@ class Tests_Query_Conditionals extends WP_UnitTestCase { // '([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]', function test_ymd_paged() { - $this->factory->post->create_many( 10, array( 'post_date' => '2007-09-04 00:00:00' ) ); + update_option( 'posts_per_page', 2 ); + $this->factory->post->create_many( 3, array( 'post_date' => '2007-09-04 00:00:00' ) ); $this->go_to('/2007/09/04/page/2/'); $this->assertQueryTrue('is_archive', 'is_day', 'is_date', 'is_paged'); } @@ -497,7 +503,8 @@ class Tests_Query_Conditionals extends WP_UnitTestCase { // '([0-9]{4})/([0-9]{1,2})/page/?([0-9]{1,})/?$' => 'index.php?year=$matches[1]&monthnum=$matches[2]&paged=$matches[3]', function test_ym_paged() { - $this->factory->post->create_many( 10, array( 'post_date' => '2007-09-04 00:00:00' ) ); + update_option( 'posts_per_page', 2 ); + $this->factory->post->create_many( 3, array( 'post_date' => '2007-09-04 00:00:00' ) ); $this->go_to('/2007/09/page/2/'); $this->assertQueryTrue('is_archive', 'is_date', 'is_month', 'is_paged'); } @@ -530,7 +537,8 @@ class Tests_Query_Conditionals extends WP_UnitTestCase { // '([0-9]{4})/page/?([0-9]{1,})/?$' => 'index.php?year=$matches[1]&paged=$matches[2]', function test_y_paged() { - $this->factory->post->create_many( 10, array( 'post_date' => '2007-09-04 00:00:00' ) ); + update_option( 'posts_per_page', 2 ); + $this->factory->post->create_many( 3, array( 'post_date' => '2007-09-04 00:00:00' ) ); $this->go_to('/2007/page/2/'); $this->assertQueryTrue('is_archive', 'is_date', 'is_year', 'is_paged'); } diff --git a/tests/phpunit/tests/query/taxQuery.php b/tests/phpunit/tests/query/taxQuery.php index a9b7cf71f8..2bf8dbd6d3 100644 --- a/tests/phpunit/tests/query/taxQuery.php +++ b/tests/phpunit/tests/query/taxQuery.php @@ -840,7 +840,7 @@ class Tests_Query_TaxQuery extends WP_UnitTestCase { public function test_tax_query_relation_or_both_clauses_empty_terms() { // An empty tax query should return an empty array, not all posts. - $this->factory->post->create_many( 10 ); + $this->factory->post->create_many( 2 ); $query = new WP_Query( array( 'fields' => 'ids', @@ -873,7 +873,7 @@ class Tests_Query_TaxQuery extends WP_UnitTestCase { public function test_tax_query_relation_or_one_clause_empty_terms() { // An empty tax query should return an empty array, not all posts. - $this->factory->post->create_many( 10 ); + $this->factory->post->create_many( 2 ); $query = new WP_Query( array( 'fields' => 'ids',