WordPress.org

Make WordPress Core

Ticket #17262: 17262.9.diff

File 17262.9.diff, 22.2 KB (added by killua99, 17 months ago)

Proposal 9, that include performance into looking for the upload path folder, skipping creation. Adding deprecation message to wp_get_attachment_thumb_file since this ticket mention about deprecate it.

  • src/js/_enqueues/wp/widgets/custom-html.js

    diff --git a/src/js/_enqueues/wp/widgets/custom-html.js b/src/js/_enqueues/wp/widgets/custom-html.js
    index 93aa901c2f..6cc4835eeb 100644
    a b wp.customHtmlWidgets = ( function( $ ) { 
    115115                        control.contentUpdateBypassed = control.fields.content.is( document.activeElement ) || control.editor && control.editor.codemirror.state.focused || 0 !== control.currentErrorAnnotations.length;
    116116                        if ( ! control.contentUpdateBypassed ) {
    117117                                syncInput = control.syncContainer.find( '.sync-input.content' );
    118                                 control.fields.content.val( syncInput.val() );
     118                                control.fields.content.val( syncInput.val() ).trigger( 'change' );
    119119                        }
    120120                },
    121121
  • src/wp-admin/includes/dashboard.php

    diff --git a/src/wp-admin/includes/dashboard.php b/src/wp-admin/includes/dashboard.php
    index cf13fcfc24..e3e8cca9a7 100644
    a b function wp_dashboard_php_nag() { 
    16471647        <?php
    16481648
    16491649        wp_update_php_annotation();
    1650         wp_direct_php_update_button();
    16511650}
    16521651
    16531652/**
  • src/wp-content/themes/twentynineteen/sass/blocks/_blocks.scss

    diff --git a/src/wp-content/themes/twentynineteen/sass/blocks/_blocks.scss b/src/wp-content/themes/twentynineteen/sass/blocks/_blocks.scss
    index 653e50a8c2..479ee33d25 100644
    a b  
    838838                // Use white text against these backgrounds by default.
    839839                color: $color__background-body;
    840840
    841                 > p,
    842                 > h1,
    843                 > h2,
    844                 > h3,
    845                 > h4,
    846                 > h5,
    847                 > h6,
    848                 > a {
     841                p,
     842                h1,
     843                h2,
     844                h3,
     845                h4,
     846                h5,
     847                h6,
     848                a {
    849849                        color: $color__background-body;
    850850                }
    851851        }
     
    854854                color: $color__text-main;
    855855
    856856                // Use dark gray text against this background by default.
    857                 > p,
    858                 > h1,
    859                 > h2,
    860                 > h3,
    861                 > h4,
    862                 > h5,
    863                 > h6,
    864                 > a {
     857                p,
     858                h1,
     859                h2,
     860                h3,
     861                h4,
     862                h5,
     863                h6,
     864                a {
    865865                        color: $color__text-main;
    866866                }
    867867        }
     
    894894        //! Custom foreground colors
    895895        .has-primary-color,
    896896        .wp-block-pullquote.is-style-solid-color blockquote.has-primary-color,
    897         .wp-block-pullquote.is-style-solid-color blockquote.has-primary-color > p {
     897        .wp-block-pullquote.is-style-solid-color blockquote.has-primary-color p {
    898898                color: $color__link;
    899899        }
    900900
    901901        .has-secondary-color,
    902902        .wp-block-pullquote.is-style-solid-color blockquote.has-secondary-color,
    903         .wp-block-pullquote.is-style-solid-color blockquote.has-secondary-color > p {
     903        .wp-block-pullquote.is-style-solid-color blockquote.has-secondary-color p {
    904904                color: $color__border-link-hover;
    905905        }
    906906
    907907        .has-dark-gray-color,
    908908        .wp-block-pullquote.is-style-solid-color blockquote.has-dark-gray-color,
    909         .wp-block-pullquote.is-style-solid-color blockquote.has-dark-gray-color > p {
     909        .wp-block-pullquote.is-style-solid-color blockquote.has-dark-gray-color p {
    910910                color: $color__text-main;
    911911        }
    912912
    913913        .has-light-gray-color,
    914914        .wp-block-pullquote.is-style-solid-color blockquote.has-light-gray-color,
    915         .wp-block-pullquote.is-style-solid-color blockquote.has-light-gray-color > p {
     915        .wp-block-pullquote.is-style-solid-color blockquote.has-light-gray-color p {
    916916                color: $color__text-light;
    917917        }
    918918
  • src/wp-content/themes/twentynineteen/style-rtl.css

    diff --git a/src/wp-content/themes/twentynineteen/style-rtl.css b/src/wp-content/themes/twentynineteen/style-rtl.css
    index 3fd6f91ecd..80732eb901 100644
    a b body.page .main-navigation { 
    60756075  color: #fff;
    60766076}
    60776077
    6078 .entry .entry-content .has-primary-background-color > p,
    6079 .entry .entry-content .has-primary-background-color > h1,
    6080 .entry .entry-content .has-primary-background-color > h2,
    6081 .entry .entry-content .has-primary-background-color > h3,
    6082 .entry .entry-content .has-primary-background-color > h4,
    6083 .entry .entry-content .has-primary-background-color > h5,
    6084 .entry .entry-content .has-primary-background-color > h6,
    6085 .entry .entry-content .has-primary-background-color > a,
    6086 .entry .entry-content .has-secondary-background-color > p,
    6087 .entry .entry-content .has-secondary-background-color > h1,
    6088 .entry .entry-content .has-secondary-background-color > h2,
    6089 .entry .entry-content .has-secondary-background-color > h3,
    6090 .entry .entry-content .has-secondary-background-color > h4,
    6091 .entry .entry-content .has-secondary-background-color > h5,
    6092 .entry .entry-content .has-secondary-background-color > h6,
    6093 .entry .entry-content .has-secondary-background-color > a,
    6094 .entry .entry-content .has-dark-gray-background-color > p,
    6095 .entry .entry-content .has-dark-gray-background-color > h1,
    6096 .entry .entry-content .has-dark-gray-background-color > h2,
    6097 .entry .entry-content .has-dark-gray-background-color > h3,
    6098 .entry .entry-content .has-dark-gray-background-color > h4,
    6099 .entry .entry-content .has-dark-gray-background-color > h5,
    6100 .entry .entry-content .has-dark-gray-background-color > h6,
    6101 .entry .entry-content .has-dark-gray-background-color > a,
    6102 .entry .entry-content .has-light-gray-background-color > p,
    6103 .entry .entry-content .has-light-gray-background-color > h1,
    6104 .entry .entry-content .has-light-gray-background-color > h2,
    6105 .entry .entry-content .has-light-gray-background-color > h3,
    6106 .entry .entry-content .has-light-gray-background-color > h4,
    6107 .entry .entry-content .has-light-gray-background-color > h5,
    6108 .entry .entry-content .has-light-gray-background-color > h6,
    6109 .entry .entry-content .has-light-gray-background-color > a {
     6078.entry .entry-content .has-primary-background-color p,
     6079.entry .entry-content .has-primary-background-color h1,
     6080.entry .entry-content .has-primary-background-color h2,
     6081.entry .entry-content .has-primary-background-color h3,
     6082.entry .entry-content .has-primary-background-color h4,
     6083.entry .entry-content .has-primary-background-color h5,
     6084.entry .entry-content .has-primary-background-color h6,
     6085.entry .entry-content .has-primary-background-color a,
     6086.entry .entry-content .has-secondary-background-color p,
     6087.entry .entry-content .has-secondary-background-color h1,
     6088.entry .entry-content .has-secondary-background-color h2,
     6089.entry .entry-content .has-secondary-background-color h3,
     6090.entry .entry-content .has-secondary-background-color h4,
     6091.entry .entry-content .has-secondary-background-color h5,
     6092.entry .entry-content .has-secondary-background-color h6,
     6093.entry .entry-content .has-secondary-background-color a,
     6094.entry .entry-content .has-dark-gray-background-color p,
     6095.entry .entry-content .has-dark-gray-background-color h1,
     6096.entry .entry-content .has-dark-gray-background-color h2,
     6097.entry .entry-content .has-dark-gray-background-color h3,
     6098.entry .entry-content .has-dark-gray-background-color h4,
     6099.entry .entry-content .has-dark-gray-background-color h5,
     6100.entry .entry-content .has-dark-gray-background-color h6,
     6101.entry .entry-content .has-dark-gray-background-color a,
     6102.entry .entry-content .has-light-gray-background-color p,
     6103.entry .entry-content .has-light-gray-background-color h1,
     6104.entry .entry-content .has-light-gray-background-color h2,
     6105.entry .entry-content .has-light-gray-background-color h3,
     6106.entry .entry-content .has-light-gray-background-color h4,
     6107.entry .entry-content .has-light-gray-background-color h5,
     6108.entry .entry-content .has-light-gray-background-color h6,
     6109.entry .entry-content .has-light-gray-background-color a {
    61106110  color: #fff;
    61116111}
    61126112
    body.page .main-navigation { 
    61146114  color: #111;
    61156115}
    61166116
    6117 .entry .entry-content .has-white-background-color > p,
    6118 .entry .entry-content .has-white-background-color > h1,
    6119 .entry .entry-content .has-white-background-color > h2,
    6120 .entry .entry-content .has-white-background-color > h3,
    6121 .entry .entry-content .has-white-background-color > h4,
    6122 .entry .entry-content .has-white-background-color > h5,
    6123 .entry .entry-content .has-white-background-color > h6,
    6124 .entry .entry-content .has-white-background-color > a {
     6117.entry .entry-content .has-white-background-color p,
     6118.entry .entry-content .has-white-background-color h1,
     6119.entry .entry-content .has-white-background-color h2,
     6120.entry .entry-content .has-white-background-color h3,
     6121.entry .entry-content .has-white-background-color h4,
     6122.entry .entry-content .has-white-background-color h5,
     6123.entry .entry-content .has-white-background-color h6,
     6124.entry .entry-content .has-white-background-color a {
    61256125  color: #111;
    61266126}
    61276127
    body.page .main-navigation { 
    61526152
    61536153.entry .entry-content .has-primary-color,
    61546154.entry .entry-content .wp-block-pullquote.is-style-solid-color blockquote.has-primary-color,
    6155 .entry .entry-content .wp-block-pullquote.is-style-solid-color blockquote.has-primary-color > p {
     6155.entry .entry-content .wp-block-pullquote.is-style-solid-color blockquote.has-primary-color p {
    61566156  color: #0073aa;
    61576157}
    61586158
    61596159.entry .entry-content .has-secondary-color,
    61606160.entry .entry-content .wp-block-pullquote.is-style-solid-color blockquote.has-secondary-color,
    6161 .entry .entry-content .wp-block-pullquote.is-style-solid-color blockquote.has-secondary-color > p {
     6161.entry .entry-content .wp-block-pullquote.is-style-solid-color blockquote.has-secondary-color p {
    61626162  color: #005177;
    61636163}
    61646164
    61656165.entry .entry-content .has-dark-gray-color,
    61666166.entry .entry-content .wp-block-pullquote.is-style-solid-color blockquote.has-dark-gray-color,
    6167 .entry .entry-content .wp-block-pullquote.is-style-solid-color blockquote.has-dark-gray-color > p {
     6167.entry .entry-content .wp-block-pullquote.is-style-solid-color blockquote.has-dark-gray-color p {
    61686168  color: #111;
    61696169}
    61706170
    61716171.entry .entry-content .has-light-gray-color,
    61726172.entry .entry-content .wp-block-pullquote.is-style-solid-color blockquote.has-light-gray-color,
    6173 .entry .entry-content .wp-block-pullquote.is-style-solid-color blockquote.has-light-gray-color > p {
     6173.entry .entry-content .wp-block-pullquote.is-style-solid-color blockquote.has-light-gray-color p {
    61746174  color: #767676;
    61756175}
    61766176
  • src/wp-content/themes/twentynineteen/style.css

    diff --git a/src/wp-content/themes/twentynineteen/style.css b/src/wp-content/themes/twentynineteen/style.css
    index ac596fab23..0185b404e5 100644
    a b body.page .main-navigation { 
    60876087  color: #fff;
    60886088}
    60896089
    6090 .entry .entry-content .has-primary-background-color > p,
    6091 .entry .entry-content .has-primary-background-color > h1,
    6092 .entry .entry-content .has-primary-background-color > h2,
    6093 .entry .entry-content .has-primary-background-color > h3,
    6094 .entry .entry-content .has-primary-background-color > h4,
    6095 .entry .entry-content .has-primary-background-color > h5,
    6096 .entry .entry-content .has-primary-background-color > h6,
    6097 .entry .entry-content .has-primary-background-color > a,
    6098 .entry .entry-content .has-secondary-background-color > p,
    6099 .entry .entry-content .has-secondary-background-color > h1,
    6100 .entry .entry-content .has-secondary-background-color > h2,
    6101 .entry .entry-content .has-secondary-background-color > h3,
    6102 .entry .entry-content .has-secondary-background-color > h4,
    6103 .entry .entry-content .has-secondary-background-color > h5,
    6104 .entry .entry-content .has-secondary-background-color > h6,
    6105 .entry .entry-content .has-secondary-background-color > a,
    6106 .entry .entry-content .has-dark-gray-background-color > p,
    6107 .entry .entry-content .has-dark-gray-background-color > h1,
    6108 .entry .entry-content .has-dark-gray-background-color > h2,
    6109 .entry .entry-content .has-dark-gray-background-color > h3,
    6110 .entry .entry-content .has-dark-gray-background-color > h4,
    6111 .entry .entry-content .has-dark-gray-background-color > h5,
    6112 .entry .entry-content .has-dark-gray-background-color > h6,
    6113 .entry .entry-content .has-dark-gray-background-color > a,
    6114 .entry .entry-content .has-light-gray-background-color > p,
    6115 .entry .entry-content .has-light-gray-background-color > h1,
    6116 .entry .entry-content .has-light-gray-background-color > h2,
    6117 .entry .entry-content .has-light-gray-background-color > h3,
    6118 .entry .entry-content .has-light-gray-background-color > h4,
    6119 .entry .entry-content .has-light-gray-background-color > h5,
    6120 .entry .entry-content .has-light-gray-background-color > h6,
    6121 .entry .entry-content .has-light-gray-background-color > a {
     6090.entry .entry-content .has-primary-background-color p,
     6091.entry .entry-content .has-primary-background-color h1,
     6092.entry .entry-content .has-primary-background-color h2,
     6093.entry .entry-content .has-primary-background-color h3,
     6094.entry .entry-content .has-primary-background-color h4,
     6095.entry .entry-content .has-primary-background-color h5,
     6096.entry .entry-content .has-primary-background-color h6,
     6097.entry .entry-content .has-primary-background-color a,
     6098.entry .entry-content .has-secondary-background-color p,
     6099.entry .entry-content .has-secondary-background-color h1,
     6100.entry .entry-content .has-secondary-background-color h2,
     6101.entry .entry-content .has-secondary-background-color h3,
     6102.entry .entry-content .has-secondary-background-color h4,
     6103.entry .entry-content .has-secondary-background-color h5,
     6104.entry .entry-content .has-secondary-background-color h6,
     6105.entry .entry-content .has-secondary-background-color a,
     6106.entry .entry-content .has-dark-gray-background-color p,
     6107.entry .entry-content .has-dark-gray-background-color h1,
     6108.entry .entry-content .has-dark-gray-background-color h2,
     6109.entry .entry-content .has-dark-gray-background-color h3,
     6110.entry .entry-content .has-dark-gray-background-color h4,
     6111.entry .entry-content .has-dark-gray-background-color h5,
     6112.entry .entry-content .has-dark-gray-background-color h6,
     6113.entry .entry-content .has-dark-gray-background-color a,
     6114.entry .entry-content .has-light-gray-background-color p,
     6115.entry .entry-content .has-light-gray-background-color h1,
     6116.entry .entry-content .has-light-gray-background-color h2,
     6117.entry .entry-content .has-light-gray-background-color h3,
     6118.entry .entry-content .has-light-gray-background-color h4,
     6119.entry .entry-content .has-light-gray-background-color h5,
     6120.entry .entry-content .has-light-gray-background-color h6,
     6121.entry .entry-content .has-light-gray-background-color a {
    61226122  color: #fff;
    61236123}
    61246124
    body.page .main-navigation { 
    61266126  color: #111;
    61276127}
    61286128
    6129 .entry .entry-content .has-white-background-color > p,
    6130 .entry .entry-content .has-white-background-color > h1,
    6131 .entry .entry-content .has-white-background-color > h2,
    6132 .entry .entry-content .has-white-background-color > h3,
    6133 .entry .entry-content .has-white-background-color > h4,
    6134 .entry .entry-content .has-white-background-color > h5,
    6135 .entry .entry-content .has-white-background-color > h6,
    6136 .entry .entry-content .has-white-background-color > a {
     6129.entry .entry-content .has-white-background-color p,
     6130.entry .entry-content .has-white-background-color h1,
     6131.entry .entry-content .has-white-background-color h2,
     6132.entry .entry-content .has-white-background-color h3,
     6133.entry .entry-content .has-white-background-color h4,
     6134.entry .entry-content .has-white-background-color h5,
     6135.entry .entry-content .has-white-background-color h6,
     6136.entry .entry-content .has-white-background-color a {
    61376137  color: #111;
    61386138}
    61396139
    body.page .main-navigation { 
    61646164
    61656165.entry .entry-content .has-primary-color,
    61666166.entry .entry-content .wp-block-pullquote.is-style-solid-color blockquote.has-primary-color,
    6167 .entry .entry-content .wp-block-pullquote.is-style-solid-color blockquote.has-primary-color > p {
     6167.entry .entry-content .wp-block-pullquote.is-style-solid-color blockquote.has-primary-color p {
    61686168  color: #0073aa;
    61696169}
    61706170
    61716171.entry .entry-content .has-secondary-color,
    61726172.entry .entry-content .wp-block-pullquote.is-style-solid-color blockquote.has-secondary-color,
    6173 .entry .entry-content .wp-block-pullquote.is-style-solid-color blockquote.has-secondary-color > p {
     6173.entry .entry-content .wp-block-pullquote.is-style-solid-color blockquote.has-secondary-color p {
    61746174  color: #005177;
    61756175}
    61766176
    61776177.entry .entry-content .has-dark-gray-color,
    61786178.entry .entry-content .wp-block-pullquote.is-style-solid-color blockquote.has-dark-gray-color,
    6179 .entry .entry-content .wp-block-pullquote.is-style-solid-color blockquote.has-dark-gray-color > p {
     6179.entry .entry-content .wp-block-pullquote.is-style-solid-color blockquote.has-dark-gray-color p {
    61806180  color: #111;
    61816181}
    61826182
    61836183.entry .entry-content .has-light-gray-color,
    61846184.entry .entry-content .wp-block-pullquote.is-style-solid-color blockquote.has-light-gray-color,
    6185 .entry .entry-content .wp-block-pullquote.is-style-solid-color blockquote.has-light-gray-color > p {
     6185.entry .entry-content .wp-block-pullquote.is-style-solid-color blockquote.has-light-gray-color p {
    61866186  color: #767676;
    61876187}
    61886188
  • src/wp-includes/functions.php

    diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php
    index 2cce881518..397acd3a42 100644
    a b function wp_update_php_annotation() { 
    68306830        );
    68316831        echo'</p>';
    68326832}
    6833 
    6834 /**
    6835  * Gets the URL for directly updating the PHP version the site is running on.
    6836  *
    6837  * A URL will only be returned if the `WP_DIRECT_UPDATE_PHP_URL` environment variable is specified or
    6838  * by using the {@see 'wp_direct_php_update_url'} filter. This allows hosts to send users directly to
    6839  * the page where they can update PHP to a newer version.
    6840  *
    6841  * @return string URL for directly updating PHP or empty string.
    6842  */
    6843 function wp_get_direct_php_update_url() {
    6844         $direct_update_url = '';
    6845 
    6846         if ( false !== getenv( 'WP_DIRECT_UPDATE_PHP_URL' ) ) {
    6847                 $direct_update_url = getenv( 'WP_DIRECT_UPDATE_PHP_URL' );
    6848         }
    6849 
    6850         /**
    6851          * Filters the URL for directly updating the PHP version the site is running on from the host.
    6852          *
    6853          * @since 5.1.1
    6854          *
    6855          * @param string $direct_update_url URL for directly updating PHP.
    6856          */
    6857         $direct_update_url = apply_filters( 'wp_direct_php_update_url', $direct_update_url );
    6858 
    6859         return $direct_update_url;
    6860 }
    6861 
    6862 /**
    6863  * Display a button directly linking to a PHP update process.
    6864  *
    6865  * This provides hosts with a way for users to be sent directly to their PHP update process.
    6866  *
    6867  * The button is only displayed if a URL is returned by `wp_get_direct_php_update_url()`.
    6868  *
    6869  * @since 5.1.1
    6870  */
    6871 function wp_direct_php_update_button() {
    6872         $direct_update_url = wp_get_direct_php_update_url();
    6873 
    6874         if ( empty( $direct_update_url ) ) {
    6875                 return;
    6876         }
    6877 
    6878         echo '<p class="button-container">';
    6879         printf(
    6880                 '<a class="button button-primary" href="%1$s" target="_blank" rel="noopener noreferrer">%2$s <span class="screen-reader-text">%3$s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a>',
    6881                 esc_url( $direct_update_url ),
    6882                 __( 'Update PHP' ),
    6883                 /* translators: accessibility text */
    6884                 __( '(opens in a new tab)' )
    6885         );
    6886         echo '</p>';
    6887 }
  • src/wp-includes/media.php

    diff --git a/src/wp-includes/media.php b/src/wp-includes/media.php
    index 019086c3b8..ecac41b7a2 100644
    a b function wp_get_attachment_image_url( $attachment_id, $size = 'thumbnail', $icon 
    945945        return isset( $image['0'] ) ? $image['0'] : false;
    946946}
    947947
     948/**
     949 * Get the size path of an image attachment.
     950 *
     951 * @param int          $attachment_id Attachment ID.
     952 * @param string|array $size Optional. Image size to retrieve. Accepts any valid image size, or an array
     953 *                           of width and height values. Default 'thumbnail'
     954 *
     955 * @return string|null Attachment path or null if no image is available.
     956 */
     957function wp_get_attachment_image_file( $attachment_id, $size = 'thumbnail' ) {
     958
     959        if ( 0 === (int) $attachment_id ) {
     960                return null;
     961        }
     962
     963        $attachment_metadata = wp_get_attachment_metadata( $attachment_id );
     964
     965        if ( ! $attachment_metadata ) {
     966                return null;
     967        }
     968
     969        $file_name = isset( $attachment_metadata['sizes'][ $size ]['file'] ) ? $attachment_metadata['sizes'][ $size ]['file'] : false;
     970
     971        $file = dirname( $attachment_metadata['file'] ) . '/' . $file_name;
     972
     973        $file_path = _wp_get_attachment_relative_path( $file );
     974
     975        if ( empty( $file_path ) ) {
     976                return null;
     977        }
     978
     979        $wp_upload_dir = wp_upload_dir( null, null );
     980
     981        $path = $wp_upload_dir['basedir'] . '/' . trailingslashit( $file_path ) . $file_name;
     982
     983        return $path;
     984
     985}
     986
     987
    948988/**
    949989 * Get the attachment path relative to the upload directory.
    950990 *
  • src/wp-includes/post.php

    diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php
    index eb69ac727b..5250aaa294 100644
    a b function wp_get_attachment_caption( $post_id = 0 ) { 
    56895689 * Retrieve thumbnail for an attachment.
    56905690 *
    56915691 * @since 2.1.0
     5692 * @deprecated 5.2 Use wp_get_attachment_image_file( $attachment_id, $size = 'thumbnail' )
    56925693 *
    56935694 * @param int $post_id Optional. Attachment ID. Default 0.
    56945695 * @return string|false False on failure. Thumbnail file path on success.
  • new file tests/phpunit/tests/media/getImageAttachmentSize.php

    diff --git a/tests/phpunit/tests/media/getImageAttachmentSize.php b/tests/phpunit/tests/media/getImageAttachmentSize.php
    new file mode 100644
    index 0000000000..37f2162f53
    - +  
     1<?php
     2
     3/**
     4 * @group media
     5 */
     6class Tests_Media_GetImageAttachmentSize extends WP_UnitTestCase {
     7
     8        /** @var array WP Upload Dir. */
     9        protected $wp_upload_dir;
     10
     11        public function setUp() {
     12                $this->wp_upload_dir = wp_upload_dir();
     13
     14                parent::setUp();
     15        }
     16
     17        /**
     18         * Creating file.
     19         *
     20         * @param string $file_name Image file name.
     21         *
     22         * @return int Attachment ID.
     23         */
     24        protected function upload_image( $file_name ) {
     25                $post_id = self::factory()->post->create( [ 'post_author' => 1 ] );
     26
     27                \copy( DIR_TESTDATA . '/images/' . $file_name, $this->wp_upload_dir['path'] . '/' . $file_name );
     28
     29                $file = $this->wp_upload_dir['path'] . '/' . $file_name;
     30
     31                $wp_filetype = wp_check_filetype( basename( $file ), null );
     32
     33                $attachment_id = wp_insert_attachment(
     34                        [
     35                                'post_mime_type' => $wp_filetype['type'],
     36                                'post_status'    => 'inherit',
     37                                'post_title'     => preg_replace( '/\.[^.]+$/', '', basename( $file ) ),
     38                                'post_content'   => '',
     39                        ],
     40                        $file,
     41                        $post_id
     42                );
     43
     44                $attachment_data = wp_generate_attachment_metadata( $attachment_id, $file );
     45
     46                wp_update_attachment_metadata( $attachment_id, $attachment_data, $post_id );
     47
     48                return $attachment_id;
     49        }
     50
     51        public function test_get_attachment_image_size() {
     52                $attachment_id = $this->upload_image( 'waffles.jpg' );
     53
     54                $file_size = wp_get_attachment_image_file( $attachment_id, 'medium' );
     55
     56                $this->assertContains( 'waffles-300x200.jpg', $file_size );
     57        }
     58
     59        public function test_get_custom_attachment_image_size() {
     60                add_image_size( 'custom', 400, 400, true );
     61
     62                $attachment_id = $this->upload_image( 'canola.jpg' );
     63
     64                $file_size = wp_get_attachment_image_file( $attachment_id, 'custom' );
     65
     66                $this->assertContains( 'canola-400x400.jpg', $file_size );
     67        }
     68}