WordPress.org

Make WordPress Core

Changeset 31510


Ignore:
Timestamp:
02/22/2015 09:06:36 PM (7 years ago)
Author:
boonebgorges
Message:

Better image-type support checks in image unit tests.

PHP can be compiled without support for certain image types. Our unit tests
should be sensitive to these configurations.

Fixes #31124.

Location:
trunk/tests/phpunit/tests/image
Files:
2 edited

Legend:

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

    r31040 r31510  
    3232    }
    3333
    34     /**
    35      * Check support for GD compatible mime types.
    36      */
    37     public function test_supports_mime_type() {
     34    public function test_supports_mime_type_jpeg() {
    3835        $gd_image_editor = new WP_Image_Editor_GD( null );
    39 
    40         $this->assertTrue( $gd_image_editor->supports_mime_type( 'image/jpeg' ), 'Does not support image/jpeg' );
    41         $this->assertTrue( $gd_image_editor->supports_mime_type( 'image/png' ), 'Does not support image/png' );
    42         $this->assertTrue( $gd_image_editor->supports_mime_type( 'image/gif' ), 'Does not support image/gif' );
     36        $expected = imagetypes() & IMG_JPG;
     37        $this->assertEquals( $expected, $gd_image_editor->supports_mime_type( 'image/jpeg' ) );
     38    }
     39
     40    public function test_supports_mime_type_png() {
     41        $gd_image_editor = new WP_Image_Editor_GD( null );
     42        $expected = imagetypes() & IMG_PNG;
     43        $this->assertEquals( $expected, $gd_image_editor->supports_mime_type( 'image/png' ) );
     44    }
     45
     46    public function test_supports_mime_type_gif() {
     47        $gd_image_editor = new WP_Image_Editor_GD( null );
     48        $expected = imagetypes() & IMG_GIF;
     49        $this->assertEquals( $expected, $gd_image_editor->supports_mime_type( 'image/gif' ) );
    4350    }
    4451
     
    461468     */
    462469    public function test_image_preserves_alpha_on_resize() {
     470        if ( ! ( imagetypes() & IMG_PNG ) ) {
     471            $this->markTestSkipped( 'This test requires PHP to be compiled with PNG support.' );
     472        }
     473
    463474        $file = DIR_TESTDATA . '/images/transparent.png';
    464475
     
    484495     */
    485496    public function test_image_preserves_alpha() {
     497        if ( ! ( imagetypes() & IMG_PNG ) ) {
     498            $this->markTestSkipped( 'This test requires PHP to be compiled with PNG support.' );
     499        }
     500
    486501        $file = DIR_TESTDATA . '/images/transparent.png';
    487502
     
    506521     */
    507522    public function test_image_preserves_alpha_on_rotate() {
     523        if ( ! ( imagetypes() & IMG_PNG ) ) {
     524            $this->markTestSkipped( 'This test requires PHP to be compiled with PNG support.' );
     525        }
     526
    508527        $file = DIR_TESTDATA . '/images/transparent.png';
    509528
  • trunk/tests/phpunit/tests/image/functions.php

    r31259 r31510  
    138138            // Save a file as each mime type, assert it works
    139139            foreach ( $mime_types as $mime_type ) {
     140                if ( ! $class::supports_mime_type( $mime_type ) ) {
     141                    continue;
     142                }
     143
    140144                $file = wp_tempnam();
    141145                $ret = wp_save_image_file( $file, $img, $mime_type, 1 );
     
    229233            $temp = get_temp_dir();
    230234            foreach ( $mime_types as $ext => $mime_type ) {
     235                if ( ! $class::supports_mime_type( $mime_type ) ) {
     236                    continue;
     237                }
     238
    231239                $file = wp_unique_filename( $temp, uniqid() . ".$ext" );
    232240                $ret = $img->save( trailingslashit( $temp ) . $file );
Note: See TracChangeset for help on using the changeset viewer.