Changeset 13986
- Timestamp:
- 07/27/2024 07:16:17 PM (11 months ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-messages/bp-messages-functions.php
r13890 r13986 57 57 ); 58 58 59 // Check if the message content is empty. 60 $content = $r['content']; 61 $empty_content = false; 62 63 // Any string is considered non-empty. 64 if ( ! is_string( $content ) || '' === $content ) { 65 $empty_content = true; 66 } 67 59 68 // Bail if no sender or no content. 60 if ( empty( $r['sender_id'] ) || empty( $r['content'] )) {69 if ( empty( $r['sender_id'] ) || $empty_content ) { 61 70 if ( 'wp_error' === $r['error_type'] ) { 62 71 if ( empty( $r['sender_id'] ) ) { … … 69 78 70 79 return new WP_Error( $error_code, $feedback ); 71 72 } else { 73 return false; 74 } 80 } 81 82 return false; 75 83 } 76 84 -
trunk/tests/phpunit/testcases/messages/functions.php
r13980 r13986 27 27 28 28 // send another message and get recheck unread count 29 $t2 =messages_new_message( array(29 messages_new_message( array( 30 30 'sender_id' => $u1, 31 31 'recipients' => array( $u2 ), … … 40 40 // recheck unread count 41 41 $this->assertEquals( 1, messages_get_unread_count( $u2 ) ); 42 } 43 44 /** 45 * @dataProvider provider_new_message_empty_content_options 46 * 47 * @ticket BP9175 48 * @group messages_new_message 49 */ 50 public function test_messages_new_message_empty_content( $content ) { 51 $t1 = messages_new_message( 52 array( 53 'sender_id' => self::factory()->user->create(), 54 'recipients' => array( self::factory()->user->create() ), 55 'subject' => 'A new message', 56 'content' => $content, 57 'error_type' => 'wp_error' 58 ) 59 ); 60 61 $this->assertSame( 62 'Your message was not sent. Please enter some content.', 63 $t1->get_error_message() 64 ); 65 } 66 67 /** 68 * @dataProvider provider_new_message_irregular_content_options 69 * 70 * @ticket BP9175 71 * @group messages_new_message 72 */ 73 public function test_messages_new_message_irregular_content( $content ) { 74 $t1 = messages_new_message( array( 75 'sender_id' => self::factory()->user->create(), 76 'recipients' => array( self::factory()->user->create() ), 77 'subject' => 'A new message', 78 'content' => $content, 79 'error_type' => 'wp_error' 80 ) ); 81 82 $this->assertTrue( is_int( $t1 ) ); 83 } 84 85 /** 86 * Provider for the test_messages_new_message_irregular_content_options() test. 87 * 88 * @return array 89 */ 90 public function provider_new_message_irregular_content_options() { 91 return array( 92 array( '0' ), 93 array( '00' ), 94 array( 'false' ), 95 ); 96 } 97 98 /** 99 * Provider for the test_messages_new_message_empty_content() test. 100 * 101 * @return array 102 */ 103 public function provider_new_message_empty_content_options() { 104 return array( 105 array( '' ), 106 array( "" ), 107 array( null ), 108 array( false ), 109 array( 0 ), // '0' is a valid message content. 110 array( array() ), 111 array( new stdClass() ), 112 ); 42 113 } 43 114
Note: See TracChangeset
for help on using the changeset viewer.