Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (9 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.php

    r38398 r42343  
    55 */
    66class Tests_Term extends WP_UnitTestCase {
    7         protected $taxonomy = 'category';
     7        protected $taxonomy        = 'category';
    88        protected static $post_ids = array();
    99
     
    1616         */
    1717        public function test_wp_delete_term_should_invalidate_cache_for_child_terms() {
    18                 register_taxonomy( 'wptests_tax', 'post', array(
    19                         'hierarchical' => true,
    20                 ) );
    21 
    22                 $parent = self::factory()->term->create( array(
    23                         'taxonomy' => 'wptests_tax',
    24                 ) );
    25 
    26                 $child = self::factory()->term->create( array(
    27                         'taxonomy' => 'wptests_tax',
    28                         'parent' => $parent,
    29                         'slug' => 'foo',
    30                 ) );
     18                register_taxonomy(
     19                        'wptests_tax', 'post', array(
     20                                'hierarchical' => true,
     21                        )
     22                );
     23
     24                $parent = self::factory()->term->create(
     25                        array(
     26                                'taxonomy' => 'wptests_tax',
     27                        )
     28                );
     29
     30                $child = self::factory()->term->create(
     31                        array(
     32                                'taxonomy' => 'wptests_tax',
     33                                'parent'   => $parent,
     34                                'slug'     => 'foo',
     35                        )
     36                );
    3137
    3238                // Prime the cache.
     
    4551                // insert a term
    4652                $term = rand_str();
    47                 $t = wp_insert_term( $term, $this->taxonomy );
     53                $t    = wp_insert_term( $term, $this->taxonomy );
    4854                $this->assertInternalType( 'array', $t );
    49                 $term_obj = get_term_by('name', $term, $this->taxonomy);
    50                 $this->assertEquals( $t['term_id'], term_exists($term_obj->slug) );
     55                $term_obj = get_term_by( 'name', $term, $this->taxonomy );
     56                $this->assertEquals( $t['term_id'], term_exists( $term_obj->slug ) );
    5157
    5258                // clean up
    53                 $this->assertTrue( wp_delete_term($t['term_id'], $this->taxonomy) );
     59                $this->assertTrue( wp_delete_term( $t['term_id'], $this->taxonomy ) );
    5460        }
    5561
     
    6874        function test_wp_add_remove_object_terms() {
    6975                $posts = self::$post_ids;
    70                 $tags = self::factory()->tag->create_many( 5 );
     76                $tags  = self::factory()->tag->create_many( 5 );
    7177
    7278                $tt = wp_add_object_terms( $posts[0], $tags[1], 'post_tag' );
     
    7581
    7682                $three_tags = array( $tags[0], $tags[1], $tags[2] );
    77                 $tt = wp_add_object_terms( $posts[1], $three_tags, 'post_tag' );
     83                $tt         = wp_add_object_terms( $posts[1], $three_tags, 'post_tag' );
    7884                $this->assertEquals( 3, count( $tt ) );
    7985                $this->assertEquals( $three_tags, wp_get_object_terms( $posts[1], 'post_tag', array( 'fields' => 'ids' ) ) );
     
    8591                $this->assertEquals( 0, count( wp_get_object_terms( $posts[1], 'post_tag' ) ) );
    8692
    87                 foreach ( $tags as $term_id )
     93                foreach ( $tags as $term_id ) {
    8894                        $this->assertTrue( wp_delete_term( $term_id, 'post_tag' ) );
    89 
    90                 foreach ( $posts as $post_id )
     95                }
     96
     97                foreach ( $posts as $post_id ) {
    9198                        $this->assertTrue( (bool) wp_delete_post( $post_id ) );
     99                }
    92100        }
    93101
     
    95103         * @group category.php
    96104         */
    97         function test_term_is_ancestor_of( ) {
    98                 $term = rand_str();
     105        function test_term_is_ancestor_of() {
     106                $term  = rand_str();
    99107                $term2 = rand_str();
    100108
     
    107115                        $this->assertFalse( term_is_ancestor_of( $t2['term_id'], $t['term_id'], 'category' ) );
    108116                }
    109                 $this->assertTrue( cat_is_ancestor_of( $t['term_id'], $t2['term_id']) );
    110                 $this->assertFalse( cat_is_ancestor_of( $t2['term_id'], $t['term_id']) );
    111 
    112                 wp_delete_term($t['term_id'], 'category');
    113                 wp_delete_term($t2['term_id'], 'category');
     117                $this->assertTrue( cat_is_ancestor_of( $t['term_id'], $t2['term_id'] ) );
     118                $this->assertFalse( cat_is_ancestor_of( $t2['term_id'], $t['term_id'] ) );
     119
     120                wp_delete_term( $t['term_id'], 'category' );
     121                wp_delete_term( $t2['term_id'], 'category' );
    114122        }
    115123
     
    121129
    122130                $t = wp_insert_category( array( 'cat_name' => $term ) );
    123                 $this->assertTrue( is_numeric($t) );
     131                $this->assertTrue( is_numeric( $t ) );
    124132                $this->assertNotWPError( $t );
    125133                $this->assertTrue( $t > 0 );
     
    127135
    128136                // make sure the term exists
    129                 $this->assertTrue( term_exists($term) > 0 );
    130                 $this->assertTrue( term_exists($t) > 0 );
     137                $this->assertTrue( term_exists( $term ) > 0 );
     138                $this->assertTrue( term_exists( $t ) > 0 );
    131139
    132140                // now delete it
    133                 $this->assertTrue( wp_delete_category($t) );
    134                 $this->assertNull( term_exists($term) );
    135                 $this->assertNull( term_exists($t) );
    136                 $this->assertEquals( $initial_count, wp_count_terms('category') );
     141                $this->assertTrue( wp_delete_category( $t ) );
     142                $this->assertNull( term_exists( $term ) );
     143                $this->assertNull( term_exists( $t ) );
     144                $this->assertEquals( $initial_count, wp_count_terms( 'category' ) );
    137145        }
    138146
     
    142150        function test_wp_set_post_categories() {
    143151                $post_id = self::$post_ids[0];
    144                 $post = get_post( $post_id );
     152                $post    = get_post( $post_id );
    145153
    146154                $this->assertInternalType( 'array', $post->post_category );
     
    152160                wp_set_post_categories( $post_id, array( $term1['term_id'], $term2['term_id'] ) );
    153161                $this->assertEquals( 2, count( $post->post_category ) );
    154                 $this->assertEquals( array( $term2['term_id'], $term1['term_id'] ) , $post->post_category );
     162                $this->assertEquals( array( $term2['term_id'], $term1['term_id'] ), $post->post_category );
    155163
    156164                wp_set_post_categories( $post_id, $term3['term_id'], true );
    157                 $this->assertEquals( array( $term2['term_id'], $term3['term_id'], $term1['term_id'] ) , $post->post_category );
     165                $this->assertEquals( array( $term2['term_id'], $term3['term_id'], $term1['term_id'] ), $post->post_category );
    158166
    159167                $term4 = wp_insert_term( 'Burrito', 'category' );
     
    179187                $term = wp_insert_term( 'foo', $this->taxonomy );
    180188
    181                 $this->assertEquals( 0, sanitize_term_field( 'parent',  0, $term['term_id'], $this->taxonomy, 'raw' ) );
    182                 $this->assertEquals( 1, sanitize_term_field( 'parent',  1, $term['term_id'], $this->taxonomy, 'raw' ) );
     189                $this->assertEquals( 0, sanitize_term_field( 'parent', 0, $term['term_id'], $this->taxonomy, 'raw' ) );
     190                $this->assertEquals( 1, sanitize_term_field( 'parent', 1, $term['term_id'], $this->taxonomy, 'raw' ) );
    183191                $this->assertEquals( 0, sanitize_term_field( 'parent', -1, $term['term_id'], $this->taxonomy, 'raw' ) );
    184192                $this->assertEquals( 0, sanitize_term_field( 'parent', '', $term['term_id'], $this->taxonomy, 'raw' ) );
     
    186194
    187195        private function assertPostHasTerms( $post_id, $expected_term_ids, $taxonomy ) {
    188                 $assigned_term_ids = wp_get_object_terms( $post_id, $taxonomy, array(
    189                         'fields' => 'ids'
    190                 ) );
     196                $assigned_term_ids = wp_get_object_terms(
     197                        $post_id, $taxonomy, array(
     198                                'fields' => 'ids',
     199                        )
     200                );
    191201
    192202                $this->assertEquals( $expected_term_ids, $assigned_term_ids );
Note: See TracChangeset for help on using the changeset viewer.