Make WordPress Core

Changeset 30875


Ignore:
Timestamp:
12/15/2014 09:49:34 PM (10 years ago)
Author:
johnbillion
Message:

Add tests which ensure the wp_editor_set_quality and jpeg_quality filters only apply if they are added before the corresponding WP_Image_Editor is instantiated.

Merges [30873] to the 4.1 branch.

Props DH-Shredder
See #29856

Location:
branches/4.1
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/4.1

  • branches/4.1/tests/phpunit/includes/mock-image-editor.php

    r25380 r30875  
    88        public static $test_return = true;
    99        public static $save_return = array();
     10
     11        // Allow testing of jpeg_quality filter.
     12        public function set_mime_type( $mime_type = null ) {
     13            $this->mime_type = $mime_type;
     14        }
    1015
    1116        public function load() {
  • branches/4.1/tests/phpunit/tests/image/editor.php

    r29834 r30875  
    5252        // Get an editor
    5353        $editor = wp_get_image_editor( DIR_TESTDATA . '/images/canola.jpg' );
     54        $editor->set_mime_type( "image/jpeg" ); // Ensure mime-specific filters act properly.
    5455
    5556        // Check default value
    5657        $this->assertEquals( 90, $editor->get_quality() );
    5758
    58         // Ensure set_quality works
     59        // Ensure the quality filters do not have precedence if created after editor instantiation.
     60        $func_100_percent = create_function( '', "return 100;" );
     61        add_filter( 'wp_editor_set_quality', $func_100_percent );
     62        $this->assertEquals( 90, $editor->get_quality() );
     63
     64        $func_95_percent = create_function( '', "return 95;" );
     65        add_filter( 'jpeg_quality', $func_95_percent );
     66        $this->assertEquals( 90, $editor->get_quality() );
     67
     68        // Ensure set_quality() works and overrides the filters
    5969        $this->assertTrue( $editor->set_quality( 75 ) );
    6070        $this->assertEquals( 75, $editor->get_quality() );
    6171
    62         // Ensure the quality filter works
    63         $func = create_function( '', "return 100;");
    64         add_filter( 'wp_editor_set_quality', $func );
    65         $this->assertTrue( $editor->set_quality( 70 ) );
    66         $this->assertEquals( 70, $editor->get_quality() );
     72        // Get a new editor to clear default quality state
     73        unset( $editor );
     74        $editor = wp_get_image_editor( DIR_TESTDATA . '/images/canola.jpg' );
     75        $editor->set_mime_type( "image/jpeg" ); // Ensure mime-specific filters act properly.
     76
     77        // Ensure jpeg_quality filter applies if it exists before editor instantiation.
     78        $this->assertEquals( 95, $editor->get_quality() );
     79
     80        // Get a new editor to clear jpeg_quality state
     81        remove_filter( 'jpeg_quality', $func_95_percent );
     82        unset( $editor );
     83        $editor = wp_get_image_editor( DIR_TESTDATA . '/images/canola.jpg' );
     84
     85        // Ensure wp_editor_set_quality filter applies if it exists before editor instantiation.
     86        $this->assertEquals( 100, $editor->get_quality() );
    6787
    6888        // Clean up
    69         remove_filter( 'wp_editor_set_quality', $func );
     89        remove_filter( 'wp_editor_set_quality', $func_100_percent );
    7090    }
    7191
Note: See TracChangeset for help on using the changeset viewer.