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

@@ -15,29 +15,34 @@ class Tests_Term_Cache extends WP_UnitTestCase {
*/
function test_category_children_cache() {
// Test with only one Parent => Child
$term_id1 = self::factory()->category->create();
$term_id1 = self::factory()->category->create();
$term_id1_child = self::factory()->category->create( array( 'parent' => $term_id1 ) );
$hierarchy = _get_term_hierarchy( 'category' );
$hierarchy = _get_term_hierarchy( 'category' );
$this->assertEquals( array( $term_id1 => array( $term_id1_child ) ), $hierarchy );
// Add another Parent => Child
$term_id2 = self::factory()->category->create();
$term_id2 = self::factory()->category->create();
$term_id2_child = self::factory()->category->create( array( 'parent' => $term_id2 ) );
$hierarchy = _get_term_hierarchy( 'category' );
$hierarchy = _get_term_hierarchy( 'category' );
$this->assertEquals( array( $term_id1 => array( $term_id1_child ), $term_id2 => array( $term_id2_child ) ), $hierarchy );
$this->assertEquals(
array(
$term_id1 => array( $term_id1_child ),
$term_id2 => array( $term_id2_child ),
), $hierarchy
);
}
/**
* @ticket 22526
*/
function test_category_name_change() {
$term = self::factory()->category->create_and_get( array( 'name' => 'Foo' ) );
$term = self::factory()->category->create_and_get( array( 'name' => 'Foo' ) );
$post_id = self::factory()->post->create();
wp_set_post_categories( $post_id, $term->term_id );
$post = get_post( $post_id );
$post = get_post( $post_id );
$cats1 = get_the_category( $post->ID );
$this->assertEquals( $term->name, reset( $cats1 )->name );
@@ -54,26 +59,26 @@ class Tests_Term_Cache extends WP_UnitTestCase {
register_taxonomy( $tax, 'post', array( 'hierarchical' => true ) );
$this->assertTrue( get_taxonomy( $tax )->hierarchical );
$step = 1;
$step = 1;
$parent_id = 0;
$children = 0;
$children = 0;
foreach ( range( 1, 9 ) as $i ) {
switch ( $step ) {
case 1:
$parent = wp_insert_term( 'Parent' . $i, $tax );
$parent_id = $parent['term_id'];
break;
case 2:
$parent = wp_insert_term( 'Child' . $i, $tax, array( 'parent' => $parent_id ) );
$parent_id = $parent['term_id'];
$children++;
break;
case 3:
wp_insert_term( 'Grandchild' . $i, $tax, array( 'parent' => $parent_id ) );
$parent_id = 0;
$children++;
break;
case 1:
$parent = wp_insert_term( 'Parent' . $i, $tax );
$parent_id = $parent['term_id'];
break;
case 2:
$parent = wp_insert_term( 'Child' . $i, $tax, array( 'parent' => $parent_id ) );
$parent_id = $parent['term_id'];
$children++;
break;
case 3:
wp_insert_term( 'Grandchild' . $i, $tax, array( 'parent' => $parent_id ) );
$parent_id = 0;
$children++;
break;
}
$terms = get_terms( $tax, array( 'hide_empty' => false ) );
@@ -98,9 +103,11 @@ class Tests_Term_Cache extends WP_UnitTestCase {
global $wpdb;
register_taxonomy( 'wptests_tax', 'post' );
$term = self::factory()->term->create( array(
'taxonomy' => 'wptests_tax',
) );
$term = self::factory()->term->create(
array(
'taxonomy' => 'wptests_tax',
)
);
$term_object = get_term( $term, 'wptests_tax' );
wp_cache_delete( $term, 'terms' );
@@ -124,9 +131,11 @@ class Tests_Term_Cache extends WP_UnitTestCase {
global $wpdb;
register_taxonomy( 'wptests_tax', 'post' );
$term = self::factory()->term->create( array(
'taxonomy' => 'wptests_tax',
) );
$term = self::factory()->term->create(
array(
'taxonomy' => 'wptests_tax',
)
);
wp_cache_delete( $term, 'terms' );
@@ -151,9 +160,11 @@ class Tests_Term_Cache extends WP_UnitTestCase {
global $wpdb;
register_taxonomy( 'wptests_tax', 'post' );
$term = self::factory()->term->create( array(
'taxonomy' => 'wptests_tax',
) );
$term = self::factory()->term->create(
array(
'taxonomy' => 'wptests_tax',
)
);
wp_cache_delete( $term, 'terms' );
@@ -182,13 +193,17 @@ class Tests_Term_Cache extends WP_UnitTestCase {
register_taxonomy( 'wptests_tax', 'post' );
$terms = self::factory()->term->create_many( 5, array(
'taxonomy' => 'wptests_tax',
) );
$terms = self::factory()->term->create_many(
5, array(
'taxonomy' => 'wptests_tax',
)
);
$term_objects = get_terms( 'wptests_tax', array(
'hide_empty' => false,
) );
$term_objects = get_terms(
'wptests_tax', array(
'hide_empty' => false,
)
);
$num_queries = $wpdb->num_queries;
@@ -226,7 +241,13 @@ class Tests_Term_Cache extends WP_UnitTestCase {
function test_get_term_by_slug_cache() {
global $wpdb;
$term_id = $this->factory->term->create( array( 'slug' => 'burrito', 'name' => 'Taco', 'taxonomy' => 'post_tag' ) );
$term_id = $this->factory->term->create(
array(
'slug' => 'burrito',
'name' => 'Taco',
'taxonomy' => 'post_tag',
)
);
clean_term_cache( $term_id, 'post_tag' );
$num_queries = $wpdb->num_queries;
@@ -251,7 +272,13 @@ class Tests_Term_Cache extends WP_UnitTestCase {
function test_get_term_by_slug_cache_update() {
global $wpdb;
$term_id = $this->factory->term->create( array( 'slug' => 'burrito', 'name' => 'Taco', 'taxonomy' => 'post_tag' ) );
$term_id = $this->factory->term->create(
array(
'slug' => 'burrito',
'name' => 'Taco',
'taxonomy' => 'post_tag',
)
);
clean_term_cache( $term_id, 'post_tag' );
$num_queries = $wpdb->num_queries;
@@ -283,7 +310,13 @@ class Tests_Term_Cache extends WP_UnitTestCase {
function test_get_term_by_name_cache() {
global $wpdb;
$term_id = $this->factory->term->create( array( 'name' => 'Burrito', 'slug' => 'noburrito', 'taxonomy' => 'post_tag' ) );
$term_id = $this->factory->term->create(
array(
'name' => 'Burrito',
'slug' => 'noburrito',
'taxonomy' => 'post_tag',
)
);
clean_term_cache( $term_id, 'post_tag' );
$num_queries = $wpdb->num_queries;
@@ -306,7 +339,13 @@ class Tests_Term_Cache extends WP_UnitTestCase {
function test_get_term_by_name_cache_update() {
global $wpdb;
$term_id = $this->factory->term->create( array( 'name' => 'Burrito', 'slug' => 'noburrito', 'taxonomy' => 'post_tag' ) );
$term_id = $this->factory->term->create(
array(
'name' => 'Burrito',
'slug' => 'noburrito',
'taxonomy' => 'post_tag',
)
);
clean_term_cache( $term_id, 'post_tag' );
$num_queries = $wpdb->num_queries;
@@ -335,10 +374,15 @@ class Tests_Term_Cache extends WP_UnitTestCase {
function test_invalidating_term_caches_should_fail_when_invalidation_is_suspended() {
global $wpdb;
$term_id = $this->factory->term->create( array( 'name' => 'Burrito', 'taxonomy' => 'post_tag' ) );
$term_id = $this->factory->term->create(
array(
'name' => 'Burrito',
'taxonomy' => 'post_tag',
)
);
clean_term_cache( $term_id, 'post_tag' );
$num_queries = $wpdb->num_queries;
$num_queries = $wpdb->num_queries;
$last_changed = wp_cache_get( 'last_changed', 'terms' );
$term1 = get_term_by( 'name', 'Burrito', 'post_tag' );
@@ -373,7 +417,12 @@ class Tests_Term_Cache extends WP_UnitTestCase {
public function test_get_term_by_does_not_prime_term_meta_cache() {
global $wpdb;
$term_id = $this->factory->term->create( array( 'name' => 'Burrito', 'taxonomy' => 'post_tag' ) );
$term_id = $this->factory->term->create(
array(
'name' => 'Burrito',
'taxonomy' => 'post_tag',
)
);
add_term_meta( $term_id, 'foo', 'bar' );
clean_term_cache( $term_id, 'post_tag' );
@@ -409,7 +458,7 @@ class Tests_Term_Cache extends WP_UnitTestCase {
* Modify cached array to insert an empty term ID,
* which will trigger an error in get_term().
*/
$cached_ids = wp_cache_get( $p, 'wptests_tax_relationships' );
$cached_ids = wp_cache_get( $p, 'wptests_tax_relationships' );
$cached_ids[] = 0;
wp_cache_set( $p, $cached_ids, 'wptests_tax_relationships' );