Skip to content

Commit 10bbb65

Browse files
committed
Tests: Reduce REST attachment quality fixture overhead.
Create attachment records with static image metadata for the three REST image quality response tests instead of uploading a JPEG and generating thumbnails. Preserve the requests, filters, and assertions while removing the unnecessary `imagejpeg()` requirements. Developed in: #14026 Props abcd95. See #66074. git-svn-id: https://develop.svn.wordpress.org/trunk@64260 602fd350-edb4-49c9-b593-d223f7449a82
1 parent fd20633 commit 10bbb65

1 file changed

Lines changed: 32 additions & 6 deletions

File tree

‎tests/phpunit/tests/rest-api/rest-attachments-controller.php‎

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2156,11 +2156,10 @@ public function test_image_quality_schema() {
21562156

21572157
/**
21582158
* @ticket 65262
2159-
* @requires function imagejpeg
21602159
*/
21612160
public function test_image_quality_default_in_response() {
21622161
wp_set_current_user( self::$editor_id );
2163-
$attachment = self::factory()->attachment->create_upload_object( self::$test_file );
2162+
$attachment = $this->create_image_quality_test_attachment();
21642163

21652164
$request = new WP_REST_Request( 'GET', "/wp/v2/media/{$attachment}" );
21662165
$request->set_param( 'context', 'edit' );
@@ -2176,11 +2175,10 @@ public function test_image_quality_default_in_response() {
21762175

21772176
/**
21782177
* @ticket 65262
2179-
* @requires function imagejpeg
21802178
*/
21812179
public function test_image_quality_with_size_aware_filter() {
21822180
wp_set_current_user( self::$editor_id );
2183-
$attachment = self::factory()->attachment->create_upload_object( self::$test_file );
2181+
$attachment = $this->create_image_quality_test_attachment();
21842182

21852183
// Lower the quality for small images (e.g. thumbnails) only.
21862184
$filter = static function ( $quality, $mime_type, $size ) {
@@ -2212,11 +2210,10 @@ public function test_image_quality_with_size_aware_filter() {
22122210
* way WP_Image_Editor::set_quality() applies it for JPEG output.
22132211
*
22142212
* @ticket 65262
2215-
* @requires function imagejpeg
22162213
*/
22172214
public function test_image_quality_honors_jpeg_quality_filter() {
22182215
wp_set_current_user( self::$editor_id );
2219-
$attachment = self::factory()->attachment->create_upload_object( self::$test_file );
2216+
$attachment = $this->create_image_quality_test_attachment();
22202217

22212218
$filter = static function () {
22222219
return 70;
@@ -2235,6 +2232,35 @@ public function test_image_quality_honors_jpeg_quality_filter() {
22352232
$this->assertSame( 70, $data['image_quality']['default'] );
22362233
}
22372234

2235+
/**
2236+
* Creates a JPEG attachment with static metadata for image quality tests.
2237+
*
2238+
* Quality reporting uses the MIME type, full-size dimensions, and registered
2239+
* image sizes, so no upload or generated thumbnails are needed.
2240+
*
2241+
* @return int Attachment post ID.
2242+
*/
2243+
private function create_image_quality_test_attachment() {
2244+
$attachment_id = self::factory()->attachment->create(
2245+
array(
2246+
'post_mime_type' => 'image/jpeg',
2247+
'post_status' => 'inherit',
2248+
'file' => 'canola.jpg',
2249+
)
2250+
);
2251+
2252+
wp_update_attachment_metadata(
2253+
$attachment_id,
2254+
array(
2255+
'width' => 640,
2256+
'height' => 480,
2257+
'file' => 'canola.jpg',
2258+
)
2259+
);
2260+
2261+
return $attachment_id;
2262+
}
2263+
22382264
/**
22392265
* Tests the image_output_format / image_save_progressive schema properties.
22402266
*

0 commit comments

Comments
 (0)