mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-11 12:20:22 +00:00
Tests: Move the test for wp_save_image_file() with a GD resource to a more appropriate place.
When passed a GD resource as `$image`, `wp_save_image_file()` should throw a deprecated argument notice:
{{{
Function wp_save_image_file was called with an argument that is deprecated since version 3.5.0!
$image needs to be a WP_Image_Editor object.
}}}
The test verifies that the notice is thrown as expected.
Includes:
* Removing the `Tests_Functions_Deprecated` class. It appears to be initially intended for testing deprecated functions or arguments, but this was later superseded by the `@expectedDeprecated` annotation.
* Removing a redundant test for `wp_save_image_file()` **not** throwing a deprecation notice when passed a `WP_Image_Editor` instance. This is already covered by `test_wp_save_image_file()`, which would fail if there is an unexpected deprecation notice.
Follow-up to [1061/tests], [25408], [25409], [53529].
See #56793.
git-svn-id: https://develop.svn.wordpress.org/trunk@55066 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -1,185 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Test cases for deprecated functions, arguments, and files
|
||||
*
|
||||
* @package WordPress
|
||||
* @subpackage Unit Tests
|
||||
*
|
||||
* @since 3.5.0
|
||||
*
|
||||
* @group functions.php
|
||||
* @group deprecated
|
||||
*/
|
||||
class Tests_Functions_Deprecated extends WP_UnitTestCase {
|
||||
|
||||
/**
|
||||
* List of functions that have been passed through _deprecated_function().
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $_deprecated_functions = array();
|
||||
|
||||
/**
|
||||
* List of arguments that have been passed through _deprecated_argument().
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $_deprecated_arguments = array();
|
||||
|
||||
/**
|
||||
* List of files that have been passed through _deprecated_file().
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $_deprecated_files = array();
|
||||
|
||||
/**
|
||||
* Sets up the test fixture.
|
||||
*/
|
||||
public function set_up() {
|
||||
parent::set_up();
|
||||
$this->_deprecated_functions = array();
|
||||
$this->_deprecated_arguments = array();
|
||||
$this->_deprecated_files = array();
|
||||
add_action( 'deprecated_function_run', array( $this, 'deprecated_function' ), 10, 3 );
|
||||
add_action( 'deprecated_function_trigger_error', '__return_false' );
|
||||
add_action( 'deprecated_argument_run', array( $this, 'deprecated_argument' ), 10, 3 );
|
||||
add_action( 'deprecated_argument_trigger_error', '__return_false' );
|
||||
add_action( 'deprecated_file_included', array( $this, 'deprecated_file' ), 10, 4 );
|
||||
add_action( 'deprecated_file_trigger_error', '__return_false' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the test fixture.
|
||||
*/
|
||||
public function tear_down() {
|
||||
remove_action( 'deprecated_function_run', array( $this, 'deprecated_function' ), 10, 3 );
|
||||
remove_action( 'deprecated_function_trigger_error', '__return_false' );
|
||||
remove_action( 'deprecated_argument_run', array( $this, 'deprecated_argument' ), 10, 3 );
|
||||
remove_action( 'deprecated_argument_trigger_error', '__return_false' );
|
||||
remove_action( 'deprecated_file_included', array( $this, 'deprecated_argument' ), 10, 4 );
|
||||
remove_action( 'deprecated_file_trigger_error', '__return_false' );
|
||||
parent::tear_down();
|
||||
}
|
||||
|
||||
/**
|
||||
* Catches functions that have passed through _deprecated_function().
|
||||
*
|
||||
* @param string $function_name
|
||||
* @param string $replacement
|
||||
* @param float $version
|
||||
*/
|
||||
public function deprecated_function( $function_name, $replacement, $version ) {
|
||||
$this->_deprecated_functions[] = array(
|
||||
'function' => $function_name,
|
||||
'replacement' => $replacement,
|
||||
'version' => $version,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Catches arguments that have passed through _deprecated_argument().
|
||||
*
|
||||
* @param string $argument
|
||||
* @param string $message
|
||||
* @param float $version
|
||||
*/
|
||||
public function deprecated_argument( $argument, $message, $version ) {
|
||||
$this->_deprecated_arguments[] = array(
|
||||
'argument' => $argument,
|
||||
'message' => $message,
|
||||
'version' => $version,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Catches arguments that have passed through _deprecated_argument().
|
||||
*
|
||||
* @param string $argument
|
||||
* @param string $message
|
||||
* @param float $version
|
||||
*/
|
||||
public function deprecated_file( $file, $version, $replacement, $message ) {
|
||||
$this->_deprecated_files[] = array(
|
||||
'file' => $file,
|
||||
'version' => $version,
|
||||
'replacement' => $replacement,
|
||||
'message' => $message,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if something was deprecated.
|
||||
*
|
||||
* @param string $type argument|function|file
|
||||
* @param string $name
|
||||
* @return array|false
|
||||
*/
|
||||
protected function was_deprecated( $type, $name ) {
|
||||
switch ( $type ) {
|
||||
case 'argument':
|
||||
$search = $this->_deprecated_arguments;
|
||||
$key = 'argument';
|
||||
break;
|
||||
case 'function':
|
||||
$search = $this->_deprecated_functions;
|
||||
$key = 'function';
|
||||
break;
|
||||
default:
|
||||
$search = $this->_deprecated_files;
|
||||
$key = 'file';
|
||||
}
|
||||
foreach ( $search as $v ) {
|
||||
if ( $name === $v[ $key ] ) {
|
||||
return $v;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that wp_save_image_file() has a deprecated argument when passed a GD resource.
|
||||
*
|
||||
* @ticket 6821
|
||||
* @expectedDeprecated wp_save_image_file
|
||||
* @requires function imagejpeg
|
||||
*
|
||||
* @covers ::wp_save_image_file
|
||||
*/
|
||||
public function test_wp_save_image_file_deprecated_with_gd_resource() {
|
||||
// Call wp_save_image_file().
|
||||
require_once ABSPATH . 'wp-admin/includes/image-edit.php';
|
||||
$file = wp_tempnam();
|
||||
$img = imagecreatefromjpeg( DIR_TESTDATA . '/images/canola.jpg' );
|
||||
wp_save_image_file( $file, $img, 'image/jpeg', 1 );
|
||||
imagedestroy( $img );
|
||||
unlink( $file );
|
||||
|
||||
// Check if the arg was deprecated.
|
||||
$check = $this->was_deprecated( 'argument', 'wp_save_image_file' );
|
||||
$this->assertNotEmpty( $check );
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that wp_save_image_file() doesn't have a deprecated argument when passed a WP_Image_Editor.
|
||||
*
|
||||
* @ticket 6821
|
||||
* @requires function imagejpeg
|
||||
*
|
||||
* @covers ::wp_save_image_file
|
||||
*/
|
||||
public function test_wp_save_image_file_not_deprecated_with_wp_image_editor() {
|
||||
// Call wp_save_image_file().
|
||||
require_once ABSPATH . 'wp-admin/includes/image-edit.php';
|
||||
$file = wp_tempnam();
|
||||
$img = wp_get_image_editor( DIR_TESTDATA . '/images/canola.jpg' );
|
||||
wp_save_image_file( $file, $img, 'image/jpeg', 1 );
|
||||
unset( $img );
|
||||
unlink( $file );
|
||||
|
||||
// Check if the arg was deprecated.
|
||||
$check = $this->was_deprecated( 'argument', 'wp_save_image_file' );
|
||||
$this->assertFalse( $check );
|
||||
}
|
||||
}
|
||||
@@ -327,6 +327,29 @@ class Tests_Image_Functions extends WP_UnitTestCase {
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that wp_save_image_file() throws a deprecated argument notice when passed a GD resource.
|
||||
*
|
||||
* @ticket 6821
|
||||
* @expectedDeprecated wp_save_image_file
|
||||
* @requires function imagejpeg
|
||||
*
|
||||
* @covers ::wp_save_image_file
|
||||
*/
|
||||
public function test_wp_save_image_file_deprecated_argument_with_gd_resource() {
|
||||
require_once ABSPATH . 'wp-admin/includes/image-edit.php';
|
||||
|
||||
// Call wp_save_image_file().
|
||||
$file = wp_tempnam();
|
||||
$img = imagecreatefromjpeg( DIR_TESTDATA . '/images/canola.jpg' );
|
||||
$ret = wp_save_image_file( $file, $img, 'image/jpeg', 1 );
|
||||
|
||||
imagedestroy( $img );
|
||||
unlink( $file );
|
||||
|
||||
$this->assertTrue( $ret, 'Image failed to save.' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that a passed mime type overrides the extension in the filename when saving an image.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user