WordPress.org

Make WordPress Core

Changeset 922 in tests


Ignore:
Timestamp:
07/19/12 16:31:22 (21 months ago)
Author:
ryan
Message:

Don't fatal when wp_insert_term() returns WP_Error. Props kurtpayne. fixes #107

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/includes/factory.php

    r883 r922  
    118118    function create_object( $args ) { 
    119119        $term_id_pair = wp_insert_term( $args['name'], $args['taxonomy'], $args ); 
     120        if ( is_wp_error( $term_id_pair ) ) 
     121            return $term_id_pair; 
    120122        return $term_id_pair['term_id']; 
    121123    } 
  • trunk/tests/term.php

    r909 r922  
    2424 
    2525        $t = wp_insert_term( $term, $this->taxonomy ); 
    26         $this->assertTrue( is_array($t) ); 
     26        $this->assertInternalType( 'array', $t ); 
    2727        $this->assertFalse( is_wp_error($t) ); 
    2828        $this->assertTrue( $t['term_id'] > 0 ); 
     
    4545        $term = rand_str(); 
    4646        $t = wp_insert_term( $term, $this->taxonomy ); 
    47  
     47        $this->assertInternalType( 'array', $t ); 
    4848        $this->assertEquals( $t['term_id'], term_exists($t['term_id']) ); 
    4949        $this->assertEquals( $t['term_id'], term_exists($term) ); 
     
    6767        $term = rand_str(); 
    6868        $t = wp_insert_term( $term, $this->taxonomy ); 
    69  
     69        $this->assertInternalType( 'array', $t ); 
    7070        $term_obj = get_term_by('name', $term, $this->taxonomy); 
    7171        $this->assertEquals( $t['term_id'], term_exists($term_obj->slug) ); 
     
    8282            $term = rand_str(); 
    8383            $result = wp_insert_term( $term, $this->taxonomy ); 
     84            $this->assertInternalType( 'array', $result ); 
    8485            $term_id[$term] = $result['term_id']; 
    8586        } 
     
    175176            $term = rand_str(); 
    176177            $result = wp_insert_term( $term, $this->taxonomy ); 
     178            $this->assertInternalType( 'array', $result ); 
    177179            $terms_1[$i] = $result['term_id']; 
    178180        } 
     
    236238 
    237239        $t = wp_insert_term( $term, 'category' ); 
     240        $this->assertInternalType( 'array', $t ); 
    238241        $t2 = wp_insert_term( $term, 'category', array( 'parent' => $t['term_id'] ) ); 
     242        $this->assertInternalType( 'array', $t2 ); 
    239243        if ( function_exists( 'term_is_ancestor_of' ) ) { 
    240244            $this->assertTrue( term_is_ancestor_of( $t['term_id'], $t2['term_id'], 'category' ) ); 
     
    274278        // set up test data 
    275279        $a = wp_insert_term( 'parent', $this->taxonomy ); 
     280        $this->assertInternalType( 'array', $a ); 
    276281        $b = wp_insert_term( 'child',  $this->taxonomy, array( 'parent' => $a['term_id'] ) ); 
     282        $this->assertInternalType( 'array', $b ); 
    277283        $c = wp_insert_term( 'neighbor', $this->taxonomy ); 
     284        $this->assertInternalType( 'array', $c ); 
    278285        $d = wp_insert_term( 'pet',  $this->taxonomy, array( 'parent' => $c['term_id'] )  ); 
     286        $this->assertInternalType( 'array', $c ); 
    279287 
    280288        $a_term = get_term( $a['term_id'], $this->taxonomy ); 
  • trunk/tests/xmlrpc/wp/deleteTerm.php

    r904 r922  
    1111 
    1212        $this->term = wp_insert_term( 'term' . rand_str() , 'category' ); 
     13        $this->assertInternalType( 'array', $this->term ); 
    1314    } 
    1415 
  • trunk/tests/xmlrpc/wp/editTerm.php

    r904 r922  
    1313 
    1414        $this->parent_term = wp_insert_term( 'parent' . rand_str() , 'category' ); 
     15        $this->assertInternalType( 'array', $this->parent_term ); 
    1516        $this->child_term = wp_insert_term( 'child' . rand_str() , 'category' ); 
     17        $this->assertInternalType( 'array', $this->child_term ); 
    1618        $this->post_tag = wp_insert_term( 'test' . rand_str() , 'post_tag' ); 
     19        $this->assertInternalType( 'array', $this->post_tag ); 
    1720    } 
    1821 
  • trunk/tests/xmlrpc/wp/getTerm.php

    r904 r922  
    1111 
    1212        $this->term = wp_insert_term( 'term' . rand_str() , 'category' ); 
     13        $this->assertInternalType( 'array', $this->term ); 
    1314    } 
    1415 
  • trunk/tests/xmlrpc/wp/newPost.php

    r904 r922  
    245245 
    246246        $tag1 = wp_create_tag ( rand_str( 30 ) ); 
     247        $this->assertInternalType( 'array', $tag1 ); 
    247248        $tag2 = wp_create_tag ( rand_str( 30 ) ); 
     249        $this->assertInternalType( 'array', $tag2 ); 
    248250        $tag3 = wp_create_tag ( rand_str( 30 ) ); 
     251        $this->assertInternalType( 'array', $tag3 ); 
    249252 
    250253        $post = array( 
  • trunk/tests/xmlrpc/wp/newTerm.php

    r904 r922  
    1111 
    1212        $this->parent_term = wp_insert_term( 'parent' . rand_str(), 'category' ); 
     13        $this->assertInternalType( 'array', $this->parent_term ); 
    1314        $this->parent_term = $this->parent_term['term_id']; 
    1415    } 
Note: See TracChangeset for help on using the changeset viewer.