Make WordPress Core

Changeset 30549


Ignore:
Timestamp:
11/24/2014 08:56:36 PM (12 years ago)
Author:
boonebgorges
Message:

Fix the unit tests for Imagick alpha.

These tests were written to use the assertImageAtAlpha() helper method, whose
internals were specific to GD. As a result, the tests could not pass. This
changeset introduces GD- and Imagick-specific versions of this method.

Props voldemortensen.
Fixes #24871.

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

Legend:

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

    r29120 r30549  
    3737
    3838        /**
    39          * Helper assertion for testing alpha on images
     39         * Helper assertion for testing alpha on images using GD library
    4040         *
    4141         * @param  string $image_path
    … …  
    4343         * @param  int $alpha
    4444         */
    45         protected function assertImageAlphaAtPoint( $image_path, $point, $alpha ) {
     45        protected function assertImageAlphaAtPointGD( $image_path, $point, $alpha ) {
    4646                $im = imagecreatefrompng( $image_path );
    4747                $rgb = imagecolorat( $im, $point[0], $point[1] );
    … …  
    5050
    5151                $this->assertEquals( $alpha, $colors['alpha'] );
     52        }
     53
     54        /**
     55         * Helper assertion for testing alpha on images using Imagick
     56         *
     57         * @param string $image_path
     58         * @param array $point      array(x,y)
     59         * @param int $expected
     60         */
     61        protected function assertImageAlphaAtPointImagick( $image_path, $point, $expected ) {
     62                $im = new Imagick( $image_path );
     63                $pixel = $im->getImagePixelColor( $point[0], $point[1] );
     64                $color = $pixel->getColorValue( imagick::COLOR_ALPHA );
     65                $this->assertEquals( $expected, $color );
    5266        }
    5367
  • trunk/tests/phpunit/tests/image/editor_gd.php

    r29834 r30549  
    473473                $editor->save( $save_to_file );
    474474
    475                 $this->assertImageAlphaAtPoint( $save_to_file, array( 0,0 ), 127 );
     475                $this->assertImageAlphaAtPointGD( $save_to_file, array( 0,0 ), 127 );
    476476
    477477                unlink( $save_to_file );
    … …  
    496496                $editor->save( $save_to_file );
    497497
    498                 $this->assertImageAlphaAtPoint( $save_to_file, array( 0,0 ), 127 );
     498                $this->assertImageAlphaAtPointGD( $save_to_file, array( 0,0 ), 127 );
    499499
    500500                unlink( $save_to_file );
  • trunk/tests/phpunit/tests/image/editor_imagick.php

    r29834 r30549  
    473473                $editor->save( $save_to_file );
    474474
    475                 $this->assertImageAlphaAtPoint( $save_to_file, array( 0,0 ), 127 );
     475                $im = new Imagick( $save_to_file );
     476                $pixel = $im->getImagePixelColor( 0, 0 );
     477                $expected = $pixel->getColorValue( imagick::COLOR_ALPHA );
     478
     479                $this->assertImageAlphaAtPointImagick( $save_to_file, array( 0,0 ), $expected );
    476480
    477481                unlink( $save_to_file );
    … …  
    496500                $editor->save( $save_to_file );
    497501
    498                 $this->assertImageAlphaAtPoint( $save_to_file, array( 0,0 ), 127 );
     502                $im = new Imagick( $save_to_file );
     503                $pixel = $im->getImagePixelColor( 0, 0 );
     504                $expected = $pixel->getColorValue( imagick::COLOR_ALPHA );
     505
     506                $this->assertImageAlphaAtPointImagick( $save_to_file, array( 0,0 ), $expected );
    499507
    500508                unlink( $save_to_file );
Note: See TracChangeset for help on using the changeset viewer.