Tests: Clean up skipping conditions and requirements for various tests.

This improves the consistency of test skipping and ensures that:

* The `@requires` annotations use the right condition and format, and are on the right level (class vs. function).
* Inline conditions with a `markTestSkipped()` call are only used when annotations cannot be used.
* All `markTestSkipped()` calls contain a verbose explanation of why the test is being skipped.

Props jrf, hellofromTonya.
Fixes #53009.

git-svn-id: https://develop.svn.wordpress.org/trunk@51415 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov
2021-07-13 10:43:42 +00:00
parent 4d616c6665
commit b396844d38
29 changed files with 183 additions and 125 deletions

View File

@@ -743,6 +743,9 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
$this->assertErrorResponse( 'rest_forbidden', $response, 401 );
}
/**
* @requires function imagejpeg
*/
public function test_create_item() {
wp_set_current_user( self::$author_id );
@@ -792,6 +795,9 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
$this->assertSame( 'codeispoetry', $data['title']['raw'] );
}
/**
* @requires function imagejpeg
*/
public function test_create_item_with_files() {
wp_set_current_user( self::$author_id );
$request = new WP_REST_Request( 'POST', '/wp/v2/media' );
@@ -810,6 +816,9 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
$this->assertSame( 201, $response->get_status() );
}
/**
* @requires function imagejpeg
*/
public function test_create_item_with_upload_files_role() {
wp_set_current_user( self::$uploader_id );
$request = new WP_REST_Request( 'POST', '/wp/v2/media' );
@@ -924,6 +933,9 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
$this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
}
/**
* @requires function imagejpeg
*/
public function test_create_item_alt_text() {
wp_set_current_user( self::$author_id );
$request = new WP_REST_Request( 'POST', '/wp/v2/media' );
@@ -937,6 +949,9 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
$this->assertSame( 'test alt text', $attachment['alt_text'] );
}
/**
* @requires function imagejpeg
*/
public function test_create_item_unsafe_alt_text() {
wp_set_current_user( self::$author_id );
$request = new WP_REST_Request( 'POST', '/wp/v2/media' );
@@ -951,6 +966,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
/**
* @ticket 40861
* @requires function imagejpeg
*/
public function test_create_item_ensure_relative_path() {
wp_set_current_user( self::$author_id );
@@ -1274,6 +1290,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
/**
* @dataProvider attachment_roundtrip_provider
* @requires function imagejpeg
*/
public function test_post_roundtrip_as_author( $raw, $expected ) {
wp_set_current_user( self::$author_id );
@@ -1281,6 +1298,9 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
$this->verify_attachment_roundtrip( $raw, $expected );
}
/**
* @requires function imagejpeg
*/
public function test_attachment_roundtrip_as_editor_unfiltered_html() {
wp_set_current_user( self::$editor_id );
if ( is_multisite() ) {
@@ -1332,6 +1352,9 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
}
}
/**
* @requires function imagejpeg
*/
public function test_attachment_roundtrip_as_superadmin_unfiltered_html() {
wp_set_current_user( self::$superadmin_id );
$this->assertTrue( current_user_can( 'unfiltered_html' ) );
@@ -1808,6 +1831,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
* once when attachments are created.
*
* @ticket 45269
* @requires function imagejpeg
*/
public function test_rest_insert_attachment_hooks_fire_once_on_create() {
self::$rest_insert_attachment_count = 0;
@@ -1865,6 +1889,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
/**
* @ticket 44567
* @requires function imagejpeg
*/
public function test_create_item_with_meta_values() {
register_post_meta(
@@ -1902,6 +1927,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
/**
* @ticket 44405
* @requires function imagejpeg
*/
public function test_edit_image_returns_error_if_logged_out() {
$attachment = self::factory()->attachment->create_upload_object( $this->test_file );
@@ -1914,6 +1940,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
/**
* @ticket 44405
* @requires function imagejpeg
*/
public function test_edit_image_returns_error_if_cannot_upload() {
$user = self::factory()->user->create_and_get( array( 'role' => 'editor' ) );
@@ -1930,6 +1957,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
/**
* @ticket 44405
* @requires function imagejpeg
*/
public function test_edit_image_returns_error_if_cannot_edit() {
wp_set_current_user( self::$uploader_id );
@@ -1956,6 +1984,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
/**
* @ticket 44405
* @requires function imagejpeg
*/
public function test_edit_image_returns_error_if_unsupported_mime_type() {
wp_set_current_user( self::$superadmin_id );
@@ -1975,6 +2004,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
/**
* @ticket 44405
* @requires function imagejpeg
*/
public function test_edit_image_returns_error_if_no_edits() {
wp_set_current_user( self::$superadmin_id );
@@ -1988,6 +2018,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
/**
* @ticket 44405
* @requires function imagejpeg
*/
public function test_edit_image_rotate() {
wp_set_current_user( self::$superadmin_id );
@@ -2012,6 +2043,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
/**
* @ticket 44405
* @requires function imagejpeg
*/
public function test_edit_image_crop() {
wp_set_current_user( self::$superadmin_id );
@@ -2118,6 +2150,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control
/**
* @ticket 50565
* @requires function imagejpeg
*/
public function test_edit_image_returns_error_if_mismatched_src() {
wp_set_current_user( self::$superadmin_id );