Make WordPress Core

Changeset 53920


Ignore:
Timestamp:
08/22/2022 07:50:15 PM (2 years ago)
Author:
SergeyBiryukov
Message:

Tests: Clean up test image before performing assertions in image tests.

This makes sure there are no leftover images in case of a test failure.

Applies to: test_wp_calculate_image_srcset_no_date_uploads().

Includes renaming the $int variable to $int_size for consistency with some other tests.

Follow-up to [34855], [35412], [35751], [53463].

See #55652.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/media.php

    r53795 r53920  
    16541654        $expected = trim( $expected, ' ,' );
    16551655
    1656         foreach ( $intermediates as $int ) {
    1657             $image_url  = wp_get_attachment_image_url( self::$large_id, $int );
    1658             $size_array = $this->get_image_size_array_from_meta( $image_meta, $int );
    1659 
    1660             if ( 'full' === $int ) {
     1656        foreach ( $intermediates as $int_size ) {
     1657            $image_url  = wp_get_attachment_image_url( self::$large_id, $int_size );
     1658            $size_array = $this->get_image_size_array_from_meta( $image_meta, $int_size );
     1659
     1660            if ( 'full' === $int_size ) {
    16611661                // Add the full size image. Expected to be in the srcset when the full size image is used as src.
    16621662                $_expected = $uploads_dir_url . $image_meta['file'] . ' ' . $image_meta['width'] . 'w, ' . $expected;
     
    17071707        $expected = trim( $expected, ' ,' );
    17081708
    1709         foreach ( $intermediates as $int ) {
    1710             $size_array = $this->get_image_size_array_from_meta( $image_meta, $int );
    1711             $image_url  = wp_get_attachment_image_url( $id, $int );
    1712 
    1713             if ( 'full' === $int ) {
     1709        foreach ( $intermediates as $int_size ) {
     1710            $image_urls[ $int_size ] = wp_get_attachment_image_url( $id, $int_size );
     1711        }
     1712
     1713        // Remove the attachment.
     1714        wp_delete_attachment( $id, true );
     1715        remove_filter( 'upload_dir', '_upload_dir_no_subdir' );
     1716
     1717        foreach ( $intermediates as $int_size ) {
     1718            $size_array = $this->get_image_size_array_from_meta( $image_meta, $int_size );
     1719            $image_url  = $image_urls[ $int_size ];
     1720
     1721            if ( 'full' === $int_size ) {
    17141722                // Add the full size image. Expected to be in the srcset when the full size image is used as src.
    17151723                $_expected = $uploads_dir_url . $image_meta['file'] . ' ' . $image_meta['width'] . 'w, ' . $expected;
     
    17221730        }
    17231731
    1724         // Remove the attachment.
    1725         wp_delete_attachment( $id, true );
    1726         remove_filter( 'upload_dir', '_upload_dir_no_subdir' );
    17271732    }
    17281733
     
    17971802        $image_meta['file'] = 'H:\home\wordpress\trunk/wp-content/uploads/' . $image_meta['file'];
    17981803
    1799         foreach ( $intermediates as $int ) {
    1800             $image_url  = wp_get_attachment_image_url( self::$large_id, $int );
    1801             $size_array = $this->get_image_size_array_from_meta( $image_meta, $int );
    1802 
    1803             if ( 'full' === $int ) {
     1804        foreach ( $intermediates as $int_size ) {
     1805            $image_url  = wp_get_attachment_image_url( self::$large_id, $int_size );
     1806            $size_array = $this->get_image_size_array_from_meta( $image_meta, $int_size );
     1807
     1808            if ( 'full' === $int_size ) {
    18041809                // Add the full size image. Expected to be in the srcset when the full size image is used as src.
    18051810                $_expected = $uploads_dir_url . $full_size_file . ' ' . $image_meta['width'] . 'w, ' . $expected;
Note: See TracChangeset for help on using the changeset viewer.