Media: Deprecate the 'edit_custom_thumbnail_sizes' filter and disable the "Apply changes to [Thumbnail|All|All except thumbnail]" UI in the image editor. Add a (boolean) filter to reenable that UI.

Props peterwilsoncc, costdev, azaozz.
See: #57685.

git-svn-id: https://develop.svn.wordpress.org/trunk@55935 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Ozz
2023-06-18 14:22:40 +00:00
parent be7dc79427
commit bcb881c17f
4 changed files with 111 additions and 77 deletions
@@ -28,39 +28,6 @@ class Tests_Ajax_wpAjaxImageEditor extends WP_Ajax_UnitTestCase {
parent::tear_down();
}
/**
* @ticket 22985
* @requires function imagejpeg
*
* @covers ::wp_insert_attachment
* @covers ::wp_save_image
*/
public function testCropImageThumbnail() {
require_once ABSPATH . 'wp-admin/includes/image-edit.php';
$filename = DIR_TESTDATA . '/images/canola.jpg';
$contents = file_get_contents( $filename );
$upload = wp_upload_bits( wp_basename( $filename ), null, $contents );
$id = $this->_make_attachment( $upload );
$_REQUEST['action'] = 'image-editor';
$_REQUEST['context'] = 'edit-attachment';
$_REQUEST['postid'] = $id;
$_REQUEST['target'] = 'thumbnail';
$_REQUEST['do'] = 'save';
$_REQUEST['history'] = '[{"c":{"x":5,"y":8,"w":289,"h":322}}]';
$media_meta = wp_get_attachment_metadata( $id );
$this->assertArrayHasKey( 'sizes', $media_meta, 'attachment should have size data' );
$this->assertArrayHasKey( 'medium', $media_meta['sizes'], 'attachment should have data for medium size' );
$ret = wp_save_image( $id );
$media_meta = wp_get_attachment_metadata( $id );
$this->assertArrayHasKey( 'sizes', $media_meta, 'cropped attachment should have size data' );
$this->assertArrayHasKey( 'medium', $media_meta['sizes'], 'cropped attachment should have data for medium size' );
}
/**
* @ticket 26381
* @requires function imagejpeg
+85
View File
@@ -350,6 +350,91 @@ class Tests_Image_Functions extends WP_UnitTestCase {
$this->assertTrue( $ret, 'Image failed to save.' );
}
/**
* Tests that `wp_image_editor()` applies 'image_edit_thumbnails_separately' filters.
*
* @ticket 53161
*
* @covers ::wp_image_editor
*/
public function test_wp_image_editor_should_apply_image_edit_thumbnails_separately_filters() {
require_once ABSPATH . 'wp-admin/includes/image-edit.php';
$filename = DIR_TESTDATA . '/images/canola.jpg';
$contents = file_get_contents( $filename );
$upload = wp_upload_bits( wp_basename( $filename ), null, $contents );
$id = $this->_make_attachment( $upload );
$filter = new MockAction();
add_filter( 'image_edit_thumbnails_separately', array( &$filter, 'filter' ) );
ob_start();
wp_image_editor( $id );
ob_end_clean();
$this->assertSame( 1, $filter->get_call_count() );
}
/**
* Tests that `wp_image_editor()` conditionally outputs markup for editing thumbnails separately
* based on the result of applying 'image_edit_thumbnails_separately' filters.
*
* @ticket 53161
*
* @covers ::wp_image_editor
*
* @dataProvider data_wp_image_editor_should_respect_image_edit_thumbnails_separately_filters
*
* @param string $callback The name of the callback for the 'image_edit_thumbnails_separately' hook.
* @param bool $expected Whether the markup should be output.
*/
public function test_wp_image_editor_should_respect_image_edit_thumbnails_separately_filters( $callback, $expected ) {
require_once ABSPATH . 'wp-admin/includes/image-edit.php';
$filename = DIR_TESTDATA . '/images/canola.jpg';
$contents = file_get_contents( $filename );
$upload = wp_upload_bits( wp_basename( $filename ), null, $contents );
$id = $this->_make_attachment( $upload );
add_filter( 'image_edit_thumbnails_separately', $callback );
ob_start();
wp_image_editor( $id );
$actual = ob_get_clean();
if ( $expected ) {
$this->assertStringContainsString(
'imgedit-applyto',
$actual,
'The markup should have been output.'
);
} else {
$this->assertStringNotContainsString(
'imgedit-applyto',
$actual,
'The markup should not have been output.'
);
}
}
/**
* Data provider.
*
* @return array[]
*/
public function data_wp_image_editor_should_respect_image_edit_thumbnails_separately_filters() {
return array(
'true' => array(
'callback' => '__return_true',
'expected' => true,
),
'false' => array(
'callback' => '__return_false',
'expected' => false,
),
);
}
/**
* Tests that a passed mime type overrides the extension in the filename when saving an image.
*