WordPress.org

Make WordPress Core

Changeset 1123 in tests


Ignore:
Timestamp:
11/09/12 20:19:18 (18 months ago)
Author:
markoheijnen
Message:

Fix unit tests for WP_Image_Editor. After changes of ticket #WP6821

Location:
trunk/tests/image
Files:
4 added
2 edited

Legend:

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

    r1099 r1123  
    3333 
    3434        // Override the filters to set our own image editor 
    35         add_filter( 'image_editor_class', array( $this, 'image_editor_class' ) ); 
    36         add_filter( 'wp_editors', array( $this, 'wp_editors' ) ); 
    37  
    38         // Un-cache the chosen image implementation 
    39         $this->_uncache_implementation(); 
     35        add_filter( 'wp_image_editor_class', array( $this, 'image_editor_class' ) ); 
     36        add_filter( 'wp_image_editors', array( $this, 'wp_editors' ) ); 
    4037    } 
    4138 
     
    4441     */ 
    4542    public function tearDown() { 
    46         remove_filter( 'image_editor_class', array( $this, 'image_editor_class' ) ); 
    47         remove_filter( 'wp_editors', array( $this, 'wp_editors' ) ); 
    48     } 
    49  
    50     /** 
    51      * Unset the static implementation cache 
    52      */ 
    53     protected function _uncache_implementation() { 
    54         $class = new ReflectionClass( 'WP_Image_Editor' ); 
    55         $var = $class->getProperty( 'implementation' ); 
    56         $var->setAccessible( true ); 
    57         $var->setValue( $class, null ); 
     43        remove_filter( 'wp_image_editor_class', array( $this, 'image_editor_class' ) ); 
     44        remove_filter( 'wp_image_editors', array( $this, 'wp_editors' ) ); 
    5845    } 
    5946 
     
    6350     */ 
    6451    public function wp_editors() { 
    65         return array( preg_replace('/^WP_Image_Editor_/', '', get_class( $this->editor ) ) ); 
     52        return array( get_class( $this->editor ) ); 
    6653    } 
    6754 
     
    8269        // Swap out the PHPUnit mock with our custom mock 
    8370        $func = create_function( '', 'return "WP_Image_Editor_Mock";'); 
    84         remove_filter( 'image_editor_class', array( $this, 'image_editor_class' ) ); 
    85         add_filter( 'image_editor_class', $func ); 
     71        remove_filter( 'wp_image_editor_class', array( $this, 'image_editor_class' ) ); 
     72        add_filter( 'wp_image_editor_class', $func ); 
    8673 
    8774        // Set load() to return true 
     
    9582 
    9683        // Remove our custom Mock 
    97         remove_filter( 'image_editor_class', $func ); 
     84        remove_filter( 'wp_image_editor_class', $func ); 
    9885    } 
    9986 
     
    10693        // Swap out the PHPUnit mock with our custom mock 
    10794        $func = create_function( '', 'return "WP_Image_Editor_Mock";'); 
    108         remove_filter( 'image_editor_class', array( $this, 'image_editor_class' ) ); 
    109         add_filter( 'image_editor_class', $func ); 
     95        remove_filter( 'wp_image_editor_class', array( $this, 'image_editor_class' ) ); 
     96        add_filter( 'wp_image_editor_class', $func ); 
    11097 
    11198        // Set load() to return true 
     
    119106 
    120107        // Remove our custom Mock 
    121         remove_filter( 'image_editor_class', $func ); 
    122     } 
    123  
    124     /** 
    125      * Test the "test" method 
    126      * @ticket 6821 
    127      */ 
    128     public function test_test_returns_true() { 
    129  
    130         // $editor::test() returns true 
    131         $this->editor->staticExpects( $this->once() ) 
    132                      ->method( 'test' ) 
    133                      ->will( $this->returnValue( true ) ); 
    134  
    135         // Load an image 
    136         $editor = WP_Image_Editor::get_instance( DIR_TESTDATA . '/images/canola.jpg' ); 
    137  
    138         // Everything should work 
    139         $this->assertInstanceOf( get_class( $this->editor ), $editor ); 
    140     } 
    141  
    142     /** 
    143      * Test the "test" method returns false and the fallback editor is chosen 
    144      * @ticket 6821 
    145      */ 
    146     public function test_test_returns_false() { 
    147  
    148         // $editor::test() returns true 
    149         $this->editor->staticExpects( $this->once() ) 
    150                      ->method( 'test' ) 
    151                      ->will( $this->returnValue( false ) ); 
    152  
    153         // Set a fallback editor 
    154         $className = preg_replace('/^WP_Image_Editor_/', '', get_class( $this->editor ) ); 
    155         $func = create_function( '', "return array('$className', 'Mock');" ); 
    156         remove_filter( 'wp_editors', array( $this, 'wp_editors' ) ); 
    157         remove_filter( 'image_editor_class', array( $this, 'image_editor_class' ) ); 
    158         add_filter( 'wp_editors', $func ); 
    159  
    160         // Load an image 
    161         WP_Image_Editor_Mock::$load_return = true; 
    162         $editor = WP_Image_Editor::get_instance( DIR_TESTDATA . '/images/canola.jpg' ); 
    163  
    164         // Everything should work 
    165         $this->assertInstanceOf( 'WP_Image_Editor_Mock', $editor ); 
    166  
    167         // Unhook 
    168         remove_filter( 'image_editor_class', '__return_null' ); 
    169         remove_filter( 'wp_editors', $func ); 
     108        remove_filter( 'wp_image_editor_class', $func ); 
    170109    } 
    171110 
     
    256195     */ 
    257196    public function test_get_suffix() { 
    258  
    259197        $editor = WP_Image_Editor::get_instance( DIR_TESTDATA . '/images/canola.jpg' ); 
    260198 
  • trunk/tests/image/resize.php

    r1075 r1123  
    66 * @group upload 
    77 */ 
    8 class Tests_Image_Resize extends WP_UnitTestCase { 
     8abstract class WP_Tests_Image_Resize_UnitTestCase extends WP_Image_UnitTestCase { 
    99    // image_resize( $file, $max_w, $max_h, $crop=false, $suffix=null, $dest_path=null, $jpeg_quality=75) 
    10  
    11     function setUp() { 
    12         if ( ! extension_loaded( 'gd' ) ) 
    13             $this->markTestSkipped( 'The gd PHP extension is not loaded.' ); 
    14         parent::setUp(); 
    15     } 
    1610 
    1711    function test_resize_jpg() { 
     
    129123     */ 
    130124    public function test_resize_non_existent_image() { 
    131         $classes = array('WP_Image_Editor_GD', 'WP_Image_Editor_Imagick'); 
    132         foreach ( $classes as $class ) { 
    133             if ( ! call_user_func( array( $class, 'test' ) ) ) { 
    134                 continue; 
    135             } 
    136             $filter = create_function( '', "return '$class';" ); 
    137             add_filter( 'image_editor_class', $filter ); 
    138             $image = image_resize( DIR_TESTDATA.'/images/test-non-existent-image.jpg', 25, 25 ); 
    139             $this->assertInstanceOf( 'WP_Error', $image ); 
    140             $this->assertEquals( 'error_loading_image', $image->get_error_code() ); 
    141         } 
     125        $image = image_resize( DIR_TESTDATA.'/images/test-non-existent-image.jpg', 25, 25 ); 
     126        $this->assertInstanceOf( 'WP_Error', $image ); 
     127        $this->assertEquals( 'error_loading_image', $image->get_error_code() ); 
    142128    } 
    143129     
     
    147133     */ 
    148134    public function test_resize_bad_image() { 
    149         $classes = array('WP_Image_Editor_GD', 'WP_Image_Editor_Imagick'); 
    150         foreach ( $classes as $class ) { 
    151             if ( ! call_user_func( array( $class, 'test' ) ) ) { 
    152                 continue; 
    153             } 
    154             $filter = create_function( '', "return '$class';" ); 
    155             add_filter( 'image_editor_class', $filter ); 
    156             $image = image_resize( DIR_TESTDATA.'/export/crazy-cdata.xml', 25, 25 ); 
    157             $this->assertInstanceOf( 'WP_Error', $image ); 
    158             $this->assertEquals( 'invalid_image', $image->get_error_code() ); 
    159         } 
     135        $image = image_resize( DIR_TESTDATA.'/export/crazy-cdata.xml', 25, 25 ); 
     136        $this->assertInstanceOf( 'WP_Error', $image ); 
     137        $this->assertEquals( 'invalid_image', $image->get_error_code() ); 
    160138    } 
    161139} 
Note: See TracChangeset for help on using the changeset viewer.