Make WordPress Core

Changeset 64036


Ignore:
Timestamp:
10/01/2026 07:57:59 PM (7 weeks ago)
Author:
lancewillett
Message:

Tests: Use static metadata for image editor filter tests.

Create attachment records with static image metadata instead of uploading images and generating thumbnails for the image_edit_thumbnails_separately filter tests. Preserve the filter invocation and conditional markup checks, including the thumbnail metadata needed to render the controls.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/13909

Props sainathpoojary.
See #66074.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/image/functions.php

    r63880 r64036  
    380380                require_once ABSPATH . 'wp-admin/includes/image-edit.php';
    381381
    382                 $filename = DIR_TESTDATA . '/images/canola.jpg';
    383                 $contents = file_get_contents( $filename );
    384                 $upload   = wp_upload_bits( wp_basename( $filename ), null, $contents );
    385                 $id       = $this->_make_attachment( $upload );
     382                $id = $this->create_image_editor_test_attachment();
    386383
    387384                $filter = new MockAction();
    … …  
    411408                require_once ABSPATH . 'wp-admin/includes/image-edit.php';
    412409
    413                 $filename = DIR_TESTDATA . '/images/canola.jpg';
    414                 $contents = file_get_contents( $filename );
    415                 $upload   = wp_upload_bits( wp_basename( $filename ), null, $contents );
    416                 $id       = $this->_make_attachment( $upload );
     410                $id = $this->create_image_editor_test_attachment();
    417411
    418412                add_filter( 'image_edit_thumbnails_separately', $callback );
    … …  
    453447                        ),
    454448                );
     449        }
     450
     451        /**
     452         * Creates a minimal image attachment for wp_image_editor() filter tests.
     453         *
     454         * Uses static metadata instead of generating real thumbnails. A thumbnail
     455         * size entry is needed for the imgedit-applyto section to render.
     456         *
     457         * @return int Attachment post ID.
     458         */
     459        private function create_image_editor_test_attachment() {
     460                $attachment_id = self::factory()->attachment->create(
     461                        array(
     462                                'post_mime_type' => 'image/jpeg',
     463                                'file'           => DIR_TESTDATA . '/images/canola.jpg',
     464                        )
     465                );
     466
     467                wp_update_attachment_metadata(
     468                        $attachment_id,
     469                        array(
     470                                'width'  => 640,
     471                                'height' => 480,
     472                                'file'   => 'canola.jpg',
     473                                'sizes'  => array(
     474                                        'thumbnail' => array(
     475                                                'file'      => 'canola-150x150.jpg',
     476                                                'width'     => 150,
     477                                                'height'    => 150,
     478                                                'mime-type' => 'image/jpeg',
     479                                        ),
     480                                ),
     481                        )
     482                );
     483
     484                return $attachment_id;
    455485        }
    456486
Note: See TracChangeset for help on using the changeset viewer.