Ticket #6821: 6821-ut.2.diff

File 6821-ut.2.diff, 2.2 KB (added by ryan, 6 months ago)

Basic wp_crop_image() tests.

  • tests/image/functions.php

     
    242242                        $this->assertEquals( 'error_loading_image', $editor->get_error_code() ); 
    243243                } 
    244244        } 
     245 
     246        public function test_wp_crop_image_file() { 
     247                $file = wp_crop_image( DIR_TESTDATA . '/images/canola.jpg', 
     248                                                          0, 0, 100, 100, 100, 100 ); 
     249                $this->assertNotInstanceOf( 'WP_Error', $file ); 
     250                $this->assertFileExists( $file ); 
     251                $image = WP_Image_Editor::get_instance( $file ); 
     252                $size = $image->get_size(); 
     253                $this->assertEquals( 100, $size['height'] ); 
     254                $this->assertEquals( 100, $size['width'] ); 
     255        } 
     256 
     257        public function test_wp_crop_image_url() { 
     258                $file = wp_crop_image( 'http://asdftestblog1.files.wordpress.com/2008/04/canola.jpg', 
     259                                                          0, 0, 100, 100, 100, 100, false, 
     260                                                          DIR_TESTDATA . '/images/' . rand_str() . '.jpg' ); 
     261                $this->assertNotInstanceOf( 'WP_Error', $file ); 
     262                $this->assertFileExists( $file ); 
     263                $image = WP_Image_Editor::get_instance( $file ); 
     264                $size = $image->get_size(); 
     265                $this->assertEquals( 100, $size['height'] ); 
     266                $this->assertEquals( 100, $size['width'] ); 
     267        } 
     268 
     269        public function test_wp_crop_image_file_not_exist() { 
     270                $file = wp_crop_image( DIR_TESTDATA . '/images/canoladoesnotexist.jpg', 
     271                                                          0, 0, 100, 100, 100, 100 ); 
     272                $this->assertInstanceOf( 'WP_Error', $file ); 
     273        } 
     274 
     275        public function test_wp_crop_image_url_not_exist() { 
     276                $file = wp_crop_image( 'http://asdftestblog1.files.wordpress.com/2008/04/canoladoesnotexist.jpg', 
     277                                                          0, 0, 100, 100, 100, 100 ); 
     278                $this->assertInstanceOf( 'WP_Error', $file ); 
     279        } 
    245280} 
  • includes/mock-image-editor.php

     
    1010                protected function load() { 
    1111                        return self::$load_return; 
    1212                } 
    13                 public function test() { 
     13                public static function test() { 
    1414                        return self::$test_return; 
    1515                } 
    16                 public function supports_mime_type( $mime_type ) { 
     16                public static function supports_mime_type( $mime_type ) { 
    1717                        return true; 
    1818                } 
    1919                public function resize( $max_w, $max_h, $crop = false ) {