Skip to:
Content

BuddyPress.org

Changeset 11042


Ignore:
Timestamp:
08/30/2016 03:44:33 PM (8 years ago)
Author:
boonebgorges
Message:

Tests: Fix message factory create/get methods.

Previously, message creation was failing because no 'sender_id' or
'recipients' were set. We now create senders and recipients when none
are passed to the create() method.

This changeset also fixes the return value of create_object(), so that
create_and_get() works for messages.

Props jdgrimes.
Fixes #7234.

Location:
trunk/tests/phpunit
Files:
2 added
1 edited

Legend:

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

    r10004 r11042  
    158158            'sender_id'  => get_current_user_id(),
    159159            'thread_id'  => 0,
    160             'recipients' => array(),
    161160            'subject'    => new WP_UnitTest_Generator_Sequence( 'Message subject %s' ),
    162161            'content'    => new WP_UnitTest_Generator_Sequence( 'Message content %s' ),
     
    166165
    167166    function create_object( $args ) {
    168         $message_id = messages_new_message( $args );
    169         return $message_id;
    170     }
    171 
    172     function update_object( $group_id, $fields ) {
     167        if ( empty( $args['sender_id'] ) ) {
     168            $args['sender_id'] = $this->factory->user->create();
     169        }
     170
     171        if ( empty( $args['recipients'] ) ) {
     172            $recipient = $this->factory->user->create_and_get();
     173            $args['recipients'] = array( $recipient->user_nicename );
     174        }
     175
     176        $thread_id = messages_new_message( $args );
     177        $thread = new BP_Messages_Thread( $thread_id );
     178        return end( $thread->messages )->id;
     179    }
     180
     181    function update_object( $message_id, $fields ) {
    173182        // todo
    174183    }
    175184
    176     function get_object_by_id( $group_id ) {
    177         // todo
     185    function get_object_by_id( $message_id ) {
     186        return new BP_Messages_Message( $message_id );
    178187    }
    179188}
Note: See TracChangeset for help on using the changeset viewer.