Skip to:
Content

bbPress.org

Changeset 5677


Ignore:
Timestamp:
04/15/2015 04:31:15 AM (11 years ago)
Author:
netweb
Message:

Tests: Add PHPUnit factory's for topics and replies:

  • New class BBP_UnitTest_Factory_For_Topic for creating topics in PHPUnit tests
  • New class BBP_UnitTest_Factory_For_Reply for creating replies in PHPUnit tests
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/includes/factory.php

    r5673 r5677  
    44
    55    public $forum = null;
     6    public $topic = null;
     7    public $reply = null;
    68
    79    public function __construct() {
     
    911
    1012        $this->forum = new BBP_UnitTest_Factory_For_Forum( $this );
     13        $this->topic = new BBP_UnitTest_Factory_For_Topic( $this );
     14        $this->reply = new BBP_UnitTest_Factory_For_Reply( $this );
    1115    }
    1216}
     
    3640    }
    3741}
     42
     43class BBP_UnitTest_Factory_For_Topic extends WP_UnitTest_Factory_For_Thing {
     44
     45    public function __construct( $factory = null ) {
     46        parent::__construct( $factory );
     47
     48        $this->default_generation_definitions = array(
     49            'post_title'   => new WP_UnitTest_Generator_Sequence( 'Topic %s' ),
     50            'post_content' => new WP_UnitTest_Generator_Sequence( 'Content of Topic %s' ),
     51        );
     52    }
     53
     54    public function create_object( $args ) {
     55        return bbp_insert_topic( $args );
     56    }
     57
     58    public function update_object( $topic_id, $fields ) {
     59        $fields['topic_id'] = $topic_id;
     60        return bbp_update_topic( $fields );
     61    }
     62
     63    public function get_object_by_id( $topic_id ) {
     64        return bbp_get_topic( $topic_id );
     65    }
     66}
     67
     68class BBP_UnitTest_Factory_For_Reply extends WP_UnitTest_Factory_For_Thing {
     69
     70    public function __construct( $factory = null ) {
     71        parent::__construct( $factory );
     72
     73        $this->default_generation_definitions = array(
     74            'post_content' => new WP_UnitTest_Generator_Sequence( 'Content of Reply %s' ),
     75        );
     76    }
     77
     78    public function create_object( $args ) {
     79        return bbp_insert_reply( $args );
     80    }
     81
     82    public function update_object( $reply_id, $fields ) {
     83        $fields['reply_id'] = $reply_id;
     84        return bbp_update_reply( $fields );
     85    }
     86
     87    public function get_object_by_id( $reply_id ) {
     88        return bbp_get_reply( $reply_id );
     89    }
     90}
Note: See TracChangeset for help on using the changeset viewer.