Make WordPress Core


Ignore:
Timestamp:
08/04/2011 08:38:26 PM (15 years ago)
Author:
ryan
Message:

Pinking shears

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wp-testcase/test_includes_taxonomy.php

    r396 r407  
    66        $this->assertEquals(array('category', 'post_tag', 'post_format'), get_object_taxonomies('post'));
    77    }
    8    
     8
    99    function test_get_link_taxonomies() {
    1010        $this->assertEquals(array('link_category'), get_object_taxonomies('link'));
    1111    }
    12    
     12
    1313    function test_get_unknown_taxonomies() {
    1414        // taxonomies for an unknown object type
     
    1919        $this->assertEquals( array(), get_object_taxonomies(NULL) );
    2020    }
    21    
     21
    2222    function test_get_post_taxonomy() {
    2323        foreach ( get_object_taxonomies('post') as $taxonomy ) {
     
    4545        $this->assertTrue( is_taxonomy('link_category') );
    4646    }
    47    
     47
    4848    function test_is_taxonomy_unknown() {
    4949        $this->assertFalse( is_taxonomy(rand_str()) );
     
    5252        $this->assertFalse( is_taxonomy(NULL) );
    5353    }
    54    
     54
    5555    function test_is_taxonomy_hierarchical() {
    5656        $this->assertTrue( is_taxonomy_hierarchical('category') );
     
    5858        $this->assertFalse( is_taxonomy_hierarchical('link_category') );
    5959    }
    60    
     60
    6161    function test_is_taxonomy_hierarchical_unknown() {
    6262        $this->assertFalse( is_taxonomy_hierarchical(rand_str()) );
     
    6565        $this->assertFalse( is_taxonomy_hierarchical(NULL) );
    6666    }
    67    
     67
    6868    function test_register_taxonomy() {
    69        
     69
    7070        // make up a new taxonomy name, and ensure it's unused
    7171        $tax = rand_str();
    7272        $this->assertFalse( is_taxonomy($tax) );
    73        
     73
    7474        register_taxonomy( $tax, 'post' );
    7575        $this->assertTrue( is_taxonomy($tax) );
    76         $this->assertFalse( is_taxonomy_hierarchical($tax) );       
    77        
     76        $this->assertFalse( is_taxonomy_hierarchical($tax) );
     77
    7878        // clean up
    7979        unset($GLOBALS['wp_taxonomies'][$tax]);
    8080    }
    81    
     81
    8282    function test_register_hierarchical_taxonomy() {
    83        
     83
    8484        // make up a new taxonomy name, and ensure it's unused
    8585        $tax = rand_str();
    8686        $this->assertFalse( is_taxonomy($tax) );
    87        
     87
    8888        register_taxonomy( $tax, 'post', array('hierarchical'=>true) );
    8989        $this->assertTrue( is_taxonomy($tax) );
    90         $this->assertTrue( is_taxonomy_hierarchical($tax) );       
    91        
     90        $this->assertTrue( is_taxonomy_hierarchical($tax) );
     91
    9292        // clean up
    9393        unset($GLOBALS['wp_taxonomies'][$tax]);
     
    9797class TestTermAPI extends _WPEmptyBlog {
    9898    var $taxonomy = 'category';
    99    
     99
    100100    function setUp() {
    101101        parent::setUp();
     
    106106            wp_insert_term( $term, $tax );
    107107    }
    108    
     108
    109109    function test_wp_insert_delete_term() {
    110110        // a new unused term
    111111        $term = rand_str();
    112112        $this->assertNull( is_term($term) );
    113        
     113
    114114        $initial_count = wp_count_terms( $this->taxonomy );
    115        
     115
    116116        $t = wp_insert_term( $term, $this->taxonomy );
    117117        $this->assertTrue( is_array($t) );
     
    120120        $this->assertTrue( $t['term_taxonomy_id'] > 0 );
    121121        $this->assertEquals( $initial_count + 1, wp_count_terms($this->taxonomy) );
    122        
     122
    123123        // make sure the term exists
    124124        $this->assertTrue( is_term($term) > 0 );
    125125        $this->assertTrue( is_term($t['term_id']) > 0 );
    126        
     126
    127127        // now delete it
    128128        $this->assertTrue( wp_delete_term($t['term_id'], $this->taxonomy) );
     
    131131        $this->assertEquals( $initial_count, wp_count_terms($this->taxonomy) );
    132132    }
    133    
     133
    134134    function test_is_term_known() {
    135135        // insert a term
    136136        $term = rand_str();
    137137        $t = wp_insert_term( $term, $this->taxonomy );
    138        
     138
    139139        $this->assertEquals( $t['term_id'], is_term($t['term_id']) );
    140140        $this->assertEquals( $t['term_id'], is_term($term) );
    141        
     141
    142142        // clean up
    143143        $this->assertTrue( wp_delete_term($t['term_id'], $this->taxonomy) );
    144144    }
    145    
     145
    146146    function test_is_term_unknown() {
    147147        $this->assertNull( is_term(rand_str()) );
     
    150150        $this->assertEquals( 0, is_term(NULL) );
    151151    }
    152    
     152
    153153    function test_is_term_type() {
    154154        // insert a term
     
    163163        $this->assertTrue( wp_delete_term($t['term_id'], $this->taxonomy) );
    164164    }
    165    
     165
    166166    function test_set_object_terms_by_id() {
    167167        $this->_insert_quick_posts(5);
    168            
     168
    169169        $terms = array();
    170170        for ($i=0; $i<3; $i++ ) {
     
    173173            $term_id[$term] = $result['term_id'];
    174174        }
    175        
     175
    176176        foreach ($this->post_ids as $id) {
    177177                $tt = wp_set_object_terms( $id, array_values($term_id), $this->taxonomy );
     
    185185            $this->assertEquals( $this->post_ids, array_map('intval', $actual) );
    186186        }
    187        
     187
    188188        // each term should have a count of 5
    189189        foreach (array_keys($term_id) as $term) {
     
    192192        }
    193193    }
    194    
     194
    195195    function test_set_object_terms_by_name() {
    196196        $this->_insert_quick_posts(5);
    197            
     197
    198198        $terms = array(
    199199                rand_str(),
    200200                rand_str(),
    201201                rand_str());
    202                
     202
    203203        foreach ($this->post_ids as $id) {
    204204                $tt = wp_set_object_terms( $id, $terms, $this->taxonomy );
     
    217217            $this->assertEquals( $this->post_ids, array_map('intval', $actual) );
    218218        }
    219        
     219
    220220        // each term should have a count of 5
    221221        foreach ($terms as $term) {
     
    224224        }
    225225    }
    226    
     226
    227227    function test_change_object_terms_by_name() {
    228228        // set some terms on an object; then change them while leaving one intact
    229        
     229
    230230        $this->_insert_quick_posts(1);
    231231        $post_id = end($this->post_ids);
     
    233233        $terms_1 = array('foo', 'bar', 'baz');
    234234        $terms_2 = array('bar', 'bing');
    235        
     235
    236236        // set the initial terms
    237237        $tt_1 = wp_set_object_terms( $post_id, $terms_1, $this->taxonomy );
     
    241241        $terms = wp_get_object_terms($post_id, $this->taxonomy, array('fields' => 'names', 'orderby' => 't.term_id'));
    242242        $this->assertEquals( $terms_1, $terms );
    243        
     243
    244244        // change the terms
    245245        $tt_2 = wp_set_object_terms( $post_id, $terms_2, $this->taxonomy );
     
    249249        $terms = wp_get_object_terms($post_id, $this->taxonomy, array('fields' => 'names', 'orderby' => 't.term_id'));
    250250        $this->assertEquals( $terms_2, $terms );
    251        
     251
    252252        // make sure the tt id for 'bar' matches
    253253        $this->assertEquals( $tt_1[1], $tt_2[0] );
    254        
     254
    255255    }
    256256
    257257    function test_change_object_terms_by_id() {
    258258        // set some terms on an object; then change them while leaving one intact
    259        
     259
    260260        $this->_insert_quick_posts(1);
    261261        $post_id = end($this->post_ids);
     
    272272        $terms_2 = array();
    273273        $terms_2[0] = $terms_1[1];
    274        
     274
    275275        $term = rand_str();
    276276        $result = wp_insert_term( $term, $this->taxonomy );
    277277        $terms_2[1] = $result['term_id'];
    278278
    279        
     279
    280280        // set the initial terms
    281281        $tt_1 = wp_set_object_terms( $post_id, $terms_1, $this->taxonomy );
     
    285285        $terms = wp_get_object_terms($post_id, $this->taxonomy, array('fields' => 'ids', 'orderby' => 't.term_id'));
    286286        $this->assertEquals( $terms_1, $terms );
    287        
     287
    288288        // change the terms
    289289        $tt_2 = wp_set_object_terms( $post_id, $terms_2, $this->taxonomy );
     
    293293        $terms = wp_get_object_terms($post_id, $this->taxonomy, array('fields' => 'ids', 'orderby' => 't.term_id'));
    294294        $this->assertEquals( $terms_2, $terms );
    295        
     295
    296296        // make sure the tt id for 'bar' matches
    297297        $this->assertEquals( $tt_1[1], $tt_2[0] );
    298        
    299     }
    300    
     298
     299    }
     300
    301301    function test_set_object_terms_invalid() {
    302302        $this->_insert_quick_posts(1);
     
    307307        $this->assertTrue( is_wp_error($result) );
    308308    }
    309    
     309
    310310}
    311311
Note: See TracChangeset for help on using the changeset viewer.