Make WordPress Core


Ignore:
Timestamp:
06/18/2023 02:22:40 PM (20 months ago)
Author:
azaozz
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/image/functions.php

    r55070 r55935  
    349349
    350350        $this->assertTrue( $ret, 'Image failed to save.' );
     351    }
     352
     353    /**
     354     * Tests that `wp_image_editor()` applies 'image_edit_thumbnails_separately' filters.
     355     *
     356     * @ticket 53161
     357     *
     358     * @covers ::wp_image_editor
     359     */
     360    public function test_wp_image_editor_should_apply_image_edit_thumbnails_separately_filters() {
     361        require_once ABSPATH . 'wp-admin/includes/image-edit.php';
     362
     363        $filename = DIR_TESTDATA . '/images/canola.jpg';
     364        $contents = file_get_contents( $filename );
     365        $upload   = wp_upload_bits( wp_basename( $filename ), null, $contents );
     366        $id       = $this->_make_attachment( $upload );
     367
     368        $filter = new MockAction();
     369        add_filter( 'image_edit_thumbnails_separately', array( &$filter, 'filter' ) );
     370
     371        ob_start();
     372        wp_image_editor( $id );
     373        ob_end_clean();
     374
     375        $this->assertSame( 1, $filter->get_call_count() );
     376    }
     377
     378    /**
     379     * Tests that `wp_image_editor()` conditionally outputs markup for editing thumbnails separately
     380     * based on the result of applying 'image_edit_thumbnails_separately' filters.
     381     *
     382     * @ticket 53161
     383     *
     384     * @covers ::wp_image_editor
     385     *
     386     * @dataProvider data_wp_image_editor_should_respect_image_edit_thumbnails_separately_filters
     387     *
     388     * @param string $callback The name of the callback for the 'image_edit_thumbnails_separately' hook.
     389     * @param bool   $expected Whether the markup should be output.
     390     */
     391    public function test_wp_image_editor_should_respect_image_edit_thumbnails_separately_filters( $callback, $expected ) {
     392        require_once ABSPATH . 'wp-admin/includes/image-edit.php';
     393
     394        $filename = DIR_TESTDATA . '/images/canola.jpg';
     395        $contents = file_get_contents( $filename );
     396        $upload   = wp_upload_bits( wp_basename( $filename ), null, $contents );
     397        $id       = $this->_make_attachment( $upload );
     398
     399        add_filter( 'image_edit_thumbnails_separately', $callback );
     400
     401        ob_start();
     402        wp_image_editor( $id );
     403        $actual = ob_get_clean();
     404
     405        if ( $expected ) {
     406            $this->assertStringContainsString(
     407                'imgedit-applyto',
     408                $actual,
     409                'The markup should have been output.'
     410            );
     411        } else {
     412            $this->assertStringNotContainsString(
     413                'imgedit-applyto',
     414                $actual,
     415                'The markup should not have been output.'
     416            );
     417        }
     418    }
     419
     420    /**
     421     * Data provider.
     422     *
     423     * @return array[]
     424     */
     425    public function data_wp_image_editor_should_respect_image_edit_thumbnails_separately_filters() {
     426        return array(
     427            'true'  => array(
     428                'callback' => '__return_true',
     429                'expected' => true,
     430            ),
     431            'false' => array(
     432                'callback' => '__return_false',
     433                'expected' => false,
     434            ),
     435        );
    351436    }
    352437
Note: See TracChangeset for help on using the changeset viewer.