Make WordPress Core


Ignore:
Timestamp:
10/30/2014 06:52:37 PM (10 years ago)
Author:
boonebgorges
Message:

Move term_exists() tests to their own file.

File:
1 edited

Legend:

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

    r29997 r30118  
    5252        $this->assertNull( term_exists($t['term_id']) );
    5353        $this->assertEquals( $initial_count, wp_count_terms($this->taxonomy) );
    54     }
    55 
    56     public function test_term_exists_term_0() {
    57         $this->assertSame( 0, term_exists( 0 ) );
    58     }
    59 
    60     public function test_term_exists_term_int_taxonomy_nonempty_term_exists() {
    61         $t = $this->factory->term->create( array(
    62             'taxonomy' => 'post_tag',
    63         ) );
    64 
    65         $found = term_exists( intval( $t ), 'post_tag' );
    66         $this->assertEquals( $t, $found['term_id'] );
    67     }
    68 
    69     public function test_term_exists_term_int_taxonomy_nonempty_term_does_not_exist() {
    70         $this->assertNull( term_exists( 54321, 'post_tag' ) );
    71     }
    72 
    73     public function test_term_exists_term_int_taxonomy_nonempty_wrong_taxonomy() {
    74         $t = $this->factory->term->create( array(
    75             'taxonomy' => 'post_tag',
    76         ) );
    77 
    78         $this->assertNull( term_exists( intval( $t ), 'foo' ) );
    79     }
    80 
    81     public function test_term_exists_term_int_taxonomy_empty_term_exists() {
    82         $t = $this->factory->term->create( array(
    83             'taxonomy' => 'post_tag',
    84         ) );
    85 
    86         $found = term_exists( intval( $t ), 'post_tag' );
    87         $this->assertEquals( $t, $found['term_id'] );
    88     }
    89 
    90     public function test_term_exists_term_int_taxonomy_empty_term_does_not_exist() {
    91         $this->assertNull( term_exists( 54321 ) );
    92     }
    93 
    94     public function test_term_exists_unslash_term() {
    95         $t = $this->factory->term->create( array(
    96             'taxonomy' => 'post_tag',
    97             'name' => 'I "love" WordPress\'s taxonomy system',
    98         ) );
    99 
    100         $found = term_exists( 'I \"love\" WordPress\\\'s taxonomy system' );
    101         $this->assertEquals( $t, $found );
    102     }
    103 
    104     public function test_term_exists_trim_term() {
    105         $t = $this->factory->term->create( array(
    106             'taxonomy' => 'post_tag',
    107             'slug' => 'foo',
    108         ) );
    109 
    110         $found = term_exists( '  foo  ' );
    111         $this->assertEquals( $t, $found );
    112     }
    113 
    114     public function test_term_exists_term_trimmed_to_empty_string() {
    115         $this->assertNull( term_exists( '   ' ) );
    116     }
    117 
    118     /**
    119      * @ticket 29589
    120      */
    121     public function test_term_exists_existing_term_that_sanitizes_to_empty() {
    122         wp_insert_term( '//', 'category' );
    123         $this->assertNotEmpty( term_exists( '//' ) );
    124         $this->assertNotEmpty( term_exists( '//', 'category' ) );
    125 
    126         wp_insert_term( '>>', 'category' );
    127         $this->assertNotEmpty( term_exists( '>>' ) );
    128         $this->assertNotEmpty( term_exists( '>>', 'category' ) );
    129     }
    130 
    131     public function test_term_exists_taxonomy_nonempty_parent_nonempty_match_slug() {
    132         register_taxonomy( 'foo', 'post', array(
    133             'hierarchical' => true,
    134         ) );
    135 
    136         $parent_term = $this->factory->term->create( array(
    137             'taxonomy' => 'foo',
    138         ) );
    139 
    140         $t = $this->factory->term->create( array(
    141             'taxonomy' => 'foo',
    142             'parent' => $parent_term,
    143             'slug' => 'child-term',
    144         ) );
    145 
    146         $found = term_exists( 'child-term', 'foo', $parent_term );
    147 
    148         _unregister_taxonomy( 'foo' );
    149 
    150         $this->assertInternalType( 'array', $found );
    151         $this->assertEquals( $t, $found['term_id'] );
    152     }
    153 
    154     /**
    155      * @ticket 29851
    156      */
    157     public function test_term_exists_taxonomy_nonempty_parent_0_should_return_false_for_child_term() {
    158         register_taxonomy( 'foo', 'post', array(
    159             'hierarchical' => true,
    160         ) );
    161 
    162         $parent_term = $this->factory->term->create( array(
    163             'taxonomy' => 'foo',
    164         ) );
    165 
    166         $t = $this->factory->term->create( array(
    167             'taxonomy' => 'foo',
    168             'parent' => $parent_term,
    169             'slug' => 'child-term',
    170         ) );
    171 
    172         $found = term_exists( 'child-term', 'foo', 0 );
    173 
    174         _unregister_taxonomy( 'foo' );
    175 
    176         $this->assertSame( null, $found['term_id'] );
    177     }
    178 
    179     public function test_term_exists_taxonomy_nonempty_parent_nonempty_match_name() {
    180         register_taxonomy( 'foo', 'post', array(
    181             'hierarchical' => true,
    182         ) );
    183 
    184         $parent_term = $this->factory->term->create( array(
    185             'taxonomy' => 'foo',
    186         ) );
    187 
    188         $t = $this->factory->term->create( array(
    189             'taxonomy' => 'foo',
    190             'parent' => $parent_term,
    191             'name' => 'Child Term',
    192         ) );
    193 
    194         $found = term_exists( 'Child Term', 'foo', $parent_term );
    195 
    196         _unregister_taxonomy( 'foo' );
    197 
    198         $this->assertInternalType( 'array', $found );
    199         $this->assertEquals( $t, $found['term_id'] );
    200     }
    201 
    202     public function test_term_exists_taxonomy_nonempty_parent_empty_match_slug() {
    203         register_taxonomy( 'foo', 'post', array() );
    204 
    205         $t = $this->factory->term->create( array(
    206             'taxonomy' => 'foo',
    207             'slug' => 'kewl-dudez',
    208         ) );
    209 
    210         $found = term_exists( 'kewl-dudez', 'foo' );
    211 
    212         _unregister_taxonomy( 'foo' );
    213 
    214         $this->assertInternalType( 'array', $found );
    215         $this->assertEquals( $t, $found['term_id'] );
    216     }
    217 
    218     public function test_term_exists_taxonomy_nonempty_parent_empty_match_name() {
    219         register_taxonomy( 'foo', 'post', array() );
    220 
    221         $t = $this->factory->term->create( array(
    222             'taxonomy' => 'foo',
    223             'name' => 'Kewl Dudez',
    224         ) );
    225 
    226         $found = term_exists( 'Kewl Dudez', 'foo' );
    227 
    228         _unregister_taxonomy( 'foo' );
    229 
    230         $this->assertInternalType( 'array', $found );
    231         $this->assertEquals( $t, $found['term_id'] );
    232     }
    233 
    234     public function test_term_exists_taxonomy_empty_parent_empty_match_slug() {
    235         register_taxonomy( 'foo', 'post', array() );
    236 
    237         $t = $this->factory->term->create( array(
    238             'taxonomy' => 'foo',
    239             'name' => 'juicy-fruit',
    240         ) );
    241 
    242         $found = term_exists( 'juicy-fruit' );
    243 
    244         _unregister_taxonomy( 'foo' );
    245 
    246         $this->assertInternalType( 'string', $found );
    247         $this->assertEquals( $t, $found );
    248     }
    249 
    250     public function test_term_exists_taxonomy_empty_parent_empty_match_name() {
    251         register_taxonomy( 'foo', 'post', array() );
    252 
    253         $t = $this->factory->term->create( array(
    254             'taxonomy' => 'foo',
    255             'name' => 'Juicy Fruit',
    256         ) );
    257 
    258         $found = term_exists( 'Juicy Fruit' );
    259 
    260         _unregister_taxonomy( 'foo' );
    261 
    262         $this->assertInternalType( 'string', $found );
    263         $this->assertEquals( $t, $found );
    264     }
    265 
    266     function test_term_exists_known() {
    267         // insert a term
    268         $term = rand_str();
    269         $t = wp_insert_term( $term, $this->taxonomy );
    270         $this->assertInternalType( 'array', $t );
    271         $this->assertEquals( $t['term_id'], term_exists($t['term_id']) );
    272         $this->assertEquals( $t['term_id'], term_exists($term) );
    273 
    274         // clean up
    275         $this->assertTrue( wp_delete_term($t['term_id'], $this->taxonomy) );
    276     }
    277 
    278     function test_term_exists_unknown() {
    279         $this->assertNull( term_exists(rand_str()) );
    280         $this->assertEquals( 0, term_exists(0) );
    281         $this->assertEquals( 0, term_exists('') );
    282         $this->assertEquals( 0, term_exists(NULL) );
    28354    }
    28455
Note: See TracChangeset for help on using the changeset viewer.