Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
09/06/2016 03:31:21 AM (5 years ago)
Author:
boonebgorges
Message:

Tests: Add Friendship factory.

Props jdgrimes.
Fixes #7243.

File:
1 edited

Legend:

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

    r11042 r11063  
    1414        $this->notification = new BP_UnitTest_Factory_For_Notification( $this );
    1515        $this->signup = new BP_UnitTest_Factory_For_Signup( $this );
     16        $this->friendship = new BP_UnitTest_Factory_For_Friendship( $this );
    1617    }
    1718}
     
    269270    }
    270271}
     272
     273/**
     274 * Factory for friendships.
     275 *
     276 * @since 2.7.0
     277 */
     278class BP_UnitTest_Factory_For_Friendship extends WP_UnitTest_Factory_For_Thing {
     279    /**
     280     * Constructor.
     281     *
     282     * @since 2.7.0
     283     *
     284     * @param $factory WP_UnitTest_Factory
     285     */
     286    public function __construct( $factory = null ) {
     287        parent::__construct( $factory );
     288    }
     289
     290    /**
     291     * Create friendship object.
     292     *
     293     * @since 2.7.0
     294     *
     295     * @param array $args Array of arguments.
     296     * @return int Friendship ID.
     297     */
     298    public function create_object( $args ) {
     299        $friendship = new BP_Friends_Friendship();
     300
     301        foreach ( array( 'initiator_user_id', 'friend_user_id' ) as $arg ) {
     302            if ( isset( $args[ $arg ] ) ) {
     303                $friendship->$arg = $args[ $arg ];
     304            } else {
     305                $friendship->$arg = $this->factory->user->create();
     306            }
     307        }
     308
     309        foreach ( array( 'is_confirmed', 'is_limited', 'date_created' ) as $arg ) {
     310            if ( isset( $args[ $arg ] ) ) {
     311                $friendship->$arg = $args[ $arg ];
     312            }
     313        }
     314
     315        $friendship->save();
     316
     317        return $friendship->id;
     318    }
     319
     320    /**
     321     * Update a friendship object.
     322     *
     323     * @since 2.7.0
     324     *
     325     * @todo Implement.
     326     *
     327     * @param int   $id     ID of the friendship.
     328     * @param array $fields Fields to update.
     329     */
     330    public function update_object( $id, $fields ) {}
     331
     332    /**
     333     * Get a friendship object by its ID.
     334     *
     335     * @since 2.7.0
     336     *
     337     * @param int $id
     338     * @return BP_Friends_Friendship
     339     */
     340    public function get_object_by_id( $id ) {
     341        return new BP_Friends_Friendship( $id );
     342    }
     343}
Note: See TracChangeset for help on using the changeset viewer.