Skip to content

Commit

Permalink
[Sitebars endpoint] Add tests for slashing behavior (WordPress#24785)
Browse files Browse the repository at this point in the history
* Add test for slashing behavior

* Lint

* Update tests

* Update tests

* Replace > with >

* Remove >
  • Loading branch information
adamziel authored Aug 27, 2020
1 parent 4b28ce9 commit 25f9e09
Showing 1 changed file with 54 additions and 1 deletion.
55 changes: 54 additions & 1 deletion phpunit/class-rest-sidebars-controller-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,60 @@ public function test_update_item_wrong_permission_subscriber() {
$this->assertErrorResponse( 'widgets_cannot_access', $response, 403 );
}

/**
* Tests if the endpoint correctly handles "slashable" characters such as " or '.
*/
public function test_update_item_slashing() {
$this->setup_widget( 'widget_text', 1, array( 'text' => 'Custom text test' ) );
$this->setup_sidebar( 'sidebar-1', array( 'name' => 'Test sidebar' ), array( 'text-1', 'rss-1' ) );

$request = new WP_REST_Request( 'POST', '/__experimental/sidebars/sidebar-1' );
$request->set_body_params(
array(
'widgets' => array(
array(
'id' => 'text-1',
'settings' => array(
'text' => 'Updated \\" \\\' text test',
),
'id_base' => 'text',
'widget_class' => 'WP_Widget_Text',
'name' => 'Text',
'description' => 'Arbitrary text.',
'number' => 1,
),
),
)
);
$response = rest_get_server()->dispatch( $request );
$data = $response->get_data();
$this->assertEquals(
array(
'id' => 'sidebar-1',
'name' => 'Test sidebar',
'description' => '',
'status' => 'active',
'widgets' => array(
array(
'id' => 'text-1',
'settings' => array(
'text' => 'Updated \\" \\\' text test',
'title' => '',
'filter' => false,
),
'id_base' => 'text',
'widget_class' => 'WP_Widget_Text',
'name' => 'Text',
'description' => 'Arbitrary text.',
'number' => 1,
'rendered' => '<div class="textwidget">Updated \\" \\\' text test</div>',
),
),
),
$data
);
}

/**
* The test_delete_item() method does not exist for sidebar.
*/
Expand Down Expand Up @@ -708,5 +762,4 @@ public function test_get_item_schema() {
$this->assertArrayHasKey( 'status', $properties );
$this->assertArrayHasKey( 'widgets', $properties );
}

}

0 comments on commit 25f9e09

Please sign in to comment.