Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
10/19/2015 07:47:01 PM (11 years ago)
Author:
r-a-y
Message:

Messages: Return context-appropriate error messages for messages_new_message().

This commit introduces the error_type parameter in the
messages_new_message() function, which allows for us to return
descriptive error messages to the user when 'error_type' is set to
'wp_error'.

This most notably addresses an issue when entering an invalid username
when composing a new private message.

Commit also includes a unit test.

Fixes #6535.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/testcases/messages/functions.php

    r9819 r10286  
    4242        }
    4343
     44        /**
     45         * @group messages_new_message
     46         */
     47        public function test_messages_new_message_invalid_recipient_error_message() {
     48                $u1 = $this->factory->user->create();
     49
     50                // attempt to send a private message to an invalid username
     51                $t1 = messages_new_message( array(
     52                        'sender_id'  => $u1,
     53                        'recipients' => array( 'homerglumpkin' ),
     54                        'subject'    => 'A new message',
     55                        'content'    => 'Hey there!',
     56                        'error_type' => 'wp_error'
     57                ) );
     58
     59                $this->assertSame( 'Message could not be sent because you have entered an invalid username. Please try again.', $t1->get_error_message() );
     60        }
    4461}
Note: See TracChangeset for help on using the changeset viewer.