Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (7 years ago)
Author:
pento
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/term/cache.php

    r38776 r42343  
    1616    function test_category_children_cache() {
    1717        // Test with only one Parent => Child
    18         $term_id1 = self::factory()->category->create();
     18        $term_id1       = self::factory()->category->create();
    1919        $term_id1_child = self::factory()->category->create( array( 'parent' => $term_id1 ) );
    20         $hierarchy = _get_term_hierarchy( 'category' );
     20        $hierarchy      = _get_term_hierarchy( 'category' );
    2121
    2222        $this->assertEquals( array( $term_id1 => array( $term_id1_child ) ), $hierarchy );
    2323
    2424        // Add another Parent => Child
    25         $term_id2 = self::factory()->category->create();
     25        $term_id2       = self::factory()->category->create();
    2626        $term_id2_child = self::factory()->category->create( array( 'parent' => $term_id2 ) );
    27         $hierarchy = _get_term_hierarchy( 'category' );
    28 
    29         $this->assertEquals( array( $term_id1 => array( $term_id1_child ), $term_id2 => array( $term_id2_child ) ), $hierarchy );
     27        $hierarchy      = _get_term_hierarchy( 'category' );
     28
     29        $this->assertEquals(
     30            array(
     31                $term_id1 => array( $term_id1_child ),
     32                $term_id2 => array( $term_id2_child ),
     33            ), $hierarchy
     34        );
    3035    }
    3136
     
    3439     */
    3540    function test_category_name_change() {
    36         $term = self::factory()->category->create_and_get( array( 'name' => 'Foo' ) );
     41        $term    = self::factory()->category->create_and_get( array( 'name' => 'Foo' ) );
    3742        $post_id = self::factory()->post->create();
    3843        wp_set_post_categories( $post_id, $term->term_id );
    3944
    40         $post = get_post( $post_id );
     45        $post  = get_post( $post_id );
    4146        $cats1 = get_the_category( $post->ID );
    4247        $this->assertEquals( $term->name, reset( $cats1 )->name );
     
    5560        $this->assertTrue( get_taxonomy( $tax )->hierarchical );
    5661
    57         $step = 1;
     62        $step      = 1;
    5863        $parent_id = 0;
    59         $children = 0;
     64        $children  = 0;
    6065
    6166        foreach ( range( 1, 9 ) as $i ) {
    6267            switch ( $step ) {
    63             case 1:
    64                 $parent = wp_insert_term( 'Parent' . $i, $tax );
    65                 $parent_id = $parent['term_id'];
    66                 break;
    67             case 2:
    68                 $parent = wp_insert_term( 'Child' . $i, $tax, array( 'parent' => $parent_id ) );
    69                 $parent_id = $parent['term_id'];
    70                 $children++;
    71                 break;
    72             case 3:
    73                 wp_insert_term( 'Grandchild' . $i, $tax, array( 'parent' => $parent_id ) );
    74                 $parent_id = 0;
    75                 $children++;
    76                 break;
     68                case 1:
     69                    $parent    = wp_insert_term( 'Parent' . $i, $tax );
     70                    $parent_id = $parent['term_id'];
     71                    break;
     72                case 2:
     73                    $parent    = wp_insert_term( 'Child' . $i, $tax, array( 'parent' => $parent_id ) );
     74                    $parent_id = $parent['term_id'];
     75                    $children++;
     76                    break;
     77                case 3:
     78                    wp_insert_term( 'Grandchild' . $i, $tax, array( 'parent' => $parent_id ) );
     79                    $parent_id = 0;
     80                    $children++;
     81                    break;
    7782            }
    7883
     
    99104
    100105        register_taxonomy( 'wptests_tax', 'post' );
    101         $term = self::factory()->term->create( array(
    102             'taxonomy' => 'wptests_tax',
    103         ) );
     106        $term = self::factory()->term->create(
     107            array(
     108                'taxonomy' => 'wptests_tax',
     109            )
     110        );
    104111
    105112        $term_object = get_term( $term, 'wptests_tax' );
     
    125132
    126133        register_taxonomy( 'wptests_tax', 'post' );
    127         $term = self::factory()->term->create( array(
    128             'taxonomy' => 'wptests_tax',
    129         ) );
     134        $term = self::factory()->term->create(
     135            array(
     136                'taxonomy' => 'wptests_tax',
     137            )
     138        );
    130139
    131140        wp_cache_delete( $term, 'terms' );
     
    152161
    153162        register_taxonomy( 'wptests_tax', 'post' );
    154         $term = self::factory()->term->create( array(
    155             'taxonomy' => 'wptests_tax',
    156         ) );
     163        $term = self::factory()->term->create(
     164            array(
     165                'taxonomy' => 'wptests_tax',
     166            )
     167        );
    157168
    158169        wp_cache_delete( $term, 'terms' );
     
    183194        register_taxonomy( 'wptests_tax', 'post' );
    184195
    185         $terms = self::factory()->term->create_many( 5, array(
    186             'taxonomy' => 'wptests_tax',
    187         ) );
    188 
    189         $term_objects = get_terms( 'wptests_tax', array(
    190             'hide_empty' => false,
    191         ) );
     196        $terms = self::factory()->term->create_many(
     197            5, array(
     198                'taxonomy' => 'wptests_tax',
     199            )
     200        );
     201
     202        $term_objects = get_terms(
     203            'wptests_tax', array(
     204                'hide_empty' => false,
     205            )
     206        );
    192207
    193208        $num_queries = $wpdb->num_queries;
     
    227242        global $wpdb;
    228243
    229         $term_id = $this->factory->term->create( array( 'slug' => 'burrito', 'name' => 'Taco', 'taxonomy' => 'post_tag' ) );
     244        $term_id = $this->factory->term->create(
     245            array(
     246                'slug'     => 'burrito',
     247                'name'     => 'Taco',
     248                'taxonomy' => 'post_tag',
     249            )
     250        );
    230251
    231252        clean_term_cache( $term_id, 'post_tag' );
     
    252273        global $wpdb;
    253274
    254         $term_id = $this->factory->term->create( array( 'slug' => 'burrito', 'name' => 'Taco', 'taxonomy' => 'post_tag' ) );
     275        $term_id = $this->factory->term->create(
     276            array(
     277                'slug'     => 'burrito',
     278                'name'     => 'Taco',
     279                'taxonomy' => 'post_tag',
     280            )
     281        );
    255282
    256283        clean_term_cache( $term_id, 'post_tag' );
     
    284311        global $wpdb;
    285312
    286         $term_id = $this->factory->term->create( array( 'name' => 'Burrito', 'slug' => 'noburrito', 'taxonomy' => 'post_tag' ) );
     313        $term_id = $this->factory->term->create(
     314            array(
     315                'name'     => 'Burrito',
     316                'slug'     => 'noburrito',
     317                'taxonomy' => 'post_tag',
     318            )
     319        );
    287320
    288321        clean_term_cache( $term_id, 'post_tag' );
     
    307340        global $wpdb;
    308341
    309         $term_id = $this->factory->term->create( array( 'name' => 'Burrito', 'slug' => 'noburrito', 'taxonomy' => 'post_tag' ) );
     342        $term_id = $this->factory->term->create(
     343            array(
     344                'name'     => 'Burrito',
     345                'slug'     => 'noburrito',
     346                'taxonomy' => 'post_tag',
     347            )
     348        );
    310349
    311350        clean_term_cache( $term_id, 'post_tag' );
     
    336375        global $wpdb;
    337376
    338         $term_id = $this->factory->term->create( array( 'name' => 'Burrito', 'taxonomy' => 'post_tag' ) );
    339 
    340         clean_term_cache( $term_id, 'post_tag' );
    341         $num_queries = $wpdb->num_queries;
     377        $term_id = $this->factory->term->create(
     378            array(
     379                'name'     => 'Burrito',
     380                'taxonomy' => 'post_tag',
     381            )
     382        );
     383
     384        clean_term_cache( $term_id, 'post_tag' );
     385        $num_queries  = $wpdb->num_queries;
    342386        $last_changed = wp_cache_get( 'last_changed', 'terms' );
    343387
     
    374418        global $wpdb;
    375419
    376         $term_id = $this->factory->term->create( array( 'name' => 'Burrito', 'taxonomy' => 'post_tag' ) );
     420        $term_id = $this->factory->term->create(
     421            array(
     422                'name'     => 'Burrito',
     423                'taxonomy' => 'post_tag',
     424            )
     425        );
    377426        add_term_meta( $term_id, 'foo', 'bar' );
    378427
     
    410459         * which will trigger an error in get_term().
    411460         */
    412         $cached_ids = wp_cache_get( $p, 'wptests_tax_relationships' );
     461        $cached_ids   = wp_cache_get( $p, 'wptests_tax_relationships' );
    413462        $cached_ids[] = 0;
    414463        wp_cache_set( $p, $cached_ids, 'wptests_tax_relationships' );
Note: See TracChangeset for help on using the changeset viewer.