Make WordPress Core

Changeset 493 in tests


Ignore:
Timestamp:
01/04/2012 10:45:09 PM (13 years ago)
Author:
ryan
Message:

Unit tests for wp_delete_category(), wp_insert_category(), term_is_ancestor_of(), and cat_is_ancestor_of()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wp-testcase/test_includes_taxonomy.php

    r454 r493  
    324324    }
    325325
     326    function test_term_is_ancestor_of( ) {
     327        $term = rand_str();
     328        $term2 = rand_str();
     329
     330        $t = wp_insert_term( $term, 'category' );
     331        $t2 = wp_insert_term( $term, 'category', array( 'parent' => $t['term_id'] ) );
     332        if ( function_exists( 'term_is_ancestor_of' ) ) {
     333            $this->assertTrue( term_is_ancestor_of( $t['term_id'], $t2['term_id'], 'category' ) );
     334            $this->assertFalse( term_is_ancestor_of( $t2['term_id'], $t['term_id'], 'category' ) );
     335        }
     336        $this->assertTrue( cat_is_ancestor_of( $t['term_id'], $t2['term_id']) );
     337        $this->assertFalse( cat_is_ancestor_of( $t2['term_id'], $t['term_id']) );
     338
     339        wp_delete_term($t['term_id'], 'category');
     340        wp_delete_term($t2['term_id'], 'category');
     341    }
     342
     343    function test_wp_insert_delete_category() {
     344        $term = rand_str();
     345        $this->assertNull( category_exists( $term ) );
     346
     347        $initial_count = wp_count_terms( 'category' );
     348
     349        $t = wp_insert_category( array( 'cat_name' => $term ) );
     350        $this->assertTrue( is_numeric($t) );
     351        $this->assertFalse( is_wp_error($t) );
     352        $this->assertTrue( $t > 0 );
     353        $this->assertEquals( $initial_count + 1, wp_count_terms( 'category' ) );
     354
     355        // make sure the term exists
     356        $this->assertTrue( term_exists($term) > 0 );
     357        $this->assertTrue( term_exists($t) > 0 );
     358
     359        // now delete it
     360        $this->assertTrue( wp_delete_category($t) );
     361        $this->assertNull( term_exists($term) );
     362        $this->assertNull( term_exists($t) );
     363        $this->assertEquals( $initial_count, wp_count_terms('category') );
     364    }
    326365}
    327366
Note: See TracChangeset for help on using the changeset viewer.