WordPress.org

Make WordPress Core

Changeset 35181


Ignore:
Timestamp:
10/15/2015 02:54:20 AM (5 years ago)
Author:
wonderboymusic
Message:

Unit Tests: in Tests_Media::test_wp_get_attachment_image_srcset_array_no_width(), just toggle metadata, instead of creating a new attachment. Shaves 75ms off the test.

See #30017, #33968.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/media.php

    r35179 r35181  
    762762     * @ticket 33641
    763763     */
    764     function test_wp_get_attachment_image_srcset_array_no_date_upoads() {
     764    function test_wp_get_attachment_image_srcset_array_no_date_uploads() {
    765765        // Save the current setting for uploads folders
    766766        $uploads_use_yearmonth_folders = get_option( 'uploads_use_yearmonth_folders' );
     
    849849        add_filter( 'wp_generate_attachment_metadata', array( $this, '_test_wp_get_attachment_image_srcset_array_no_width_filter' ) );
    850850
    851         // Make our attachment.
    852         $filename = DIR_TESTDATA . '/images/test-image-large.png';
    853         $id = $this->factory->attachment->create_upload_object( $filename );
    854         $srcset = wp_get_attachment_image_srcset_array( $id, 'medium' );
    855 
    856         // Remove filter.
    857         remove_filter( 'wp_generate_attachment_metadata', array( $this, '_test_wp_get_attachment_image_srcset_array_no_width_filter' ) );
     851        $old_meta = get_post_meta( self::$large_id, '_wp_attachment_metadata', true );
     852        $file = get_attached_file( self::$large_id );
     853
     854        $data = wp_generate_attachment_metadata( self::$large_id, $file );
     855        wp_update_attachment_metadata( self::$large_id, $data );
     856
     857        $srcset = wp_get_attachment_image_srcset_array( self::$large_id, 'medium' );
     858
     859        update_post_meta( self::$large_id, '_wp_attachment_metadata', $old_meta );
    858860
    859861        // The srcset should be false.
     
    865867     */
    866868    public function _test_wp_get_attachment_image_srcset_array_no_width_filter( $meta ) {
     869        remove_filter( 'wp_generate_attachment_metadata', array( $this, __FUNCTION__ ) );
     870
    867871        $meta['sizes']['medium']['width'] = 0;
    868872        $meta['sizes']['medium']['height'] = 0;
Note: See TracChangeset for help on using the changeset viewer.