Make WordPress Core


Ignore:
Timestamp:
10/03/2014 01:30:22 PM (10 years ago)
Author:
boonebgorges
Message:

Improve unit test coverage for wp_insert_term().

See #5809, #22023.

File:
1 edited

Legend:

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

    r28926 r29830  
    235235        $this->assertEquals( 0, wp_insert_category( $cat, false ) );
    236236    }
    237 
    238     /**
    239      * @ticket 17689
    240      */
    241     function test_duplicate_name() {
    242         $term = $this->factory->tag->create_and_get( array( 'name' => 'Bozo' ) );
    243         $this->assertFalse( is_wp_error( $term ) );
    244         $this->assertTrue( empty( $term->errors ) );
    245 
    246         // Test existing term name with unique slug
    247         $term1 = $this->factory->tag->create( array( 'name' => 'Bozo', 'slug' => 'bozo1' ) );
    248         $this->assertFalse( is_wp_error( $term1 ) );
    249         $this->assertTrue( empty($term1->errors ) );
    250 
    251         // Test an existing term name
    252         $term2 = $this->factory->tag->create( array( 'name' => 'Bozo' ) );
    253         $this->assertTrue( is_wp_error( $term2 ) );
    254         $this->assertNotEmpty( $term2->errors );
    255 
    256         // Test named terms ending in special characters
    257         $term3 = $this->factory->tag->create( array( 'name' => 'T$' ) );
    258         $term4 = $this->factory->tag->create( array( 'name' => 'T$$' ) );
    259         $term5 = $this->factory->tag->create( array( 'name' => 'T$$$' ) );
    260         $term6 = $this->factory->tag->create( array( 'name' => 'T$$$$' ) );
    261         $term7 = $this->factory->tag->create( array( 'name' => 'T$$$$' ) );
    262         $this->assertTrue( is_wp_error( $term7 ) );
    263         $this->assertNotEmpty( $term7->errors );
    264         $this->assertEquals( $term6, $term7->error_data['term_exists'] );
    265 
    266         $terms = array_map( 'get_tag', array( $term3, $term4, $term5, $term6 ) );
    267         $this->assertCount( 4, array_unique( wp_list_pluck( $terms, 'slug' ) ) );
    268 
    269         // Test named terms with only special characters
    270         $term8 = $this->factory->tag->create( array( 'name' => '$' ) );
    271         $term9 = $this->factory->tag->create( array( 'name' => '$$' ) );
    272         $term10 = $this->factory->tag->create( array( 'name' => '$$$' ) );
    273         $term11 = $this->factory->tag->create( array( 'name' => '$$$$' ) );
    274         $term12 = $this->factory->tag->create( array( 'name' => '$$$$' ) );
    275         $this->assertTrue( is_wp_error( $term12 ) );
    276         $this->assertNotEmpty( $term12->errors );
    277         $this->assertEquals( $term11, $term12->error_data['term_exists'] );
    278 
    279         $terms = array_map( 'get_tag', array( $term8, $term9, $term10, $term11 ) );
    280         $this->assertCount( 4, array_unique( wp_list_pluck( $terms, 'slug' ) ) );
    281 
    282         $term13 = $this->factory->tag->create( array( 'name' => 'A' ) );
    283         $this->assertFalse( is_wp_error( $term13 ) );
    284         $term14 = $this->factory->tag->create( array( 'name' => 'A' ) );
    285         $this->assertTrue( is_wp_error( $term14 ) );
    286         $term15 = $this->factory->tag->create( array( 'name' => 'A+', 'slug' => 'a' ) );
    287         $this->assertFalse( is_wp_error( $term15 ) );
    288         $term16 = $this->factory->tag->create( array( 'name' => 'A+' ) );
    289         $this->assertTrue( is_wp_error( $term16 ) );
    290         $term17 = $this->factory->tag->create( array( 'name' => 'A++' ) );
    291         $this->assertFalse( is_wp_error( $term17 ) );
    292         $term18 = $this->factory->tag->create( array( 'name' => 'A-', 'slug' => 'a' ) );
    293         $this->assertFalse( is_wp_error( $term18 ) );
    294         $term19 = $this->factory->tag->create( array( 'name' => 'A-' ) );
    295         $this->assertTrue( is_wp_error( $term19 ) );
    296         $term20 = $this->factory->tag->create( array( 'name' => 'A--' ) );
    297         $this->assertFalse( is_wp_error( $term20 ) );
    298     }
    299237}
Note: See TracChangeset for help on using the changeset viewer.