WordPress.org

Make WordPress Core

Changeset 848 in tests


Ignore:
Timestamp:
07/02/12 06:15:14 (22 months ago)
Author:
nacin
Message:

Add factory for terms. see #66. see #44.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-testlib/factory.php

    r838 r848  
    66        $this->comment = new WP_UnitTest_Factory_For_Comment( $this ); 
    77        $this->user = new WP_UnitTest_Factory_For_User( $this ); 
     8        $this->term = new WP_UnitTest_Factory_For_Term( $this ); 
    89        if ( is_multisite() ) 
    910            $this->blog = new WP_UnitTest_Factory_For_Blog( $this ); 
     
    101102 
    102103    function update_object( $blog_id, $fields ) {} 
     104} 
     105 
     106 
     107class WP_UnitTest_Factory_For_Term extends WP_UnitTest_Factory_For_Thing { 
     108 
     109    function __construct( $factory = null ) { 
     110        parent::__construct( $factory ); 
     111        $this->default_generation_definitions = array( 
     112            'name' => new WP_UnitTest_Generator_Sequence( 'Term %s' ), 
     113            'taxonomy' => 'post_tag', 
     114            'description' => new WP_UnitTest_Generator_Sequence( 'Term description %s' ), 
     115        ); 
     116    } 
     117 
     118    function create_object( $args ) { 
     119        $term_id_pair = wp_insert_term( $args['name'], $args['taxonomy'], $args ); 
     120        return $term_id_pair['term_id']; 
     121    } 
     122 
     123    function update_object( $term, $fields ) { 
     124        if ( is_object( $term ) ) 
     125            $taxonomy = $term->taxonomy; 
     126        elseif ( isset( $fields['taxonomy'] ) ) 
     127            $taxonomy = $fields['taxonomy']; 
     128        else 
     129            $taxonomy = 'post_tag'; 
     130        $term_id_pair = wp_update_term( $term, $taxonomy, $fields ); 
     131        return $term_id_pair['term_id']; 
     132    } 
    103133} 
    104134 
Note: See TracChangeset for help on using the changeset viewer.