From a76e6cef7dd83c150c1dfab7dcb08f89243cb005 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Thu, 12 Sep 2013 04:40:13 +0000 Subject: [PATCH] * Avoid notice by making `WP_Image_Editor_Mock::test()` compatible with `WP_Image_Editor::test()`. * Suppress deprecated function notice for `wp_load_image()`. * Add assertion for `wp_get_image_editor()`. See #25282. git-svn-id: https://develop.svn.wordpress.org/trunk@25380 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/includes/mock-image-editor.php | 2 +- tests/phpunit/tests/image/functions.php | 27 +++++++++++++++++--- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/tests/phpunit/includes/mock-image-editor.php b/tests/phpunit/includes/mock-image-editor.php index 2d8164e5c9..808b32dfc3 100644 --- a/tests/phpunit/includes/mock-image-editor.php +++ b/tests/phpunit/includes/mock-image-editor.php @@ -11,7 +11,7 @@ if (class_exists( 'WP_Image_Editor' ) ) : public function load() { return self::$load_return; } - public static function test() { + public static function test( $args = array() ) { return self::$test_return; } public static function supports_mime_type( $mime_type ) { diff --git a/tests/phpunit/tests/image/functions.php b/tests/phpunit/tests/image/functions.php index 3982f7bc5a..2b5b1d7245 100644 --- a/tests/phpunit/tests/image/functions.php +++ b/tests/phpunit/tests/image/functions.php @@ -9,12 +9,30 @@ class Tests_Image_Functions extends WP_UnitTestCase { /** * Setup test fixture */ - public function setup() { + public function setUp() { + parent::setUp(); + require_once( ABSPATH . WPINC . '/class-wp-image-editor.php' ); require_once( ABSPATH . WPINC . '/class-wp-image-editor-gd.php' ); require_once( ABSPATH . WPINC . '/class-wp-image-editor-imagick.php' ); include_once( DIR_TESTDATA . '/../includes/mock-image-editor.php' ); + add_action( 'deprecated_function_run', array( $this, 'deprecated_function_run' ) ); + } + + function tearDown() { + parent::tearDown(); + remove_action( 'deprecated_function_run', array( $this, 'deprecated_function_run' ) ); + } + + function deprecated_function_run( $function ) { + if ( in_array( $function, array( 'wp_load_image' ) ) ) + add_filter( 'deprecated_function_trigger_error', array( $this, 'deprecated_function_trigger_error' ) ); + } + + function deprecated_function_trigger_error() { + remove_filter( 'deprecated_function_trigger_error', array( $this, 'deprecated_function_trigger_error' ) ); + return false; } /** @@ -236,8 +254,11 @@ class Tests_Image_Functions extends WP_UnitTestCase { public function test_load_directory() { // First, test with deprecated wp_load_image function - $editor = wp_load_image( DIR_TESTDATA ); - $this->assertNotInternalType( 'resource', $editor ); + $editor1 = wp_load_image( DIR_TESTDATA ); + $this->assertNotInternalType( 'resource', $editor1 ); + + $editor2 = wp_get_image_editor( DIR_TESTDATA ); + $this->assertNotInternalType( 'resource', $editor2 ); // Then, test with editors. $classes = array('WP_Image_Editor_GD', 'WP_Image_Editor_Imagick');