Changeset 1157 in tests
- Timestamp:
- 11/26/2012 11:55:36 PM (14 years ago)
- Location:
- trunk/tests/image
- Files:
-
- 3 edited
-
base.php (modified) (3 diffs)
-
editor.php (modified) (4 diffs)
-
functions.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/image/base.php
r1153 r1157 10 10 */ 11 11 public function setUp() { 12 $class = $this->editor_engine; 13 if ( ! call_user_func( array( $class, 'test' ) ) ) { 12 if ( ! call_user_func( array( $this->editor_engine, 'test' ) ) ) { 14 13 $this->markTestSkipped( sprintf('The image editor engine %s is not supported on this system', $this->editor_engine) ); 15 14 } 16 add_filter( 'wp_image_editor_class', array( $this, 'setEngine') ); 15 16 add_filter( 'wp_image_editors', array( $this, 'setEngine' ), 10, 2 ); 17 17 } 18 18 … … 21 21 */ 22 22 public function tearDown() { 23 remove_filter( 'wp_image_editor _class', array( $this, 'setEngine' ));23 remove_filter( 'wp_image_editors', array( $this, 'setEngine' ), 10, 2 ); 24 24 } 25 25 … … 28 28 * @return string 29 29 */ 30 public function setEngine( ) {31 return $this->editor_engine;30 public function setEngine( $editors ) { 31 return array( $this->editor_engine ); 32 32 } 33 33 } -
trunk/tests/image/editor.php
r1152 r1157 6 6 * @group media 7 7 */ 8 class Tests_Image_Editor extends WP_UnitTestCase { 9 10 /** 11 * Image editor 12 * @var WP_Image_Editor 13 */ 14 protected $editor = null; 8 class Tests_Image_Editor extends WP_Image_UnitTestCase { 9 public $editor_engine = 'WP_Image_Editor_Mock'; 15 10 16 11 /** … … 22 17 include_once( DIR_TESTDATA . '/../includes/mock-image-editor.php' ); 23 18 24 // Mock up an abstract image editor based on WP_Image_Editor 25 // note: this *HAS* to start with 'WP_Image_Editor_' 26 $className = 'WP_Image_Editor_' . substr( md5( uniqid() ), -12 ); 27 $this->editor = $this->getMockForAbstractClass( 'WP_Image_Editor', array( 28 'get_size', 29 'get_suffix' 30 ), $className, false ); 31 32 // Override the filters to set our own image editor 33 add_filter( 'wp_image_editor_class', array( $this, 'image_editor_class' ) ); 34 } 35 36 /** 37 * Tear down test fixture 38 */ 39 public function tearDown() { 40 remove_filter( 'wp_image_editor_class', array( $this, 'image_editor_class' ) ); 41 } 42 43 /** 44 * Override the image_editor_class filter 45 * @return mixed 46 */ 47 public function image_editor_class() { 48 return get_class( $this->editor ); 19 parent::setUp(); 49 20 } 50 21 … … 54 25 */ 55 26 public function test_get_editor_load_returns_true() { 56 57 // Swap out the PHPUnit mock with our custom mock58 $func = create_function( '', 'return "WP_Image_Editor_Mock";');59 remove_filter( 'wp_image_editor_class', array( $this, 'image_editor_class' ) );60 add_filter( 'wp_image_editor_class', $func );61 62 // Set load() to return true63 WP_Image_Editor_Mock::$load_return = true;64 65 // Load an image66 27 $editor = wp_get_image_editor( DIR_TESTDATA . '/images/canola.jpg' ); 67 28 68 // Everything should work69 29 $this->assertInstanceOf( 'WP_Image_Editor_Mock', $editor ); 70 71 // Remove our custom Mock72 remove_filter( 'wp_image_editor_class', $func );73 30 } 74 31 … … 78 35 */ 79 36 public function test_get_editor_load_returns_false() { 80 81 // Swap out the PHPUnit mock with our custom mock82 $func = create_function( '', 'return "WP_Image_Editor_Mock";');83 remove_filter( 'wp_image_editor_class', array( $this, 'image_editor_class' ) );84 add_filter( 'wp_image_editor_class', $func );85 86 // Set load() to return true87 37 WP_Image_Editor_Mock::$load_return = new WP_Error(); 88 38 89 // Load an image90 39 $editor = wp_get_image_editor( DIR_TESTDATA . '/images/canola.jpg' ); 91 40 92 // Everything should work93 41 $this->assertInstanceOf( 'WP_Error', $editor ); 94 42 95 // Remove our custom Mock 96 remove_filter( 'wp_image_editor_class', $func ); 43 WP_Image_Editor_Mock::$load_return = true; 97 44 } 98 45 -
trunk/tests/image/functions.php
r1154 r1157 126 126 continue; 127 127 } 128 $filter = create_function( '', "return '$class';" ); 129 add_filter( 'wp_image_editor_class', $filter ); 130 131 // Call wp_save_image_file 132 $img = wp_get_image_editor( DIR_TESTDATA . '/images/canola.jpg' ); 128 129 $img = new $class( DIR_TESTDATA . '/images/canola.jpg' ); 130 $loaded = $img->load(); 133 131 134 132 // Save a file as each mime type, assert it works … … 164 162 continue; 165 163 } 166 $filter = create_function( '', "return '$class';" ); 167 add_filter( 'wp_image_editor_class', $filter ); 164 165 $img = new $class( DIR_TESTDATA . '/images/canola.jpg' ); 166 $loaded = $img->load(); 168 167 169 168 // Save the file 170 $img = wp_get_image_editor( DIR_TESTDATA . '/images/canola.jpg' );171 169 $mime_type = 'image/gif'; 172 170 $file = wp_tempnam( 'tmp.jpg' ); … … 209 207 continue; 210 208 } 211 $filter = create_function( '', "return '$class';" ); 212 add_filter( 'wp_image_editor_class', $filter ); 209 210 $img = new $class( DIR_TESTDATA . '/images/canola.jpg' ); 211 $loaded = $img->load(); 213 212 214 213 // Save the image as each file extension, check the mime type … … 243 242 $classes = array('WP_Image_Editor_GD', 'WP_Image_Editor_Imagick'); 244 243 foreach ( $classes as $class ) { 245 if ( ! call_user_func( array( $class, 'test' ) ) ) { 246 continue; 247 } 248 $filter = create_function( '', "return '$class';" ); 249 add_filter( 'wp_image_editor_class', $filter ); 250 $editor = wp_get_image_editor( DIR_TESTDATA ); 251 $this->assertInstanceOf( 'WP_Error', $editor ); 252 $this->assertEquals( 'error_loading_image', $editor->get_error_code() ); 244 // If the image editor isn't available, skip it 245 if ( ! call_user_func( array( $class, 'test' ) ) ) { 246 continue; 247 } 248 249 $editor = new $class( DIR_TESTDATA ); 250 $loaded = $editor->load(); 251 252 $this->assertInstanceOf( 'WP_Error', $loaded ); 253 $this->assertEquals( 'error_loading_image', $loaded->get_error_code() ); 253 254 } 254 255 }
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)