WordPress.org

Make WordPress Core

Changeset 952 in tests


Ignore:
Timestamp:
08/06/12 01:40:04 (2 years ago)
Author:
nbachiyski
Message:

Introduce a category factory

Accomodate the term taxonomy, but set the default taxonomy on construct

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/includes/factory.php

    r950 r952  
    77        $this->user = new WP_UnitTest_Factory_For_User( $this ); 
    88        $this->term = new WP_UnitTest_Factory_For_Term( $this ); 
     9        $this->category = new WP_UnitTest_Factory_For_Term( $this, 'category' ); 
    910        if ( is_multisite() ) 
    1011            $this->blog = new WP_UnitTest_Factory_For_Blog( $this ); 
     
    123124class WP_UnitTest_Factory_For_Term extends WP_UnitTest_Factory_For_Thing { 
    124125 
    125     function __construct( $factory = null ) { 
    126         parent::__construct( $factory ); 
     126    private $taxonomy; 
     127    const DEFAULT_TAXONOMY = 'post_tag'; 
     128 
     129    function __construct( $factory = null, $taxonomy = null ) { 
     130        parent::__construct( $factory ); 
     131        $this->taxonomy = $taxonomy?: self::DEFAULT_TAXONOMY; 
    127132        $this->default_generation_definitions = array( 
    128133            'name' => new WP_UnitTest_Generator_Sequence( 'Term %s' ), 
    129             'taxonomy' => 'post_tag', 
     134            'taxonomy' => $this->taxonomy, 
    130135            'description' => new WP_UnitTest_Generator_Sequence( 'Term description %s' ), 
    131136        ); 
     
    133138 
    134139    function create_object( $args ) { 
     140        $args = array_merge( array( 'taxonomy' => $this->taxonomy ), $args ); 
    135141        $term_id_pair = wp_insert_term( $args['name'], $args['taxonomy'], $args ); 
    136142        if ( is_wp_error( $term_id_pair ) ) 
     
    140146 
    141147    function update_object( $term, $fields ) { 
     148        $fields = array_merge( array( 'taxonomy' => $this->taxonomy ), $fields ); 
    142149        if ( is_object( $term ) ) 
    143150            $taxonomy = $term->taxonomy; 
    144         elseif ( isset( $fields['taxonomy'] ) ) 
    145             $taxonomy = $fields['taxonomy']; 
    146         else 
    147             $taxonomy = 'post_tag'; 
    148151        $term_id_pair = wp_update_term( $term, $taxonomy, $fields ); 
    149152        return $term_id_pair['term_id']; 
     
    155158 
    156159    function get_object_by_id( $term_id ) { 
    157         return get_term( $term_id ); 
     160        return get_term_by( 'id', $term_id, $this->taxonomy ); 
    158161    } 
    159162} 
Note: See TracChangeset for help on using the changeset viewer.