Changeset 14035
- Timestamp:
- 10/02/2024 04:13:14 AM (19 months ago)
- Location:
- trunk
- Files:
-
- 4 edited
-
src/bp-messages/classes/class-bp-messages-rest-controller.php (modified) (2 diffs)
-
src/bp-messages/classes/class-bp-messages-thread.php (modified) (7 diffs)
-
tests/phpunit/testcases/members/test-controller.php (modified) (3 diffs)
-
tests/phpunit/testcases/messages/test-controller.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-messages/classes/class-bp-messages-rest-controller.php
r14026 r14035 340 340 */ 341 341 public function create_item( $request ) { 342 $create_args = $this->prepare_item_for_database( $request ); 343 344 // Let's return the original error if possible. 345 $create_args->error_type = 'wp_error'; 346 342 347 // Create the message or the reply. 343 $thread_id = messages_new_message( $ this->prepare_item_for_database( $request ));348 $thread_id = messages_new_message( $create_args ); 344 349 345 350 // Validate it created a Thread or was added to it. 346 if ( false === $thread_id) {351 if ( $thread_id instanceof WP_Error ) { 347 352 return new WP_Error( 348 353 'bp_rest_messages_create_failed', 349 __( 'There was an error trying to create the message.', 'buddypress' ), 350 array( 351 'status' => 500, 352 ) 354 $thread_id->get_error_message(), 355 array( 'status' => 500 ) 353 356 ); 354 357 } … … 780 783 } 781 784 782 if ( ! empty( $schema['properties']['message'] ) && ! empty( $request->get_param( 'message' ) ) ) { 785 if ( ! empty( $thread->message ) ) { 786 $prepared_thread->message = $thread->message; 787 } elseif ( ! empty( $schema['properties']['message'] ) ) { 783 788 $prepared_thread->content = $request->get_param( 'message' ); 784 } elseif ( ! empty( $thread->message ) ) {785 $prepared_thread->message = $thread->message;786 789 } 787 790 -
trunk/src/bp-messages/classes/class-bp-messages-thread.php
r13878 r14035 52 52 53 53 /** 54 * The user ID of the sender of the message thread. 55 * 56 * @since 1.2.0 57 * @var int 58 */ 59 public $sender_id; 60 61 /** 54 62 * The user IDs of all messages in the message thread. 55 63 * … … 119 127 * 120 128 * @since 1.0.0 121 * @since 10.0.0 Updated the `$args` with new par emeters.129 * @since 10.0.0 Updated the `$args` with new parameters. 122 130 * 123 131 * @param int $thread_id The message thread ID. … … 149 157 * 150 158 * @since 1.0.0 151 * @since 10.0.0 Updated the `$args` with new par emeters.159 * @since 10.0.0 Updated the `$args` with new parameters. 152 160 * 153 161 * @param int $thread_id The message thread ID. … … 518 526 519 527 $thread_id = (int) $thread_id; 520 $user_id = (int) $user_id;528 $user_id = (int) $user_id; 521 529 522 530 if ( empty( $user_id ) ) { … … 733 741 ); 734 742 735 $pag_sql = $type_sql = $search_sql = $user_id_sql = $sender_sql = '';743 $pag_sql = $type_sql = $search_sql = $user_id_sql = $sender_sql = ''; 736 744 $meta_query_sql = array( 737 745 'join' => '', … … 740 748 741 749 if ( $r['limit'] && $r['page'] ) { 742 $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $r['page'] - 1 ) * $r['limit'] ), intval( $r['limit'] ) );750 $pag_sql = $wpdb->prepare( ' LIMIT %d, %d', intval( ( $r['page'] - 1 ) * $r['limit'] ), intval( $r['limit'] ) ); 743 751 } 744 752 745 753 if ( $r['type'] == 'unread' ) { 746 $type_sql = " AND r.unread_count != 0 ";754 $type_sql = ' AND r.unread_count != 0 '; 747 755 } elseif ( $r['type'] == 'read' ) { 748 $type_sql = " AND r.unread_count = 0 ";756 $type_sql = ' AND r.unread_count = 0 '; 749 757 } 750 758 751 759 if ( ! empty( $r['search_terms'] ) ) { 752 760 $search_terms_like = '%' . bp_esc_like( $r['search_terms'] ) . '%'; 753 $search_sql = $wpdb->prepare( "AND ( subject LIKE %s OR message LIKE %s )", $search_terms_like, $search_terms_like );761 $search_sql = $wpdb->prepare( 'AND ( subject LIKE %s OR message LIKE %s )', $search_terms_like, $search_terms_like ); 754 762 } 755 763 … … 788 796 789 797 // Set up SQL array. 790 $sql = array();798 $sql = array(); 791 799 $sql['select'] = 'SELECT m.thread_id, MAX(m.date_sent) AS date_sent'; 792 800 $sql['from'] = "FROM {$bp->messages->table_name_recipients} r INNER JOIN {$bp->messages->table_name_messages} m ON m.thread_id = r.thread_id {$meta_query_sql['join']}"; -
trunk/tests/phpunit/testcases/members/test-controller.php
r14034 r14035 571 571 $this->assertTrue( bp_is_user_spammer( $u ) ); 572 572 573 wp_set_current_user( $u2 );573 $this->bp::set_current_user( $u2 ); 574 574 575 575 $request = new WP_REST_Request( 'GET', sprintf( $this->endpoint_url . '/%d', $u ) ); … … 591 591 $this->assertTrue( bp_is_user_spammer( $u ) ); 592 592 593 wp_set_current_user( $u );593 $this->bp::set_current_user( $u ); 594 594 595 595 $request = new WP_REST_Request( 'GET', sprintf( $this->endpoint_url . '/%d', $u ) ); … … 611 611 $this->assertTrue( bp_is_user_spammer( $u ) ); 612 612 613 wp_set_current_user( $this->user );613 $this->bp::set_current_user( $this->user ); 614 614 615 615 $request = new WP_REST_Request( 'GET', sprintf( $this->endpoint_url . '/%d', $u ) ); -
trunk/tests/phpunit/testcases/messages/test-controller.php
r14026 r14035 424 424 425 425 /** 426 * @dataProvider provider_create_item_with_empty_content_options 427 * 428 * @ticket BP9175 426 429 * @group create_item 427 430 */ 428 public function test_create_item_with_ no_content() {431 public function test_create_item_with_empty_content_options( $content ) { 429 432 $this->bp::set_current_user( $this->user ); 430 433 … … 435 438 'sender_id' => $this->user, 436 439 'recipients' => array( static::factory()->user->create() ), 437 'subject' => 'Foo', 440 'subject' => 'A new message', 441 'message' => $content, 442 ) 443 ); 444 445 $response = $this->server->dispatch( $request ); 446 447 $this->assertErrorResponse( 'bp_rest_messages_create_failed', $response, 500 ); 448 $this->assertSame( 'Your message was not sent. Please enter some content.', $response->get_data()['message'] ); 449 } 450 451 /** 452 * @ticket BP9175 453 * @group create_item 454 */ 455 public function test_create_item_with_null_content() { 456 $this->bp::set_current_user( $this->user ); 457 458 $request = new WP_REST_Request( 'POST', $this->endpoint_url ); 459 $request->set_param( 'context', 'edit' ); 460 $request->set_query_params( 461 array( 462 'sender_id' => $this->user, 463 'recipients' => array( static::factory()->user->create() ), 464 'subject' => 'A new message', 465 'message' => null, 438 466 ) 439 467 ); … … 447 475 448 476 /** 477 * @dataProvider provider_create_item_irregular_content_options 478 * 479 * @ticket BP9175 449 480 * @group create_item 450 481 */ 451 public function test_create_item_with_no_receipts() { 482 public function test_create_item_with_irregular_content_options( $content ) { 483 $this->bp::set_current_user( $this->user ); 484 485 $request = new WP_REST_Request( 'POST', $this->endpoint_url ); 486 $request->set_param( 'context', 'edit' ); 487 $request->set_query_params( 488 array( 489 'sender_id' => $this->user, 490 'recipients' => array( static::factory()->user->create() ), 491 'subject' => 'A new message', 492 'message' => $content, 493 ) 494 ); 495 496 $response = $this->server->dispatch( $request ); 497 498 $this->assertEquals( 200, $response->get_status() ); 499 } 500 501 /** 502 * Provider for the test_create_item_with_empty_content_options() test. 503 * 504 * @return array 505 */ 506 public function provider_create_item_with_empty_content_options() { 507 return array( 508 array( '' ), 509 array( '' ), 510 array( false ), 511 array( 0 ), // '0' is a valid message content. 512 array( array() ), 513 ); 514 } 515 516 /** 517 * Provider for the test_create_item_with_irregular_content_options() test. 518 * 519 * @return array 520 */ 521 public function provider_create_item_irregular_content_options() { 522 return array( 523 array( '0' ), 524 array( '00' ), 525 array( 'false' ), 526 ); 527 } 528 529 /** 530 * @group create_item 531 */ 532 public function test_create_item_with_no_recipients() { 452 533 $this->bp::set_current_user( $this->user ); 453 534
Note: See TracChangeset
for help on using the changeset viewer.