Make WordPress Core

Ticket #24871: 24871(1).diff

File 24871(1).diff, 3.6 KB (added by voldemortensen, 10 years ago)
  • tests/phpunit/tests/image/base.php

     
    3636        }
    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
    4242         * @param  array $point      array(x,y)
    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] );
    4848
     
    5252        }
    5353
    5454        /**
     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 );
     66        }
     67
     68        /**
    5569         * Helper assertion to check actual image dimensions on disk
    5670         *
    5771         * @param string $filename Image filename.
  • tests/phpunit/tests/image/editor_imagick.php

     
    461461         */
    462462        public function test_image_preserves_alpha_on_resize() {
    463463                $file = DIR_TESTDATA . '/images/transparent.png';
    464 
    465464                $editor = wp_get_image_editor( $file );
    466 
    467465                $this->assertNotInstanceOf( 'WP_Error', $editor );
    468466               
    469467                $editor->load();
     
    472470
    473471                $editor->save( $save_to_file );
    474472
    475                 $this->assertImageAlphaAtPoint( $save_to_file, array( 0,0 ), 127 );
     473                $im = new Imagick( $save_to_file );
     474                $pixel = $im->getImagePixelColor( 0, 0 );
     475                $expected = $pixel->getColorValue( imagick::COLOR_ALPHA );
    476476
     477                $this->assertImageAlphaAtPointImagick( $save_to_file, array( 0,0 ), $expected );
     478
    477479                unlink( $save_to_file );
    478480        }
    479481
     
    484486         */
    485487        public function test_image_preserves_alpha() {
    486488                $file = DIR_TESTDATA . '/images/transparent.png';
    487 
    488489                $editor = wp_get_image_editor( $file );
    489 
    490490                $this->assertNotInstanceOf( 'WP_Error', $editor );
    491491
    492492                $editor->load();
    493 
    494493                $save_to_file = tempnam( get_temp_dir(), '' ) . '.png';
    495 
    496494                $editor->save( $save_to_file );
    497495
    498                 $this->assertImageAlphaAtPoint( $save_to_file, array( 0,0 ), 127 );
     496                $im = new Imagick( $save_to_file );
     497                $pixel = $im->getImagePixelColor( 0, 0 );
     498                $expected = $pixel->getColorValue( imagick::COLOR_ALPHA );
    499499
     500                $this->assertImageAlphaAtPointImagick( $save_to_file, array( 0,0 ), $expected );
     501
    500502                unlink( $save_to_file );
    501503        }
    502504}
  • tests/phpunit/tests/image/editor_gd.php

     
    472472
    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 );
    478478        }
     
    495495
    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 );
    501501        }