Code is Poetry.

WordPress' code just... wasn't.
This is now dealt with.

Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS.
Fixes #41057.



git-svn-id: https://develop.svn.wordpress.org/trunk@42343 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Gary Pendergast
2017-11-30 23:09:33 +00:00
parent ec6a089f98
commit 8f95800d52
1103 changed files with 105981 additions and 78187 deletions

View File

@@ -11,14 +11,14 @@ class Tests_Query extends WP_UnitTestCase {
/**
* @ticket 24785
*
*/
function test_nested_loop_reset_postdata() {
$post_id = self::factory()->post->create();
$post_id = self::factory()->post->create();
$nested_post_id = self::factory()->post->create();
$first_query = new WP_Query( array( 'post__in' => array( $post_id ) ) );
while ( $first_query->have_posts() ) { $first_query->the_post();
while ( $first_query->have_posts() ) {
$first_query->the_post();
$second_query = new WP_Query( array( 'post__in' => array( $nested_post_id ) ) );
while ( $second_query->have_posts() ) {
$second_query->the_post();
@@ -94,9 +94,11 @@ class Tests_Query extends WP_UnitTestCase {
// Don't override the args provided below.
remove_action( 'pre_get_posts', array( $this, 'pre_get_posts_tax_category_tax_query' ) );
register_taxonomy( 'wptests_tax', 'post' );
$terms = self::factory()->term->create_many( 2, array(
'taxonomy' => 'wptests_tax',
) );
$terms = self::factory()->term->create_many(
2, array(
'taxonomy' => 'wptests_tax',
)
);
$posts = self::factory()->post->create_many( 2 );
@@ -104,10 +106,12 @@ class Tests_Query extends WP_UnitTestCase {
wp_set_object_terms( $posts[1], array( $terms[1] ), 'wptests_tax' );
add_action( 'parse_query', array( $this, 'filter_parse_query_to_remove_tax' ) );
$q = new WP_Query( array(
'fields' => 'ids',
'wptests_tax' => $terms[1],
) );
$q = new WP_Query(
array(
'fields' => 'ids',
'wptests_tax' => $terms[1],
)
);
remove_action( 'parse_query', array( $this, 'filter_parse_query_to_remove_tax' ) );
@@ -124,14 +128,16 @@ class Tests_Query extends WP_UnitTestCase {
public function test_get_queried_object_should_return_null_for_not_exists_tax_query() {
register_taxonomy( 'wptests_tax', 'post' );
$q = new WP_Query( array(
'tax_query' => array(
array(
'taxonomy' => 'wptests_tax',
'operator' => 'NOT EXISTS',
$q = new WP_Query(
array(
'tax_query' => array(
array(
'taxonomy' => 'wptests_tax',
'operator' => 'NOT EXISTS',
),
),
),
) );
)
);
$queried_object = $q->get_queried_object();
$this->assertNull( $queried_object );
@@ -140,23 +146,29 @@ class Tests_Query extends WP_UnitTestCase {
public function test_orderby_space_separated() {
global $wpdb;
$q = new WP_Query( array(
'orderby' => 'title date',
'order' => 'DESC',
) );
$q = new WP_Query(
array(
'orderby' => 'title date',
'order' => 'DESC',
)
);
$this->assertContains( "ORDER BY $wpdb->posts.post_title DESC, $wpdb->posts.post_date DESC", $q->request );
}
public function test_cat_querystring_single_term() {
$c1 = self::factory()->category->create( array(
'name' => 'Test Category 1',
'slug' => 'test1',
) );
$c2 = self::factory()->category->create( array(
'name' => 'Test Category 2',
'slug' => 'test2',
) );
$c1 = self::factory()->category->create(
array(
'name' => 'Test Category 1',
'slug' => 'test1',
)
);
$c2 = self::factory()->category->create(
array(
'name' => 'Test Category 2',
'slug' => 'test2',
)
);
$p1 = self::factory()->post->create();
$p2 = self::factory()->post->create();
@@ -166,9 +178,11 @@ class Tests_Query extends WP_UnitTestCase {
wp_set_object_terms( $p2, array( $c1, $c2 ), 'category' );
wp_set_object_terms( $p3, $c2, 'category' );
$url = add_query_arg( array(
'cat' => $c1,
), '/' );
$url = add_query_arg(
array(
'cat' => $c1,
), '/'
);
$this->go_to( $url );
@@ -178,18 +192,24 @@ class Tests_Query extends WP_UnitTestCase {
}
public function test_category_querystring_multiple_terms_comma_separated() {
$c1 = self::factory()->category->create( array(
'name' => 'Test Category 1',
'slug' => 'test1',
) );
$c2 = self::factory()->category->create( array(
'name' => 'Test Category 2',
'slug' => 'test2',
) );
$c3 = self::factory()->category->create( array(
'name' => 'Test Category 3',
'slug' => 'test3',
) );
$c1 = self::factory()->category->create(
array(
'name' => 'Test Category 1',
'slug' => 'test1',
)
);
$c2 = self::factory()->category->create(
array(
'name' => 'Test Category 2',
'slug' => 'test2',
)
);
$c3 = self::factory()->category->create(
array(
'name' => 'Test Category 3',
'slug' => 'test3',
)
);
$p1 = self::factory()->post->create();
$p2 = self::factory()->post->create();
@@ -201,9 +221,11 @@ class Tests_Query extends WP_UnitTestCase {
wp_set_object_terms( $p3, $c2, 'category' );
wp_set_object_terms( $p4, $c3, 'category' );
$url = add_query_arg( array(
'cat' => implode( ',',array( $c1,$c2 ) ),
), '/' );
$url = add_query_arg(
array(
'cat' => implode( ',', array( $c1, $c2 ) ),
), '/'
);
$this->go_to( $url );
@@ -216,18 +238,24 @@ class Tests_Query extends WP_UnitTestCase {
* @ticket 33532
*/
public function test_category_querystring_multiple_terms_formatted_as_array() {
$c1 = self::factory()->category->create( array(
'name' => 'Test Category 1',
'slug' => 'test1',
) );
$c2 = self::factory()->category->create( array(
'name' => 'Test Category 2',
'slug' => 'test2',
) );
$c3 = self::factory()->category->create( array(
'name' => 'Test Category 3',
'slug' => 'test3',
) );
$c1 = self::factory()->category->create(
array(
'name' => 'Test Category 1',
'slug' => 'test1',
)
);
$c2 = self::factory()->category->create(
array(
'name' => 'Test Category 2',
'slug' => 'test2',
)
);
$c3 = self::factory()->category->create(
array(
'name' => 'Test Category 3',
'slug' => 'test3',
)
);
$p1 = self::factory()->post->create();
$p2 = self::factory()->post->create();
@@ -239,9 +267,11 @@ class Tests_Query extends WP_UnitTestCase {
wp_set_object_terms( $p3, $c2, 'category' );
wp_set_object_terms( $p4, $c3, 'category' );
$url = add_query_arg( array(
'cat' => array( $c1, $c2 ),
), '/' );
$url = add_query_arg(
array(
'cat' => array( $c1, $c2 ),
), '/'
);
$this->go_to( $url );
@@ -252,14 +282,18 @@ class Tests_Query extends WP_UnitTestCase {
public function test_tag_querystring_single_term() {
$t1 = self::factory()->tag->create_and_get( array(
'name' => 'Test Tag 1',
'slug' => 'test1',
) );
$t2 = self::factory()->tag->create_and_get( array(
'name' => 'Test Tag 2',
'slug' => 'test2',
) );
$t1 = self::factory()->tag->create_and_get(
array(
'name' => 'Test Tag 1',
'slug' => 'test1',
)
);
$t2 = self::factory()->tag->create_and_get(
array(
'name' => 'Test Tag 2',
'slug' => 'test2',
)
);
$p1 = self::factory()->post->create();
$p2 = self::factory()->post->create();
@@ -269,9 +303,11 @@ class Tests_Query extends WP_UnitTestCase {
wp_set_object_terms( $p2, array( $t1->slug, $t2->slug ), 'post_tag' );
wp_set_object_terms( $p3, $t2->slug, 'post_tag' );
$url = add_query_arg( array(
'tag' => $t1->slug,
), '/' );
$url = add_query_arg(
array(
'tag' => $t1->slug,
), '/'
);
$this->go_to( $url );
@@ -281,18 +317,24 @@ class Tests_Query extends WP_UnitTestCase {
}
public function test_tag_querystring_multiple_terms_comma_separated() {
$c1 = self::factory()->tag->create_and_get( array(
'name' => 'Test Tag 1',
'slug' => 'test1',
) );
$c2 = self::factory()->tag->create_and_get( array(
'name' => 'Test Tag 2',
'slug' => 'test2',
) );
$c3 = self::factory()->tag->create_and_get( array(
'name' => 'Test Tag 3',
'slug' => 'test3',
) );
$c1 = self::factory()->tag->create_and_get(
array(
'name' => 'Test Tag 1',
'slug' => 'test1',
)
);
$c2 = self::factory()->tag->create_and_get(
array(
'name' => 'Test Tag 2',
'slug' => 'test2',
)
);
$c3 = self::factory()->tag->create_and_get(
array(
'name' => 'Test Tag 3',
'slug' => 'test3',
)
);
$p1 = self::factory()->post->create();
$p2 = self::factory()->post->create();
@@ -304,9 +346,11 @@ class Tests_Query extends WP_UnitTestCase {
wp_set_object_terms( $p3, $c2->slug, 'post_tag' );
wp_set_object_terms( $p4, $c3->slug, 'post_tag' );
$url = add_query_arg( array(
'tag' => implode( ',',array( $c1->slug,$c2->slug ) ),
), '/' );
$url = add_query_arg(
array(
'tag' => implode( ',', array( $c1->slug, $c2->slug ) ),
), '/'
);
$this->go_to( $url );
@@ -319,18 +363,24 @@ class Tests_Query extends WP_UnitTestCase {
* @ticket 33532
*/
public function test_tag_querystring_multiple_terms_formatted_as_array() {
$c1 = self::factory()->tag->create_and_get( array(
'name' => 'Test Tag 1',
'slug' => 'test1',
) );
$c2 = self::factory()->tag->create_and_get( array(
'name' => 'Test Tag 2',
'slug' => 'test2',
) );
$c3 = self::factory()->tag->create_and_get( array(
'name' => 'Test Tag 3',
'slug' => 'test3',
) );
$c1 = self::factory()->tag->create_and_get(
array(
'name' => 'Test Tag 1',
'slug' => 'test1',
)
);
$c2 = self::factory()->tag->create_and_get(
array(
'name' => 'Test Tag 2',
'slug' => 'test2',
)
);
$c3 = self::factory()->tag->create_and_get(
array(
'name' => 'Test Tag 3',
'slug' => 'test3',
)
);
$p1 = self::factory()->post->create();
$p2 = self::factory()->post->create();
@@ -342,9 +392,11 @@ class Tests_Query extends WP_UnitTestCase {
wp_set_object_terms( $p3, $c2->slug, 'post_tag' );
wp_set_object_terms( $p4, $c3->slug, 'post_tag' );
$url = add_query_arg( array(
'tag' => array($c1->slug,$c2->slug),
), '/' );
$url = add_query_arg(
array(
'tag' => array( $c1->slug, $c2->slug ),
), '/'
);
$this->go_to( $url );
@@ -368,9 +420,11 @@ class Tests_Query extends WP_UnitTestCase {
wp_set_object_terms( $p2, array( 'test1', 'test2' ), 'test_tax_cat' );
wp_set_object_terms( $p3, 'test2', 'test_tax_cat' );
$url = add_query_arg( array(
'test_tax_cat' => 'test1',
), '/' );
$url = add_query_arg(
array(
'test_tax_cat' => 'test1',
), '/'
);
$this->go_to( $url );
@@ -392,11 +446,13 @@ class Tests_Query extends WP_UnitTestCase {
wp_set_object_terms( $p1, 'test1', 'test_tax_cat' );
wp_set_object_terms( $p2, array( 'test1', 'test2' ), 'test_tax_cat' );
wp_set_object_terms( $p3, 'test2', 'test_tax_cat' );
wp_set_object_terms( $p4, "test3", 'test_tax_cat' );
wp_set_object_terms( $p4, 'test3', 'test_tax_cat' );
$url = add_query_arg( array(
'test_tax_cat' => 'test1,test2',
), '/' );
$url = add_query_arg(
array(
'test_tax_cat' => 'test1,test2',
), '/'
);
$this->go_to( $url );
@@ -421,11 +477,13 @@ class Tests_Query extends WP_UnitTestCase {
wp_set_object_terms( $p1, 'test1', 'test_tax_cat' );
wp_set_object_terms( $p2, array( 'test1', 'test2' ), 'test_tax_cat' );
wp_set_object_terms( $p3, 'test2', 'test_tax_cat' );
wp_set_object_terms( $p4, "test3", 'test_tax_cat' );
wp_set_object_terms( $p4, 'test3', 'test_tax_cat' );
$url = add_query_arg( array(
'test_tax_cat' => array( 'test1', 'test2' ),
), '/' );
$url = add_query_arg(
array(
'test_tax_cat' => array( 'test1', 'test2' ),
), '/'
);
$this->go_to( $url );
@@ -436,7 +494,12 @@ class Tests_Query extends WP_UnitTestCase {
* @ticket 31355
*/
public function test_pages_dont_404_when_queried_post_id_is_modified() {
$post_id = self::factory()->post->create( array( 'post_title' => 'A Test Page', 'post_type' => 'page' ) );
$post_id = self::factory()->post->create(
array(
'post_title' => 'A Test Page',
'post_type' => 'page',
)
);
add_action( 'parse_query', array( $this, 'filter_parse_query_to_modify_queried_post_id' ) );
@@ -455,9 +518,20 @@ class Tests_Query extends WP_UnitTestCase {
public function test_custom_hierarchical_post_types_404_when_queried_post_id_is_modified() {
global $wp_rewrite;
register_post_type( 'guide', array( 'name' => 'Guide', 'public' => true, 'hierarchical' => true ) );
register_post_type(
'guide', array(
'name' => 'Guide',
'public' => true,
'hierarchical' => true,
)
);
$wp_rewrite->flush_rules();
$post_id = self::factory()->post->create( array( 'post_title' => 'A Test Guide', 'post_type' => 'guide' ) );
$post_id = self::factory()->post->create(
array(
'post_title' => 'A Test Guide',
'post_type' => 'guide',
)
);
add_action( 'parse_query', array( $this, 'filter_parse_query_to_modify_queried_post_id' ) );
@@ -478,11 +552,13 @@ class Tests_Query extends WP_UnitTestCase {
* @ticket 34060
*/
public function test_offset_0_should_override_page() {
$q = new WP_Query( array(
'paged' => 2,
'posts_per_page' => 5,
'offset' => 0,
) );
$q = new WP_Query(
array(
'paged' => 2,
'posts_per_page' => 5,
'offset' => 0,
)
);
$this->assertContains( 'LIMIT 0, 5', $q->request );
}
@@ -491,10 +567,12 @@ class Tests_Query extends WP_UnitTestCase {
* @ticket 34060
*/
public function test_offset_should_be_ignored_when_not_set() {
$q = new WP_Query( array(
'paged' => 2,
'posts_per_page' => 5,
) );
$q = new WP_Query(
array(
'paged' => 2,
'posts_per_page' => 5,
)
);
$this->assertContains( 'LIMIT 5, 5', $q->request );
}
@@ -503,11 +581,13 @@ class Tests_Query extends WP_UnitTestCase {
* @ticket 34060
*/
public function test_offset_should_be_ignored_when_passed_a_non_numeric_value() {
$q = new WP_Query( array(
'paged' => 2,
'posts_per_page' => 5,
'offset' => '',
) );
$q = new WP_Query(
array(
'paged' => 2,
'posts_per_page' => 5,
'offset' => '',
)
);
$this->assertContains( 'LIMIT 5, 5', $q->request );
}
@@ -519,10 +599,12 @@ class Tests_Query extends WP_UnitTestCase {
$p1 = self::factory()->post->create( array( 'comment_status' => 'open' ) );
$p2 = self::factory()->post->create( array( 'comment_status' => 'closed' ) );
$q = new WP_Query( array(
'fields' => 'ids',
'comment_status' => 'closed',
) );
$q = new WP_Query(
array(
'fields' => 'ids',
'comment_status' => 'closed',
)
);
$this->assertSame( array( $p2 ), $q->posts );
}
@@ -534,10 +616,12 @@ class Tests_Query extends WP_UnitTestCase {
$p1 = self::factory()->post->create( array( 'ping_status' => 'open' ) );
$p2 = self::factory()->post->create( array( 'ping_status' => 'closed' ) );
$q = new WP_Query( array(
'fields' => 'ids',
'ping_status' => 'closed',
) );
$q = new WP_Query(
array(
'fields' => 'ids',
'ping_status' => 'closed',
)
);
$this->assertSame( array( $p2 ), $q->posts );
}
@@ -549,8 +633,18 @@ class Tests_Query extends WP_UnitTestCase {
register_taxonomy( 'tax1', 'post' );
register_taxonomy( 'tax2', 'post' );
$term1 = $this->factory->term->create( array( 'taxonomy' => 'tax1', 'name' => 'term1' ) );
$term2 = $this->factory->term->create( array( 'taxonomy' => 'tax2', 'name' => 'term2' ) );
$term1 = $this->factory->term->create(
array(
'taxonomy' => 'tax1',
'name' => 'term1',
)
);
$term2 = $this->factory->term->create(
array(
'taxonomy' => 'tax2',
'name' => 'term2',
)
);
$post_id = $this->factory->post->create();
wp_set_object_terms( $post_id, 'term1', 'tax1' );
wp_set_object_terms( $post_id, 'term2', 'tax2' );
@@ -569,8 +663,18 @@ class Tests_Query extends WP_UnitTestCase {
register_taxonomy( 'tax1', 'post' );
register_taxonomy( 'tax2', 'post' );
$term1 = $this->factory->term->create( array( 'taxonomy' => 'tax1', 'name' => 'term1' ) );
$term2 = $this->factory->term->create( array( 'taxonomy' => 'tax2', 'name' => 'term2' ) );
$term1 = $this->factory->term->create(
array(
'taxonomy' => 'tax1',
'name' => 'term1',
)
);
$term2 = $this->factory->term->create(
array(
'taxonomy' => 'tax2',
'name' => 'term2',
)
);
$post_id = $this->factory->post->create();
wp_set_object_terms( $post_id, 'term1', 'tax1' );
wp_set_object_terms( $post_id, 'term2', 'tax2' );