diff --git includes/mock-image-editor.php includes/mock-image-editor.php
index c7d0a5a..3722e22 100644
|
|
|
if (class_exists( 'WP_Image_Editor' ) ) : |
| 7 | 7 | public static $load_return = true; |
| 8 | 8 | public static $test_return = true; |
| 9 | 9 | |
| 10 | | protected function load() { |
| | 10 | public function load() { |
| 11 | 11 | return self::$load_return; |
| 12 | 12 | } |
| 13 | 13 | public static function test() { |
| … |
… |
if (class_exists( 'WP_Image_Editor' ) ) : |
| 39 | 39 | } |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | | endif; |
| 43 | | No newline at end of file |
| | 42 | endif; |
diff --git tests/image/editor.php tests/image/editor.php
index 2000e67..51d88d2 100644
|
|
|
class Tests_Image_Editor extends WP_UnitTestCase { |
| 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 mock |
| 24 | 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 |
| … |
… |
class Tests_Image_Editor extends WP_UnitTestCase { |
| 61 | 59 | } |
| 62 | 60 | |
| 63 | 61 | /** |
| 64 | | * Test get_instance where load returns true |
| | 62 | * 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";'); |
| … |
… |
class Tests_Image_Editor extends WP_UnitTestCase { |
| 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 ); |
| … |
… |
class Tests_Image_Editor extends WP_UnitTestCase { |
| 85 | 83 | } |
| 86 | 84 | |
| 87 | 85 | /** |
| 88 | | * Test get_instance where load returns false |
| | 86 | * 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";'); |
| … |
… |
class Tests_Image_Editor extends WP_UnitTestCase { |
| 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 ); |
| … |
… |
class Tests_Image_Editor extends WP_UnitTestCase { |
| 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' ); |
| … |
… |
class Tests_Image_Editor extends WP_UnitTestCase { |
| 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( |
| … |
… |
class Tests_Image_Editor extends WP_UnitTestCase { |
| 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() ); |
| … |
… |
class Tests_Image_Editor extends WP_UnitTestCase { |
| 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() ); |