Create fewer fixtures in some tests.

See #30017, #33968.

git-svn-id: https://develop.svn.wordpress.org/trunk@35162 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Boone Gorges 2015-10-14 21:23:03 +00:00
parent c98ac461a9
commit 6c28fe3853
9 changed files with 47 additions and 41 deletions

View File

@ -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));
}
/**

View File

@ -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 );

View File

@ -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,
) );

View File

@ -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' ) );

View File

@ -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 );
}

View File

@ -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 )

View File

@ -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 ) {

View File

@ -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');
}

View File

@ -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',