Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 7 additions & 21 deletions tests/phpunit/tests/post/getPages.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,28 +55,22 @@ public function test_get_pages_cache() {
$time1 = wp_cache_get( 'last_changed', 'posts' );
$this->assertNotEmpty( $time1 );
$num_queries = get_num_queries();
foreach ( $pages as $page ) {
$this->assertInstanceOf( 'WP_Post', $page );
}
$this->assertContainsOnlyInstancesOf( 'WP_Post', $pages );

// Again. num_queries and last_changed should remain the same.
$pages = get_pages();
$this->assertCount( 3, $pages );
$this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) );
$this->assertSame( $num_queries, get_num_queries() );
foreach ( $pages as $page ) {
$this->assertInstanceOf( 'WP_Post', $page );
}
$this->assertContainsOnlyInstancesOf( 'WP_Post', $pages );

// 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' => 2 ) );
$this->assertCount( 2, $pages );
$this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) );
$this->assertSame( $num_queries + 1, get_num_queries() );
foreach ( $pages as $page ) {
$this->assertInstanceOf( 'WP_Post', $page );
}
$this->assertContainsOnlyInstancesOf( 'WP_Post', $pages );

$num_queries = get_num_queries();

Expand All @@ -85,18 +79,14 @@ public function test_get_pages_cache() {
$this->assertCount( 2, $pages );
$this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) );
$this->assertSame( $num_queries, get_num_queries() );
foreach ( $pages as $page ) {
$this->assertInstanceOf( 'WP_Post', $page );
}
$this->assertContainsOnlyInstancesOf( 'WP_Post', $pages );

// Do the first query again. The interim queries should not affect it.
$pages = get_pages();
$this->assertCount( 3, $pages );
$this->assertSame( $time1, wp_cache_get( 'last_changed', 'posts' ) );
$this->assertSame( $num_queries, get_num_queries() );
foreach ( $pages as $page ) {
$this->assertInstanceOf( 'WP_Post', $page );
}
$this->assertContainsOnlyInstancesOf( 'WP_Post', $pages );

// Force last_changed to increment.
clean_post_cache( $pages[0]->ID );
Expand All @@ -109,9 +99,7 @@ public function test_get_pages_cache() {
$this->assertCount( 2, $pages );
$this->assertSame( $time2, wp_cache_get( 'last_changed', 'posts' ) );
$this->assertSame( $num_queries + 1, get_num_queries() );
foreach ( $pages as $page ) {
$this->assertInstanceOf( 'WP_Post', $page );
}
$this->assertContainsOnlyInstancesOf( 'WP_Post', $pages );

$last_changed = wp_cache_get( 'last_changed', 'posts' );

Expand All @@ -129,9 +117,7 @@ public function test_get_pages_cache() {
$this->assertCount( 2, $pages );
$this->assertSame( $last_changed, wp_cache_get( 'last_changed', 'posts' ) );
$this->assertSame( $num_queries + 1, get_num_queries() );
foreach ( $pages as $page ) {
$this->assertInstanceOf( 'WP_Post', $page );
}
$this->assertContainsOnlyInstancesOf( 'WP_Post', $pages );
}

/**
Expand Down
4 changes: 1 addition & 3 deletions tests/phpunit/tests/post/wpPostType.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ public function test_instances() {

$this->assertNotEmpty( $wp_post_types );

foreach ( $wp_post_types as $post_type ) {
$this->assertInstanceOf( 'WP_Post_Type', $post_type );
}
$this->assertContainsOnlyInstancesOf( 'WP_Post_Type', $wp_post_types );
}

public function test_add_supports_defaults() {
Expand Down
8 changes: 2 additions & 6 deletions tests/phpunit/tests/term/getTerms.php
Original file line number Diff line number Diff line change
Expand Up @@ -2876,9 +2876,7 @@ public function test_should_return_wp_term_objects() {

$this->assertNotEmpty( $found );

foreach ( $found as $term ) {
$this->assertInstanceOf( 'WP_Term', $term );
}
$this->assertContainsOnlyInstancesOf( 'WP_Term', $found );
}

/**
Expand Down Expand Up @@ -2914,9 +2912,7 @@ public function test_should_return_wp_term_objects_when_pulling_from_the_cache()

$this->assertNotEmpty( $found );

foreach ( $found as $term ) {
$this->assertInstanceOf( 'WP_Term', $term );
}
$this->assertContainsOnlyInstancesOf( 'WP_Term', $found );
}

/**
Expand Down
8 changes: 2 additions & 6 deletions tests/phpunit/tests/term/wpGetObjectTerms.php
Original file line number Diff line number Diff line change
Expand Up @@ -781,9 +781,7 @@ public function test_should_return_wp_term_objects_for_fields_all() {
);

$this->assertNotEmpty( $found );
foreach ( $found as $f ) {
$this->assertInstanceOf( 'WP_Term', $f );
}
$this->assertContainsOnlyInstancesOf( 'WP_Term', $found );
}

/**
Expand All @@ -804,9 +802,7 @@ public function test_should_return_wp_term_objects_for_fields_all_with_object_id
);

$this->assertNotEmpty( $found );
foreach ( $found as $f ) {
$this->assertInstanceOf( 'WP_Term', $f );
}
$this->assertContainsOnlyInstancesOf( 'WP_Term', $found );
}

/**
Expand Down
4 changes: 1 addition & 3 deletions tests/phpunit/tests/term/wpTaxonomy.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ public function test_instances() {

$this->assertNotEmpty( $wp_taxonomies );

foreach ( $wp_taxonomies as $taxonomy ) {
$this->assertInstanceOf( 'WP_Taxonomy', $taxonomy );
}
$this->assertContainsOnlyInstancesOf( 'WP_Taxonomy', $wp_taxonomies );
}

public function test_does_not_add_query_var_if_not_public() {
Expand Down
16 changes: 4 additions & 12 deletions tests/phpunit/tests/user/query.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,7 @@ public function test_get_all() {

// +1 for the default user created during installation.
$this->assertCount( 13, $users );
foreach ( $users as $user ) {
$this->assertInstanceOf( 'WP_User', $user );
}
$this->assertContainsOnlyInstancesOf( 'WP_User', $users );

$users = new WP_User_Query(
array(
Expand All @@ -150,9 +148,7 @@ public function test_get_all() {
);
$users = $users->get_results();
$this->assertCount( 13, $users );
foreach ( $users as $user ) {
$this->assertInstanceOf( 'WP_User', $user );
}
$this->assertContainsOnlyInstancesOf( 'WP_User', $users );
}

/**
Expand Down Expand Up @@ -1416,9 +1412,7 @@ public function test_get_multiple_roles_should_only_match_users_who_have_each_ro

$this->assertCount( 2, $users );

foreach ( $users as $user ) {
$this->assertInstanceOf( 'WP_User', $user );
}
$this->assertContainsOnlyInstancesOf( 'WP_User', $users );
}

/**
Expand All @@ -1430,9 +1424,7 @@ public function test_get_multiple_roles_or() {

// +1 for the default user created during installation.
$this->assertCount( 8, $users );
foreach ( $users as $user ) {
$this->assertInstanceOf( 'WP_User', $user );
}
$this->assertContainsOnlyInstancesOf( 'WP_User', $users );
}

/**
Expand Down
Loading