Skip to content

Commit f7616f3

Browse files
committed
Tests: Assert unsupported pattern directory requests.
Replace empty `@doesNotPerformAssertions` stubs with checks that unsupported item and write requests return `rest_no_route` with status `404`. Use an authenticated contributor so permission errors cannot satisfy the assertions. Developed in: WordPress#13950 Props shailu25. See #66073. git-svn-id: https://develop.svn.wordpress.org/trunk@64076 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 2591f87 commit f7616f3

1 file changed

Lines changed: 40 additions & 8 deletions

File tree

‎tests/phpunit/tests/rest-api/rest-pattern-directory-controller.php‎

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -579,31 +579,63 @@ public function data_get_items_query_args() {
579579
}
580580

581581
/**
582-
* @doesNotPerformAssertions
582+
* Pattern directory has no item route.
583+
*
584+
* @ticket 66073
583585
*/
584586
public function test_get_item() {
585-
// Controller does not implement get_item().
587+
wp_set_current_user( self::$contributor_id );
588+
589+
$request = new WP_REST_Request( 'GET', '/wp/v2/pattern-directory/patterns/1' );
590+
$response = rest_get_server()->dispatch( $request );
591+
592+
$this->assertErrorResponse( 'rest_no_route', $response, 404 );
586593
}
587594

588595
/**
589-
* @doesNotPerformAssertions
596+
* Pattern directory is read-only; create requests should not match a route.
597+
*
598+
* @ticket 66073
590599
*/
591600
public function test_create_item() {
592-
// Controller does not implement create_item().
601+
wp_set_current_user( self::$contributor_id );
602+
603+
$request = new WP_REST_Request( 'POST', '/wp/v2/pattern-directory/patterns' );
604+
$request->set_param( 'title', 'Example pattern' );
605+
606+
$response = rest_get_server()->dispatch( $request );
607+
608+
$this->assertErrorResponse( 'rest_no_route', $response, 404 );
593609
}
594610

595611
/**
596-
* @doesNotPerformAssertions
612+
* Pattern directory has no item route; update requests should not match a route.
613+
*
614+
* @ticket 66073
597615
*/
598616
public function test_update_item() {
599-
// Controller does not implement update_item().
617+
wp_set_current_user( self::$contributor_id );
618+
619+
$request = new WP_REST_Request( 'POST', '/wp/v2/pattern-directory/patterns/1' );
620+
$request->set_param( 'title', 'Updated' );
621+
622+
$response = rest_get_server()->dispatch( $request );
623+
624+
$this->assertErrorResponse( 'rest_no_route', $response, 404 );
600625
}
601626

602627
/**
603-
* @doesNotPerformAssertions
628+
* Pattern directory has no item route; delete requests should not match a route.
629+
*
630+
* @ticket 66073
604631
*/
605632
public function test_delete_item() {
606-
// Controller does not implement delete_item().
633+
wp_set_current_user( self::$contributor_id );
634+
635+
$request = new WP_REST_Request( 'DELETE', '/wp/v2/pattern-directory/patterns/1' );
636+
$response = rest_get_server()->dispatch( $request );
637+
638+
$this->assertErrorResponse( 'rest_no_route', $response, 404 );
607639
}
608640

609641
/**

0 commit comments

Comments
 (0)