Make WordPress Core

Changeset 1187 in tests


Ignore:
Timestamp:
01/14/2013 09:25:14 PM (12 years ago)
Author:
joehoyle
Message:

Added some more tests for WP_Image_Editor_GD for crop(), rotate() etc

Location:
trunk
Files:
1 added
1 edited

Legend:

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

    r1182 r1187  
    55 * @group image
    66 * @group media
     7 * @group wp-image-editor-gd
    78 */
    89
     
    1415        require_once( ABSPATH . WPINC . '/class-wp-image-editor-gd.php' );
    1516        parent::setUp();
     17    }
     18
     19    /**
     20     * Check support for GD compatible mime types.
     21     *
     22     */
     23    public function test_supports_mime_type() {
     24        $gd_image_editor = new WP_Image_Editor_GD( null );
     25
     26        $this->assertTrue( $gd_image_editor->supports_mime_type( 'image/jpeg' ), 'Does not support image/jpeg' );
     27        $this->assertTrue( $gd_image_editor->supports_mime_type( 'image/png' ), 'Does not support image/png' );
     28        $this->assertTrue( $gd_image_editor->supports_mime_type( 'image/gif' ), 'Does not support image/gif' );
     29    }
     30
     31    /**
     32     * Test resizing an image, not using crop
     33     *
     34     */
     35    public function test_resize() {
     36
     37        $file = DIR_TESTDATA . '/images/gradient-square.jpg';
     38
     39        $gd_image_editor = new WP_Image_Editor_GD( $file );
     40        $gd_image_editor->load();
     41
     42        $gd_image_editor->resize( 100, 50 );
     43
     44        $this->assertEquals( array( 'width' => 50, 'height' => 50 ), $gd_image_editor->get_size() );
     45    }
     46
     47    /**
     48     * Test resizing an image including cropping
     49     *
     50     */
     51    public function test_resize_and_crop() {
     52
     53        $file = DIR_TESTDATA . '/images/gradient-square.jpg';
     54
     55        $gd_image_editor = new WP_Image_Editor_GD( $file );
     56        $gd_image_editor->load();
     57
     58        $gd_image_editor->resize( 100, 50, true );
     59
     60        $this->assertEquals( array( 'width' => 100, 'height' => 50 ), $gd_image_editor->get_size() );
     61    }
     62
     63    /**
     64     * Test cropping an image
     65     */
     66    public function test_crop() {
     67
     68        $file = DIR_TESTDATA . '/images/gradient-square.jpg';
     69
     70        $gd_image_editor = new WP_Image_Editor_GD( $file );
     71        $gd_image_editor->load();
     72
     73        $gd_image_editor->crop( 0, 0, 50, 50 );
     74
     75        $this->assertEquals( array( 'width' => 50, 'height' => 50 ), $gd_image_editor->get_size() );
     76
     77    }
     78
     79    /**
     80     * Test rotating an image 180 deg
     81     */
     82    public function test_rotate() {
     83
     84        $file = DIR_TESTDATA . '/images/gradient-square.jpg';
     85
     86        $gd_image_editor = new WP_Image_Editor_GD( $file );
     87        $gd_image_editor->load();
     88
     89        $property = new ReflectionProperty( $gd_image_editor, 'image' );
     90        $property->setAccessible( true );
     91
     92        $color_top_left = imagecolorat( $property->getValue( $gd_image_editor ), 0, 0 );
     93
     94        $gd_image_editor->rotate( 180 );
     95
     96        $this->assertEquals( $color_top_left, imagecolorat( $property->getValue( $gd_image_editor ), 99, 99 ) );
     97    }
     98
     99    /**
     100     * Test flipping an image
     101     */
     102    public function test_flip() {
     103
     104        $file = DIR_TESTDATA . '/images/gradient-square.jpg';
     105
     106        $gd_image_editor = new WP_Image_Editor_GD( $file );
     107        $gd_image_editor->load();
     108
     109        $property = new ReflectionProperty( $gd_image_editor, 'image' );
     110        $property->setAccessible( true );
     111
     112        $color_top_left = imagecolorat( $property->getValue( $gd_image_editor ), 0, 0 );
     113
     114        $gd_image_editor->flip( true, false );
     115
     116        $this->assertEquals( $color_top_left, imagecolorat( $property->getValue( $gd_image_editor ), 0, 99 ) );
    16117    }
    17118
Note: See TracChangeset for help on using the changeset viewer.