Skip to content

Commit

Permalink
XProfile field: test apostrophes is handled correctly in field update
Browse files Browse the repository at this point in the history
  • Loading branch information
renatonascalves committed Apr 8, 2024
1 parent 4bb1a70 commit 3cbe838
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions tests/testcases/xprofile/test-data-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,49 @@ public function test_update_textbox() {
$this->assertEquals( $data[0]['value']['raw'], 'textbox field' );
}

/**
* @group update_item
*
* @ticket https://buddypress.trac.wordpress.org/ticket/9127
*/
public function test_update_textbox_with_apostrophe_value() {
$field_id = $this->bp_factory->xprofile_field->create(
[
'type' => 'textbox',
'field_group_id' => $this->group_id,
'value' => 'textbox field',
]
);

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

$request = new WP_REST_Request( 'POST', sprintf( $this->endpoint_url . '%d/data/%d', $field_id, $this->user ) );
$request->add_header( 'content-type', 'application/json' );

$params = $this->set_field_data( [ 'value' => "I don't travel often" ] );
$request->set_param( 'context', 'edit' );
$request->set_body( wp_json_encode( $params ) );
$response = $this->server->dispatch( $request );

$data = $response->get_data();

$this->assertNotEmpty( $data );
$this->assertEquals( $data[0]['value']['raw'], "I don't travel often" );

$request = new WP_REST_Request( 'POST', sprintf( $this->endpoint_url . '%d/data/%d', $field_id, $this->user ) );
$request->add_header( 'content-type', 'application/json' );

$params = $this->set_field_data( [ 'value' => "I don\\'t travel often" ] );
$request->set_param( 'context', 'edit' );
$request->set_body( wp_json_encode( $params ) );
$response = $this->server->dispatch( $request );

$data = $response->get_data();

$this->assertNotEmpty( $data );
$this->assertEquals( $data[0]['value']['raw'], "I don't travel often" );
}

/**
* @group update_item
*/
Expand Down

0 comments on commit 3cbe838

Please sign in to comment.