Make WordPress Core

Changeset 107 in tests


Ignore:
Timestamp:
12/04/2007 06:12:03 AM (15 years ago)
Author:
tellyworth
Message:

more taxonomy test fixes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wp-testcase/test_includes_taxonomy.php

    r106 r107  
    9494class TestTermAPI extends _WPEmptyBlog {
    9595    var $taxonomy = 'category';
     96   
     97    function setUp() {
     98        parent::setUp();
     99        // insert one term into every post taxonomy
     100        // otherwise term_ids and term_taxonomy_ids might be identical, which could mask bugs
     101        $term = rand_str();
     102        foreach(get_object_taxonomies('post') as $tax)
     103            wp_insert_term( $term, $tax );
     104    }
    96105   
    97106    function test_wp_insert_delete_term() {
     
    158167            $term = rand_str();
    159168            $result = wp_insert_term( $term, $this->taxonomy );
    160             $tax_id[$term] = $result['term_taxonomy_id'];
    161169            $term_id[$term] = $result['term_id'];
    162170        }
    163171       
    164172        foreach ($this->post_ids as $id) {
    165                 $tt = wp_set_object_terms( $id, array_values($tax_id), $this->taxonomy );
     173                $tt = wp_set_object_terms( $id, array_values($term_id), $this->taxonomy );
    166174                // should return three term taxonomy ids
    167175                $this->assertEquals( 3, count($tt) );
     
    169177
    170178        // each term should be associated with every post
    171         foreach (array_values($term_id) as $term) {
    172             $actual = get_objects_in_term($term, $this->taxonomy);
    173             $this->assertEquals( $this->post_ids, $actual );
     179        foreach ($term_id as $term=>$id) {
     180            $actual = get_objects_in_term($id, $this->taxonomy);
     181            $this->assertEquals( $this->post_ids, array_map('intval', $actual) );
    174182        }
    175183       
     
    193201                // should return three term taxonomy ids
    194202                $this->assertEquals( 3, count($tt) );
    195                 // remember which term has which tax_id
    196                 for ($i=0; $i<3; $i++)
    197                     $tax_id[$terms[$i]] = intval($tt[$i]);
     203                // remember which term has which term_id
     204                for ($i=0; $i<3; $i++) {
     205                    $term = get_term_by('name', $terms[$i], $this->taxonomy);
     206                    $term_id[$terms[$i]] = intval($term->term_id);
     207                }
    198208        }
    199209
    200210        // each term should be associated with every post
    201         foreach ($tax_id as $term=>$id) {
     211        foreach ($term_id as $term=>$id) {
    202212            $actual = get_objects_in_term($id, $this->taxonomy);
    203213            $this->assertEquals( $this->post_ids, array_map('intval', $actual) );
Note: See TracChangeset for help on using the changeset viewer.