Skip to content

Commit 4e8a1a7

Browse files
committed
Tests: Reject unsupported site export requests.
Replace empty REST test stubs with assertions that item paths and write methods return `rest_no_route` for the site export controller. Developed in: #14115 Props shailu25. See #66073. git-svn-id: https://develop.svn.wordpress.org/trunk@64275 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 7148cd9 commit 4e8a1a7

1 file changed

Lines changed: 71 additions & 8 deletions

File tree

‎tests/phpunit/tests/rest-api/wpRestEditSiteExportController.php‎

Lines changed: 71 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@ class Tests_REST_WpRestEditSiteExportController extends WP_Test_REST_Controller_
2121
*/
2222
const REQUEST_ROUTE = '/wp-block-editor/v1/export';
2323

24+
/**
25+
* Administrator user ID.
26+
*
27+
* @since 5.9.0
28+
*
29+
* @var int
30+
*/
31+
protected static $admin_id;
32+
2433
/**
2534
* Subscriber user ID.
2635
*
@@ -38,6 +47,11 @@ class Tests_REST_WpRestEditSiteExportController extends WP_Test_REST_Controller_
3847
* @param WP_UnitTest_Factory $factory WordPress unit test factory.
3948
*/
4049
public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
50+
self::$admin_id = $factory->user->create(
51+
array(
52+
'role' => 'administrator',
53+
)
54+
);
4155
self::$subscriber_id = $factory->user->create(
4256
array(
4357
'role' => 'subscriber',
@@ -51,6 +65,7 @@ public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
5165
* @since 5.9.0
5266
*/
5367
public static function wpTearDownAfterClass() {
68+
self::delete_user( self::$admin_id );
5469
self::delete_user( self::$subscriber_id );
5570
}
5671

@@ -110,38 +125,86 @@ public function test_context_param() {
110125
}
111126

112127
/**
113-
* @doesNotPerformAssertions
128+
* Edit Site Export has no item route.
129+
*
130+
* @ticket 66073
114131
*/
115132
public function test_get_item() {
116-
// Controller does not implement get_item().
133+
wp_set_current_user( self::$admin_id );
134+
135+
$request = new WP_REST_Request( 'GET', static::REQUEST_ROUTE . '/example' );
136+
$response = rest_get_server()->dispatch( $request );
137+
138+
$this->assertErrorResponse( 'rest_no_route', $response, 404 );
117139
}
118140

119141
/**
142+
* Edit Site Export has no collection list operation; GET on the export route downloads a ZIP.
143+
*
120144
* @doesNotPerformAssertions
121145
*/
122146
public function test_get_items() {
123147
// Controller does not implement get_items().
124148
}
125149

126150
/**
127-
* @doesNotPerformAssertions
151+
* Edit Site Export is read-only; create requests should not match a route.
152+
*
153+
* @ticket 66073
128154
*/
129155
public function test_create_item() {
130-
// Controller does not implement create_item().
156+
wp_set_current_user( self::$admin_id );
157+
158+
$request = new WP_REST_Request( 'POST', static::REQUEST_ROUTE );
159+
$response = rest_get_server()->dispatch( $request );
160+
161+
$this->assertErrorResponse( 'rest_no_route', $response, 404 );
131162
}
132163

133164
/**
134-
* @doesNotPerformAssertions
165+
* Edit Site Export is read-only; update requests should not match a route.
166+
*
167+
* Uses OPTIONS (not GET) to prove the route exists, because a successful GET
168+
* triggers the ZIP export and exits the request.
169+
*
170+
* @ticket 66073
135171
*/
136172
public function test_update_item() {
137-
// Controller does not implement update_item().
173+
wp_set_current_user( self::$admin_id );
174+
175+
$route = static::REQUEST_ROUTE;
176+
177+
$response = rest_get_server()->dispatch( new WP_REST_Request( 'OPTIONS', $route ) );
178+
$this->assertSame( 200, $response->get_status() );
179+
180+
foreach ( array( 'POST', 'PUT', 'PATCH' ) as $method ) {
181+
$request = new WP_REST_Request( $method, $route );
182+
$response = rest_get_server()->dispatch( $request );
183+
184+
$this->assertErrorResponse( 'rest_no_route', $response, 404 );
185+
}
138186
}
139187

140188
/**
141-
* @doesNotPerformAssertions
189+
* Edit Site Export is read-only; delete requests should not match a route.
190+
*
191+
* Uses OPTIONS (not GET) to prove the route exists, because a successful GET
192+
* triggers the ZIP export and exits the request.
193+
*
194+
* @ticket 66073
142195
*/
143196
public function test_delete_item() {
144-
// Controller does not implement delete_item().
197+
wp_set_current_user( self::$admin_id );
198+
199+
$route = static::REQUEST_ROUTE;
200+
201+
$response = rest_get_server()->dispatch( new WP_REST_Request( 'OPTIONS', $route ) );
202+
$this->assertSame( 200, $response->get_status() );
203+
204+
$request = new WP_REST_Request( 'DELETE', $route );
205+
$response = rest_get_server()->dispatch( $request );
206+
207+
$this->assertErrorResponse( 'rest_no_route', $response, 404 );
145208
}
146209

147210
/**

0 commit comments

Comments
 (0)