Ticket #22356: 22356.9.tests.diff
File 22356.9.tests.diff, 6.9 KB (added by , 12 years ago) |
---|
-
tests/image/editor.php
17 17 * Setup test fixture 18 18 */ 19 19 public function setup() { 20 if ( !class_exists( 'WP_Image_Editor' ) ) 21 $this->markTestSkipped(); 20 require_once( ABSPATH . WPINC . '/class-wp-image-editor.php' ); 22 21 23 // Include our custom mock24 22 include_once( DIR_TESTDATA . '/../includes/mock-image-editor.php' ); 25 23 26 24 // Mock up an abstract image editor based on WP_Image_Editor … … 61 59 } 62 60 63 61 /** 64 * Test get_instancewhere load returns true62 * Test wp_get_image_editor() where load returns true 65 63 * @ticket 6821 66 64 */ 67 public function test_get_ instance_load_returns_true() {65 public function test_get_editor_load_returns_true() { 68 66 69 67 // Swap out the PHPUnit mock with our custom mock 70 68 $func = create_function( '', 'return "WP_Image_Editor_Mock";'); … … 75 73 WP_Image_Editor_Mock::$load_return = true; 76 74 77 75 // Load an image 78 $editor = WP_Image_Editor::get_instance( DIR_TESTDATA . '/images/canola.jpg' );76 $editor = wp_get_image_editor( DIR_TESTDATA . '/images/canola.jpg' ); 79 77 80 78 // Everything should work 81 79 $this->assertInstanceOf( 'WP_Image_Editor_Mock', $editor ); … … 85 83 } 86 84 87 85 /** 88 * Test get_instancewhere load returns false86 * Test wp_get_image_editor() where load returns false 89 87 * @ticket 6821 90 88 */ 91 public function test_get_ instance_load_returns_false() {89 public function test_get_editor_load_returns_false() { 92 90 93 91 // Swap out the PHPUnit mock with our custom mock 94 92 $func = create_function( '', 'return "WP_Image_Editor_Mock";'); … … 99 97 WP_Image_Editor_Mock::$load_return = new WP_Error(); 100 98 101 99 // Load an image 102 $editor = WP_Image_Editor::get_instance( DIR_TESTDATA . '/images/canola.jpg' );100 $editor = wp_get_image_editor( DIR_TESTDATA . '/images/canola.jpg' ); 103 101 104 102 // Everything should work 105 103 $this->assertInstanceOf( 'WP_Error', $editor ); … … 115 113 public function test_set_quality() { 116 114 117 115 // Get an editor 118 $editor = WP_Image_Editor::get_instance( DIR_TESTDATA . '/images/canola.jpg' );116 $editor = wp_get_image_editor( DIR_TESTDATA . '/images/canola.jpg' ); 119 117 120 118 // Make quality readable 121 119 $property = new ReflectionProperty( $editor, 'quality' ); … … 142 140 public function test_generate_filename() { 143 141 144 142 // Get an editor 145 $editor = WP_Image_Editor::get_instance( DIR_TESTDATA . '/images/canola.jpg' ); 143 $editor = wp_get_image_editor( DIR_TESTDATA . '/images/canola.jpg' ); 144 146 145 $property = new ReflectionProperty( $editor, 'size' ); 147 146 $property->setAccessible( true ); 148 147 $property->setValue( $editor, array( … … 172 171 */ 173 172 public function test_get_size() { 174 173 175 $editor = WP_Image_Editor::get_instance( DIR_TESTDATA . '/images/canola.jpg' );174 $editor = wp_get_image_editor( DIR_TESTDATA . '/images/canola.jpg' ); 176 175 177 176 // Size should be false by default 178 177 $this->assertNull( $editor->get_size() ); … … 194 193 * @ticket 6821 195 194 */ 196 195 public function test_get_suffix() { 197 $editor = WP_Image_Editor::get_instance( DIR_TESTDATA . '/images/canola.jpg' );196 $editor = wp_get_image_editor( DIR_TESTDATA . '/images/canola.jpg' ); 198 197 199 198 // Size should be false by default 200 199 $this->assertFalse( $editor->get_suffix() ); -
tests/image/functions.php
8 8 class Tests_Image_Functions extends WP_UnitTestCase { 9 9 10 10 /** 11 * Setup test fixture 12 */ 13 public function setup() { 14 require_once ABSPATH . WPINC . '/class-wp-image-editor.php'; 15 require_once ABSPATH . WPINC . '/class-wp-image-editor-gd.php'; 16 require_once ABSPATH . WPINC . '/class-wp-image-editor-imagick.php'; 17 } 18 19 /** 11 20 * Get the MIME type of a file 12 21 * @param string $filename 13 22 * @return string … … 120 129 add_filter( 'image_editor_class', $filter ); 121 130 122 131 // Call wp_save_image_file 123 $img = WP_Image_Editor::get_instance( DIR_TESTDATA . '/images/canola.jpg' );132 $img = wp_get_image_editor( DIR_TESTDATA . '/images/canola.jpg' ); 124 133 125 134 // Save a file as each mime type, assert it works 126 135 foreach ( $mime_types as $mime_type ) { … … 158 167 add_filter( 'image_editor_class', $filter ); 159 168 160 169 // Save the file 161 $img = WP_Image_Editor::get_instance( DIR_TESTDATA . '/images/canola.jpg' );170 $img = wp_get_image_editor( DIR_TESTDATA . '/images/canola.jpg' ); 162 171 $mime_type = 'image/gif'; 163 172 $file = wp_tempnam( 'tmp.jpg' ); 164 173 $ret = $img->save( $file, $mime_type ); … … 203 212 add_filter( 'image_editor_class', $filter ); 204 213 205 214 // Save the image as each file extension, check the mime type 206 $img = WP_Image_Editor::get_instance( DIR_TESTDATA . '/images/canola.jpg' );215 $img = wp_get_image_editor( DIR_TESTDATA . '/images/canola.jpg' ); 207 216 $temp = get_temp_dir(); 208 217 foreach ( $mime_types as $ext => $mime_type ) { 209 218 $file = wp_unique_filename( $temp, uniqid() . ".$ext" ); … … 225 234 * @ticket 17814 226 235 */ 227 236 public function test_load_directory() { 237 228 238 // First, test with deprecated wp_load_image function 229 239 $editor = wp_load_image( DIR_TESTDATA ); 230 240 $this->assertNotInternalType( 'resource', $editor ); … … 237 247 } 238 248 $filter = create_function( '', "return '$class';" ); 239 249 add_filter( 'image_editor_class', $filter ); 240 $editor = WP_Image_Editor::get_instance( DIR_TESTDATA );250 $editor = wp_get_image_editor( DIR_TESTDATA ); 241 251 $this->assertInstanceOf( 'WP_Error', $editor ); 242 252 $this->assertEquals( 'error_loading_image', $editor->get_error_code() ); 243 253 } … … 248 258 0, 0, 100, 100, 100, 100 ); 249 259 $this->assertNotInstanceOf( 'WP_Error', $file ); 250 260 $this->assertFileExists( $file ); 251 $image = WP_Image_Editor::get_instance( $file );261 $image = wp_get_image_editor( $file ); 252 262 $size = $image->get_size(); 253 263 $this->assertEquals( 100, $size['height'] ); 254 264 $this->assertEquals( 100, $size['width'] ); … … 260 270 DIR_TESTDATA . '/images/' . rand_str() . '.jpg' ); 261 271 $this->assertNotInstanceOf( 'WP_Error', $file ); 262 272 $this->assertFileExists( $file ); 263 $image = WP_Image_Editor::get_instance( $file );273 $image = wp_get_image_editor( $file ); 264 274 $size = $image->get_size(); 265 275 $this->assertEquals( 100, $size['height'] ); 266 276 $this->assertEquals( 100, $size['width'] ); -
includes/mock-image-editor.php
7 7 public static $load_return = true; 8 8 public static $test_return = true; 9 9 10 p rotectedfunction load() {10 public function load() { 11 11 return self::$load_return; 12 12 } 13 13 public static function test() { … … 39 39 } 40 40 } 41 41 42 endif; 43 No newline at end of file 42 endif;