wordpress-develop/tests/phpunit/tests/rest-api/wpRestEditSiteExportController.php
Sergey Biryukov 32ead26653 Tests: Explicitly mark empty REST API tests as not performing any assertions.
WordPress core test suite uses PHPUnit's `beStrictAboutTestsThatDoNotTestAnything` option set to true, which marks a test as risky when no assertions are performed.

REST API test classes have some empty tests for non-implemented methods because these test classes extend the abstract `WP_Test_REST_Controller_Testcase` class, which requires several methods to be implemented that don't necessarily make sense for all REST API routes.

As these tests are intentionally empty, they were previously marked as skipped, so that they are not reported as risky.

This commit aims to further reduce noise in the test suite and effectively ignores these empty tests altogether, which seems like a more appropriate option at this time.

The `@doesNotPerformAssertions` annotation can be reconsidered in the future when the tests are either removed as unnecessary or updated to actually perform assertions related to their behavior.

Follow-up to [40534], [41176], [41228], [53921].

See #40538, #41463, #55652.

git-svn-id: https://develop.svn.wordpress.org/trunk@54058 602fd350-edb4-49c9-b593-d223f7449a82
2022-09-01 22:54:19 +00:00

157 lines
3.2 KiB
PHP

<?php
/**
* WP_REST_Edit_Site_Export_Controller tests.
*
* @package WordPress
* @subpackage REST_API
* @since 5.9.0
*/
/**
* Tests for WP_REST_Edit_Site_Export_Controller.
*
* @since 5.9.0
*
* @covers WP_REST_Edit_Site_Export_Controller
*
* @group restapi
*/
class Tests_REST_WpRestEditSiteExportController extends WP_Test_REST_Controller_Testcase {
/**
* The REST API route for the edit site export.
*
* @since 5.9.0
*
* @var string
*/
const REQUEST_ROUTE = '/wp-block-editor/v1/export';
/**
* Subscriber user ID.
*
* @since 5.9.0
*
* @var int
*/
protected static $subscriber_id;
/**
* Set up class test fixtures.
*
* @since 5.9.0
*
* @param WP_UnitTest_Factory $factory WordPress unit test factory.
*/
public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
self::$subscriber_id = $factory->user->create(
array(
'role' => 'subscriber',
)
);
}
/**
* Delete test data after our tests run.
*
* @since 5.9.0
*/
public static function wpTearDownAfterClass() {
self::delete_user( self::$subscriber_id );
}
/**
* @covers WP_REST_Edit_Site_Export_Controller::register_routes
* @ticket 54448
*/
public function test_register_routes() {
$routes = rest_get_server()->get_routes();
$this->assertArrayHasKey( static::REQUEST_ROUTE, $routes );
$this->assertCount( 1, $routes[ static::REQUEST_ROUTE ] );
}
/**
* @covers WP_REST_Edit_Site_Export_Controller::permissions_check
*
* @ticket 54448
*/
public function test_export_for_no_user_permissions() {
wp_set_current_user( 0 );
$request = new WP_REST_Request( 'GET', static::REQUEST_ROUTE );
$response = rest_get_server()->dispatch( $request );
$this->assertErrorResponse( 'rest_cannot_export_templates', $response, 401 );
}
/**
* @covers WP_REST_Edit_Site_Export_Controller::permissions_check
*
* @ticket 54448
*/
public function test_export_for_user_with_insufficient_permissions() {
wp_set_current_user( self::$subscriber_id );
$request = new WP_REST_Request( 'GET', static::REQUEST_ROUTE );
$response = rest_get_server()->dispatch( $request );
$this->assertErrorResponse( 'rest_cannot_export_templates', $response, 403 );
}
/**
* @doesNotPerformAssertions
*/
public function test_context_param() {
// Controller does not use get_context_param().
}
/**
* @doesNotPerformAssertions
*/
public function test_get_item() {
// Controller does not implement get_item().
}
/**
* @doesNotPerformAssertions
*/
public function test_get_items() {
// Controller does not implement get_items().
}
/**
* @doesNotPerformAssertions
*/
public function test_create_item() {
// Controller does not implement create_item().
}
/**
* @doesNotPerformAssertions
*/
public function test_update_item() {
// Controller does not implement update_item().
}
/**
* @doesNotPerformAssertions
*/
public function test_delete_item() {
// Controller does not implement delete_item().
}
/**
* @doesNotPerformAssertions
*/
public function test_prepare_item() {
// Controller does not implement prepare_item().
}
/**
* @doesNotPerformAssertions
*/
public function test_get_item_schema() {
// Controller does not implement get_item_schema().
}
}