Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BP9170: "raw" property missing from subject/excerpt/message nodes #510

Merged
merged 2 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -868,8 +868,9 @@ public function prepare_message_for_response( $message, $request ) {
$data['is_starred'] = bp_messages_is_message_starred( $data['id'], $user_id );
}

// Add REST Fields (BP Messages meta) data.
$data = $this->add_additional_fields_to_object( $data, $request );
$context = ! empty( $request->get_param( 'context' ) ) ? $request->get_param( 'context' ) : 'view';
$data = $this->add_additional_fields_to_object( $data, $request );
$data = $this->filter_response_by_context( $data, $context );

/**
* Filter a message value returned from the API.
Expand Down
58 changes: 56 additions & 2 deletions tests/testcases/messages/test-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,64 @@ public function test_get_item_admin_access() {
$this->assertEquals( 200, $response->get_status() );

$all_data = $response->get_data();
$this->assertNotEmpty( $all_data );

$data = current( $all_data );
$this->check_thread_data( $this->endpoint->get_thread_object( $data['id'], $u2 ), $data );

$this->assertFalse( isset( $data['message']['raw'] ) );
$this->assertFalse( isset( $data['excerpt']['raw'] ) );
$this->assertFalse( isset( $data['subject']['raw'] ) );
$this->assertSame( 'Foo', $data['subject']['rendered'] );

$message = $data['messages'][0];

$this->assertSame( $m->id, $message['id'] );
$this->assertFalse( isset( $message['message']['raw'] ) );
$this->assertFalse( isset( $message['subject']['raw'] ) );

$this->assertTrue( isset( $message['message']['rendered'] ) );
$this->assertTrue( isset( $message['subject']['rendered'] ) );
}

/**
* @group get_item
*/
public function test_get_item_with_edit_context() {
$u1 = static::factory()->user->create();
$u2 = static::factory()->user->create();
$m = $this->bp::factory()->message->create_and_get( array(
'sender_id' => $u1,
'recipients' => array( $u2 ),
'subject' => 'Foo',
) );

$this->bp::set_current_user( $this->user );

$request = new WP_REST_Request( 'GET', $this->endpoint_url . '/' . $m->thread_id );

$request->set_param( 'context', 'edit' );
$request->set_param( 'user_id', $u2 );
$response = $this->server->dispatch( $request );

$this->assertEquals( 200, $response->get_status() );

$all_data = $response->get_data();

$data = current( $all_data );

$this->assertTrue( isset( $data['message']['raw'] ) );
$this->assertTrue( isset( $data['excerpt']['raw'] ) );
$this->assertTrue( isset( $data['subject']['raw'] ) );
$this->assertSame( 'Foo', $data['subject']['raw'] );

$message = $data['messages'][0];

$this->assertSame( $m->id, $message['id'] );
$this->assertTrue( isset( $message['message']['raw'] ) );
$this->assertTrue( isset( $message['subject']['raw'] ) );

$this->assertTrue( isset( $message['message']['rendered'] ) );
$this->assertTrue( isset( $message['subject']['rendered'] ) );
$this->assertSame( 'Foo', $message['subject']['raw'] );
}

/**
Expand Down