Make WordPress Core

Changeset 53463


Ignore:
Timestamp:
06/04/2022 12:55:15 PM (4 years ago)
Author:
SergeyBiryukov
Message:

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

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

Follow-up to [161/tests], [1255/tests].

See #55652.

File:
1 edited

Legend:

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

    r52010 r53463  
    2424                $image = $this->resize_helper( DIR_TESTDATA . '/images/test-image.jpg', 25, 25 );
    2525
     26                list( $w, $h, $type ) = getimagesize( $image );
     27
     28                unlink( $image );
     29
    2630                $this->assertSame( 'test-image-25x25.jpg', wp_basename( $image ) );
    27                 list($w, $h, $type) = getimagesize( $image );
    28                 $this->assertSame( 25, $w );
    29                 $this->assertSame( 25, $h );
    30                 $this->assertSame( IMAGETYPE_JPEG, $type );
    31 
    32                 unlink( $image );
     31                $this->assertSame( 25, $w );
     32                $this->assertSame( 25, $h );
     33                $this->assertSame( IMAGETYPE_JPEG, $type );
    3334        }
    3435
    … …  
    4041                }
    4142
     43                list( $w, $h, $type ) = getimagesize( $image );
     44
     45                unlink( $image );
     46
    4247                $this->assertSame( 'test-image-25x25.png', wp_basename( $image ) );
    43                 list($w, $h, $type) = getimagesize( $image );
    4448                $this->assertSame( 25, $w );
    4549                $this->assertSame( 25, $h );
    4650                $this->assertSame( IMAGETYPE_PNG, $type );
    47 
    48                 unlink( $image );
    4951        }
    5052
    … …  
    5658                }
    5759
     60                list( $w, $h, $type ) = getimagesize( $image );
     61
     62                unlink( $image );
     63
    5864                $this->assertSame( 'test-image-25x25.gif', wp_basename( $image ) );
    59                 list($w, $h, $type) = getimagesize( $image );
    6065                $this->assertSame( 25, $w );
    6166                $this->assertSame( 25, $h );
    6267                $this->assertSame( IMAGETYPE_GIF, $type );
    63 
    64                 unlink( $image );
    6568        }
    6669
    … …  
    7578
    7679                $image = $this->resize_helper( $file, 25, 25 );
     80
     81                list( $w, $h, $type ) = wp_getimagesize( $image );
     82
     83                unlink( $image );
     84
    7785                $this->assertSame( 'test-image-25x25.webp', wp_basename( $image ) );
    78                 list($w, $h, $type) = wp_getimagesize( $image );
    7986                $this->assertSame( 25, $w );
    8087                $this->assertSame( 25, $h );
    8188                $this->assertSame( IMAGETYPE_WEBP, $type );
    82                 unlink( $image );
    8389        }
    8490
    … …  
    94100                $image = $this->resize_helper( DIR_TESTDATA . '/images/2007-06-17DSC_4173.JPG', 128, 96 );
    95101
     102                list( $w, $h, $type ) = getimagesize( $image );
     103
     104                unlink( $image );
     105
    96106                $this->assertSame( '2007-06-17DSC_4173-64x96.jpg', wp_basename( $image ) );
    97                 list($w, $h, $type) = getimagesize( $image );
    98107                $this->assertSame( 64, $w );
    99108                $this->assertSame( 96, $h );
    100109                $this->assertSame( IMAGETYPE_JPEG, $type );
    101 
    102                 unlink( $image );
    103110        }
    104111
    … …  
    106113                $image = $this->resize_helper( DIR_TESTDATA . '/images/2007-06-17DSC_4173.JPG', 128, 0 );
    107114
     115                list( $w, $h, $type ) = getimagesize( $image );
     116
     117                unlink( $image );
     118
    108119                $this->assertSame( '2007-06-17DSC_4173-128x193.jpg', wp_basename( $image ) );
    109                 list($w, $h, $type) = getimagesize( $image );
    110120                $this->assertSame( 128, $w );
    111121                $this->assertSame( 193, $h );
    112122                $this->assertSame( IMAGETYPE_JPEG, $type );
    113 
    114                 unlink( $image );
    115123        }
    116124
    … …  
    118126                $image = $this->resize_helper( DIR_TESTDATA . '/images/2007-06-17DSC_4173.JPG', 0, 96 );
    119127
     128                list( $w, $h, $type ) = getimagesize( $image );
     129
     130                unlink( $image );
     131
    120132                $this->assertSame( '2007-06-17DSC_4173-64x96.jpg', wp_basename( $image ) );
    121                 list($w, $h, $type) = getimagesize( $image );
    122133                $this->assertSame( 64, $w );
    123134                $this->assertSame( 96, $h );
    124135                $this->assertSame( IMAGETYPE_JPEG, $type );
    125 
    126                 unlink( $image );
    127136        }
    128137
    … …  
    130139                $image = $this->resize_helper( DIR_TESTDATA . '/images/2007-06-17DSC_4173.JPG', 150, 150, true );
    131140
     141                list( $w, $h, $type ) = getimagesize( $image );
     142
     143                unlink( $image );
     144
    132145                $this->assertSame( '2007-06-17DSC_4173-150x150.jpg', wp_basename( $image ) );
    133                 list($w, $h, $type) = getimagesize( $image );
    134146                $this->assertSame( 150, $w );
    135147                $this->assertSame( 150, $h );
    136148                $this->assertSame( IMAGETYPE_JPEG, $type );
    137 
    138                 unlink( $image );
    139149        }
    140150
    … …  
    142152                $image = $this->resize_helper( DIR_TESTDATA . '/images/2007-06-17DSC_4173.JPG', 150, 100, true );
    143153
     154                list( $w, $h, $type ) = getimagesize( $image );
     155
     156                unlink( $image );
     157
    144158                $this->assertSame( '2007-06-17DSC_4173-150x100.jpg', wp_basename( $image ) );
    145                 list($w, $h, $type) = getimagesize( $image );
    146159                $this->assertSame( 150, $w );
    147160                $this->assertSame( 100, $h );
    148161                $this->assertSame( IMAGETYPE_JPEG, $type );
    149 
    150                 unlink( $image );
    151162        }
    152163
    … …  
    154165                $image = $this->resize_helper( DIR_TESTDATA . '/images/2007-06-17DSC_4173.JPG', 50, 150, true );
    155166
     167                list( $w, $h, $type ) = getimagesize( $image );
     168
     169                unlink( $image );
     170
    156171                $this->assertSame( '2007-06-17DSC_4173-50x150.jpg', wp_basename( $image ) );
    157                 list($w, $h, $type) = getimagesize( $image );
    158172                $this->assertSame( 50, $w );
    159173                $this->assertSame( 150, $h );
    160174                $this->assertSame( IMAGETYPE_JPEG, $type );
    161 
    162                 unlink( $image );
    163175        }
    164176
    … …  
    186198
    187199                $resized = $editor->resize( $width, $height, $crop );
     200
    188201                if ( is_wp_error( $resized ) ) {
    189202                        return $resized;
Note: See TracChangeset for help on using the changeset viewer.