| 1 | diff --git includes/mock-image-editor.php includes/mock-image-editor.php |
|---|
| 2 | index c7d0a5a..3722e22 100644 |
|---|
| 3 | --- includes/mock-image-editor.php |
|---|
| 4 | +++ includes/mock-image-editor.php |
|---|
| 5 | @@ -7,7 +7,7 @@ if (class_exists( 'WP_Image_Editor' ) ) : |
|---|
| 6 | public static $load_return = true; |
|---|
| 7 | public static $test_return = true; |
|---|
| 8 | |
|---|
| 9 | - protected function load() { |
|---|
| 10 | + public function load() { |
|---|
| 11 | return self::$load_return; |
|---|
| 12 | } |
|---|
| 13 | public static function test() { |
|---|
| 14 | @@ -39,4 +39,4 @@ if (class_exists( 'WP_Image_Editor' ) ) : |
|---|
| 15 | } |
|---|
| 16 | } |
|---|
| 17 | |
|---|
| 18 | -endif; |
|---|
| 19 | \ No newline at end of file |
|---|
| 20 | +endif; |
|---|
| 21 | diff --git tests/image/editor.php tests/image/editor.php |
|---|
| 22 | index 2000e67..51d88d2 100644 |
|---|
| 23 | --- tests/image/editor.php |
|---|
| 24 | +++ tests/image/editor.php |
|---|
| 25 | @@ -17,10 +17,8 @@ class Tests_Image_Editor extends WP_UnitTestCase { |
|---|
| 26 | * Setup test fixture |
|---|
| 27 | */ |
|---|
| 28 | public function setup() { |
|---|
| 29 | - if ( !class_exists( 'WP_Image_Editor' ) ) |
|---|
| 30 | - $this->markTestSkipped(); |
|---|
| 31 | + require_once( ABSPATH . WPINC . '/class-wp-image-editor.php' ); |
|---|
| 32 | |
|---|
| 33 | - // Include our custom mock |
|---|
| 34 | include_once( DIR_TESTDATA . '/../includes/mock-image-editor.php' ); |
|---|
| 35 | |
|---|
| 36 | // Mock up an abstract image editor based on WP_Image_Editor |
|---|
| 37 | @@ -61,10 +59,10 @@ class Tests_Image_Editor extends WP_UnitTestCase { |
|---|
| 38 | } |
|---|
| 39 | |
|---|
| 40 | /** |
|---|
| 41 | - * Test get_instance where load returns true |
|---|
| 42 | + * Test wp_get_image_editor() where load returns true |
|---|
| 43 | * @ticket 6821 |
|---|
| 44 | */ |
|---|
| 45 | - public function test_get_instance_load_returns_true() { |
|---|
| 46 | + public function test_get_editor_load_returns_true() { |
|---|
| 47 | |
|---|
| 48 | // Swap out the PHPUnit mock with our custom mock |
|---|
| 49 | $func = create_function( '', 'return "WP_Image_Editor_Mock";'); |
|---|
| 50 | @@ -75,7 +73,7 @@ class Tests_Image_Editor extends WP_UnitTestCase { |
|---|
| 51 | WP_Image_Editor_Mock::$load_return = true; |
|---|
| 52 | |
|---|
| 53 | // Load an image |
|---|
| 54 | - $editor = WP_Image_Editor::get_instance( DIR_TESTDATA . '/images/canola.jpg' ); |
|---|
| 55 | + $editor = wp_get_image_editor( DIR_TESTDATA . '/images/canola.jpg' ); |
|---|
| 56 | |
|---|
| 57 | // Everything should work |
|---|
| 58 | $this->assertInstanceOf( 'WP_Image_Editor_Mock', $editor ); |
|---|
| 59 | @@ -85,10 +83,10 @@ class Tests_Image_Editor extends WP_UnitTestCase { |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | /** |
|---|
| 63 | - * Test get_instance where load returns false |
|---|
| 64 | + * Test wp_get_image_editor() where load returns false |
|---|
| 65 | * @ticket 6821 |
|---|
| 66 | */ |
|---|
| 67 | - public function test_get_instance_load_returns_false() { |
|---|
| 68 | + public function test_get_editor_load_returns_false() { |
|---|
| 69 | |
|---|
| 70 | // Swap out the PHPUnit mock with our custom mock |
|---|
| 71 | $func = create_function( '', 'return "WP_Image_Editor_Mock";'); |
|---|
| 72 | @@ -99,7 +97,7 @@ class Tests_Image_Editor extends WP_UnitTestCase { |
|---|
| 73 | WP_Image_Editor_Mock::$load_return = new WP_Error(); |
|---|
| 74 | |
|---|
| 75 | // Load an image |
|---|
| 76 | - $editor = WP_Image_Editor::get_instance( DIR_TESTDATA . '/images/canola.jpg' ); |
|---|
| 77 | + $editor = wp_get_image_editor( DIR_TESTDATA . '/images/canola.jpg' ); |
|---|
| 78 | |
|---|
| 79 | // Everything should work |
|---|
| 80 | $this->assertInstanceOf( 'WP_Error', $editor ); |
|---|
| 81 | @@ -115,7 +113,7 @@ class Tests_Image_Editor extends WP_UnitTestCase { |
|---|
| 82 | public function test_set_quality() { |
|---|
| 83 | |
|---|
| 84 | // Get an editor |
|---|
| 85 | - $editor = WP_Image_Editor::get_instance( DIR_TESTDATA . '/images/canola.jpg' ); |
|---|
| 86 | + $editor = wp_get_image_editor( DIR_TESTDATA . '/images/canola.jpg' ); |
|---|
| 87 | |
|---|
| 88 | // Make quality readable |
|---|
| 89 | $property = new ReflectionProperty( $editor, 'quality' ); |
|---|
| 90 | @@ -142,7 +140,8 @@ class Tests_Image_Editor extends WP_UnitTestCase { |
|---|
| 91 | public function test_generate_filename() { |
|---|
| 92 | |
|---|
| 93 | // Get an editor |
|---|
| 94 | - $editor = WP_Image_Editor::get_instance( DIR_TESTDATA . '/images/canola.jpg' ); |
|---|
| 95 | + $editor = wp_get_image_editor( DIR_TESTDATA . '/images/canola.jpg' ); |
|---|
| 96 | + |
|---|
| 97 | $property = new ReflectionProperty( $editor, 'size' ); |
|---|
| 98 | $property->setAccessible( true ); |
|---|
| 99 | $property->setValue( $editor, array( |
|---|
| 100 | @@ -172,7 +171,7 @@ class Tests_Image_Editor extends WP_UnitTestCase { |
|---|
| 101 | */ |
|---|
| 102 | public function test_get_size() { |
|---|
| 103 | |
|---|
| 104 | - $editor = WP_Image_Editor::get_instance( DIR_TESTDATA . '/images/canola.jpg' ); |
|---|
| 105 | + $editor = wp_get_image_editor( DIR_TESTDATA . '/images/canola.jpg' ); |
|---|
| 106 | |
|---|
| 107 | // Size should be false by default |
|---|
| 108 | $this->assertNull( $editor->get_size() ); |
|---|
| 109 | @@ -194,7 +193,7 @@ class Tests_Image_Editor extends WP_UnitTestCase { |
|---|
| 110 | * @ticket 6821 |
|---|
| 111 | */ |
|---|
| 112 | public function test_get_suffix() { |
|---|
| 113 | - $editor = WP_Image_Editor::get_instance( DIR_TESTDATA . '/images/canola.jpg' ); |
|---|
| 114 | + $editor = wp_get_image_editor( DIR_TESTDATA . '/images/canola.jpg' ); |
|---|
| 115 | |
|---|
| 116 | // Size should be false by default |
|---|
| 117 | $this->assertFalse( $editor->get_suffix() ); |
|---|