From e421f262dc79a0304a8217d12d730bef10ffcc1e Mon Sep 17 00:00:00 2001 From: Aaron Jorbin Date: Fri, 1 Mar 2019 20:57:26 +0000 Subject: [PATCH] Replace usages of basename() with wp_basename() in order to support multibyte filenames This is focused on the pieces of code that touch media files and the tests that support them. `basename` isn't multibyte compatible out of the box. See http://php.net/basename and https://bugs.php.net/bug.php?id=62119. See #43170. Props Viper007Bond. git-svn-id: https://develop.svn.wordpress.org/trunk@44785 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/custom-background.php | 2 +- src/wp-admin/custom-header.php | 12 ++-- src/wp-admin/includes/ajax-actions.php | 4 +- src/wp-admin/includes/class-wp-site-icon.php | 4 +- src/wp-admin/includes/image-edit.php | 2 +- src/wp-admin/includes/image.php | 10 ++-- src/wp-admin/includes/import.php | 2 +- src/wp-admin/includes/media.php | 6 +- src/wp-admin/includes/misc.php | 2 +- .../themes/twentyten/loop-attachment.php | 2 +- .../class-wp-customize-manager.php | 6 +- .../class-wp-customize-media-control.php | 2 +- src/wp-includes/deprecated.php | 6 +- src/wp-includes/functions.php | 4 +- src/wp-includes/media.php | 2 +- src/wp-includes/post.php | 16 +++--- .../class-wp-rest-attachments-controller.php | 4 +- tests/phpunit/includes/abstract-testcase.php | 2 +- ...ass-wp-unittest-factory-for-attachment.php | 4 +- tests/phpunit/tests/ajax/Attachments.php | 4 +- tests/phpunit/tests/ajax/MediaEdit.php | 4 +- tests/phpunit/tests/blocks/block-parser.php | 2 +- tests/phpunit/tests/blocks/render.php | 2 +- tests/phpunit/tests/general/template.php | 4 +- tests/phpunit/tests/image/editor.php | 6 +- .../phpunit/tests/image/intermediateSize.php | 2 +- tests/phpunit/tests/image/resize.php | 18 +++--- tests/phpunit/tests/image/siteIcon.php | 6 +- tests/phpunit/tests/media.php | 2 +- tests/phpunit/tests/post/attachments.php | 56 +++++++++---------- .../rest-api/rest-attachments-controller.php | 2 +- .../phpunit/tests/xmlrpc/wp/getMediaItem.php | 2 +- 32 files changed, 101 insertions(+), 101 deletions(-) diff --git a/src/wp-admin/custom-background.php b/src/wp-admin/custom-background.php index e5151015ec..2a26f7f221 100644 --- a/src/wp-admin/custom-background.php +++ b/src/wp-admin/custom-background.php @@ -494,7 +494,7 @@ class Custom_Background { $url = $file['url']; $type = $file['type']; $file = $file['file']; - $filename = basename( $file ); + $filename = wp_basename( $file ); // Construct the object array $object = array( diff --git a/src/wp-admin/custom-header.php b/src/wp-admin/custom-header.php index 127a46a6a7..6164330df6 100644 --- a/src/wp-admin/custom-header.php +++ b/src/wp-admin/custom-header.php @@ -820,7 +820,7 @@ endif; return $this->finished(); } elseif ( $width > $max_width ) { $oitar = $width / $max_width; - $image = wp_crop_image( $attachment_id, 0, 0, $width, $height, $max_width, $height / $oitar, false, str_replace( basename( $file ), 'midsize-' . basename( $file ), $file ) ); + $image = wp_crop_image( $attachment_id, 0, 0, $width, $height, $max_width, $height / $oitar, false, str_replace( wp_basename( $file ), 'midsize-' . wp_basename( $file ), $file ) ); if ( ! $image || is_wp_error( $image ) ) { wp_die( __( 'Image could not be processed. Please go back and try again.' ), __( 'Image Processing Error' ) ); } @@ -828,7 +828,7 @@ endif; /** This filter is documented in wp-admin/custom-header.php */ $image = apply_filters( 'wp_create_file_in_uploads', $image, $attachment_id ); // For replication - $url = str_replace( basename( $url ), basename( $image ), $url ); + $url = str_replace( wp_basename( $url ), wp_basename( $image ), $url ); $width = $width / $oitar; $height = $height / $oitar; } else { @@ -895,7 +895,7 @@ endif; $url = $file['url']; $type = $file['type']; $file = $file['file']; - $filename = basename( $file ); + $filename = wp_basename( $file ); // Construct the object array $object = array( @@ -984,7 +984,7 @@ endif; $this->set_header_image( compact( 'url', 'attachment_id', 'width', 'height' ) ); // Cleanup. - $medium = str_replace( basename( $original ), 'midsize-' . basename( $original ), $original ); + $medium = str_replace( wp_basename( $original ), 'midsize-' . wp_basename( $original ), $original ); if ( file_exists( $medium ) ) { wp_delete_file( $medium ); } @@ -1208,14 +1208,14 @@ endif; final public function create_attachment_object( $cropped, $parent_attachment_id ) { $parent = get_post( $parent_attachment_id ); $parent_url = wp_get_attachment_url( $parent->ID ); - $url = str_replace( basename( $parent_url ), basename( $cropped ), $parent_url ); + $url = str_replace( wp_basename( $parent_url ), wp_basename( $cropped ), $parent_url ); $size = @getimagesize( $cropped ); $image_type = ( $size ) ? $size['mime'] : 'image/jpeg'; $object = array( 'ID' => $parent_attachment_id, - 'post_title' => basename( $cropped ), + 'post_title' => wp_basename( $cropped ), 'post_mime_type' => $image_type, 'guid' => $url, 'context' => 'custom-header', diff --git a/src/wp-admin/includes/ajax-actions.php b/src/wp-admin/includes/ajax-actions.php index 4da538bea9..c565817914 100644 --- a/src/wp-admin/includes/ajax-actions.php +++ b/src/wp-admin/includes/ajax-actions.php @@ -3651,13 +3651,13 @@ function wp_ajax_crop_image() { $cropped = apply_filters( 'wp_create_file_in_uploads', $cropped, $attachment_id ); // For replication. $parent_url = wp_get_attachment_url( $attachment_id ); - $url = str_replace( basename( $parent_url ), basename( $cropped ), $parent_url ); + $url = str_replace( wp_basename( $parent_url ), wp_basename( $cropped ), $parent_url ); $size = @getimagesize( $cropped ); $image_type = ( $size ) ? $size['mime'] : 'image/jpeg'; $object = array( - 'post_title' => basename( $cropped ), + 'post_title' => wp_basename( $cropped ), 'post_content' => $url, 'post_mime_type' => $image_type, 'guid' => $url, diff --git a/src/wp-admin/includes/class-wp-site-icon.php b/src/wp-admin/includes/class-wp-site-icon.php index 69ac09b408..a16565e70f 100644 --- a/src/wp-admin/includes/class-wp-site-icon.php +++ b/src/wp-admin/includes/class-wp-site-icon.php @@ -85,14 +85,14 @@ class WP_Site_Icon { public function create_attachment_object( $cropped, $parent_attachment_id ) { $parent = get_post( $parent_attachment_id ); $parent_url = wp_get_attachment_url( $parent->ID ); - $url = str_replace( basename( $parent_url ), basename( $cropped ), $parent_url ); + $url = str_replace( wp_basename( $parent_url ), wp_basename( $cropped ), $parent_url ); $size = @getimagesize( $cropped ); $image_type = ( $size ) ? $size['mime'] : 'image/jpeg'; $object = array( 'ID' => $parent_attachment_id, - 'post_title' => basename( $cropped ), + 'post_title' => wp_basename( $cropped ), 'post_content' => $url, 'post_mime_type' => $image_type, 'guid' => $url, diff --git a/src/wp-admin/includes/image-edit.php b/src/wp-admin/includes/image-edit.php index 740405d328..e1ae86b607 100644 --- a/src/wp-admin/includes/image-edit.php +++ b/src/wp-admin/includes/image-edit.php @@ -33,7 +33,7 @@ function wp_image_editor( $post_id, $msg = false ) { $backup_sizes = get_post_meta( $post_id, '_wp_attachment_backup_sizes', true ); $can_restore = false; if ( ! empty( $backup_sizes ) && isset( $backup_sizes['full-orig'], $meta['file'] ) ) { - $can_restore = $backup_sizes['full-orig']['file'] != basename( $meta['file'] ); + $can_restore = $backup_sizes['full-orig']['file'] != wp_basename( $meta['file'] ); } if ( $msg ) { diff --git a/src/wp-admin/includes/image.php b/src/wp-admin/includes/image.php index 31844b3082..d0a2954e5f 100644 --- a/src/wp-admin/includes/image.php +++ b/src/wp-admin/includes/image.php @@ -47,7 +47,7 @@ function wp_crop_image( $src, $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h, $s } if ( ! $dst_file ) { - $dst_file = str_replace( basename( $src_file ), 'cropped-' . basename( $src_file ), $src_file ); + $dst_file = str_replace( wp_basename( $src_file ), 'cropped-' . wp_basename( $src_file ), $src_file ); } /* @@ -56,7 +56,7 @@ function wp_crop_image( $src, $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h, $s */ wp_mkdir_p( dirname( $dst_file ) ); - $dst_file = dirname( $dst_file ) . '/' . wp_unique_filename( dirname( $dst_file ), basename( $dst_file ) ); + $dst_file = dirname( $dst_file ) . '/' . wp_unique_filename( dirname( $dst_file ), wp_basename( $dst_file ) ); $result = $editor->save( $dst_file ); if ( is_wp_error( $result ) ) { @@ -189,7 +189,7 @@ function wp_generate_attachment_metadata( $attachment_id, $file ) { $ext = '.png'; break; } - $basename = str_replace( '.', '-', basename( $file ) ) . '-image' . $ext; + $basename = str_replace( '.', '-', wp_basename( $file ) ) . '-image' . $ext; $uploaded = wp_upload_bits( $basename, '', $metadata['image']['data'] ); if ( false === $uploaded['error'] ) { $image_attachment = array( @@ -711,8 +711,8 @@ function _copy_image_file( $attachment_id ) { } if ( $src_file ) { - $dst_file = str_replace( basename( $dst_file ), 'copy-' . basename( $dst_file ), $dst_file ); - $dst_file = dirname( $dst_file ) . '/' . wp_unique_filename( dirname( $dst_file ), basename( $dst_file ) ); + $dst_file = str_replace( wp_basename( $dst_file ), 'copy-' . wp_basename( $dst_file ), $dst_file ); + $dst_file = dirname( $dst_file ) . '/' . wp_unique_filename( dirname( $dst_file ), wp_basename( $dst_file ) ); /* * The directory containing the original file may no longer diff --git a/src/wp-admin/includes/import.php b/src/wp-admin/includes/import.php index e1aac052fa..7b6ff88641 100644 --- a/src/wp-admin/includes/import.php +++ b/src/wp-admin/includes/import.php @@ -99,7 +99,7 @@ function wp_import_handle_upload() { // Construct the object array $object = array( - 'post_title' => basename( $upload['file'] ), + 'post_title' => wp_basename( $upload['file'] ), 'post_content' => $upload['url'], 'post_mime_type' => $upload['type'], 'guid' => $upload['url'], diff --git a/src/wp-admin/includes/media.php b/src/wp-admin/includes/media.php index 2738a2137b..58dc569b80 100644 --- a/src/wp-admin/includes/media.php +++ b/src/wp-admin/includes/media.php @@ -434,7 +434,7 @@ function media_handle_sideload( $file_array, $post_id, $desc = null, $post_data $url = $file['url']; $type = $file['type']; $file = $file['file']; - $title = preg_replace( '/\.[^.]+$/', '', basename( $file ) ); + $title = preg_replace( '/\.[^.]+$/', '', wp_basename( $file ) ); $content = ''; // Use image exif/iptc data for title and caption defaults if possible. @@ -826,7 +826,7 @@ function wp_media_upload_handler() { if ( isset( $_POST['media_type'] ) && 'image' != $_POST['media_type'] ) { $title = esc_html( wp_unslash( $_POST['title'] ) ); if ( empty( $title ) ) { - $title = esc_html( basename( $src ) ); + $title = esc_html( wp_basename( $src ) ); } if ( $title && $src ) { @@ -930,7 +930,7 @@ function media_sideload_image( $file, $post_id, $desc = null, $return = 'html' ) } $file_array = array(); - $file_array['name'] = basename( $matches[0] ); + $file_array['name'] = wp_basename( $matches[0] ); // Download file to temp location. $file_array['tmp_name'] = download_url( $file ); diff --git a/src/wp-admin/includes/misc.php b/src/wp-admin/includes/misc.php index 8a3be1093d..83f02988d0 100644 --- a/src/wp-admin/includes/misc.php +++ b/src/wp-admin/includes/misc.php @@ -362,7 +362,7 @@ function wp_print_theme_file_tree( $tree, $level = 2, $size = 1, $index = 1 ) { aria-posinset=""> (' . esc_html( $filename ) . ')'; } diff --git a/src/wp-content/themes/twentyten/loop-attachment.php b/src/wp-content/themes/twentyten/loop-attachment.php index 20564c21b5..a94084f4e6 100644 --- a/src/wp-content/themes/twentyten/loop-attachment.php +++ b/src/wp-content/themes/twentyten/loop-attachment.php @@ -138,7 +138,7 @@ if ( have_posts() ) { - +
diff --git a/src/wp-includes/class-wp-customize-manager.php b/src/wp-includes/class-wp-customize-manager.php index 81be17b79d..ab3839ac43 100644 --- a/src/wp-includes/class-wp-customize-manager.php +++ b/src/wp-includes/class-wp-customize-manager.php @@ -1360,7 +1360,7 @@ final class WP_Customize_Manager { if ( ! $attachment_id ) { // Copy file to temp location so that original file won't get deleted from theme after sideloading. - $temp_file_name = wp_tempnam( basename( $file_path ) ); + $temp_file_name = wp_tempnam( wp_basename( $file_path ) ); if ( $temp_file_name && copy( $file_path, $temp_file_name ) ) { $file_array['tmp_name'] = $temp_file_name; } @@ -1621,7 +1621,7 @@ final class WP_Customize_Manager { } else { continue; } - $file_name = basename( $attachment['file'] ); + $file_name = wp_basename( $attachment['file'] ); // Skip file types that are not recognized. $checked_filetype = wp_check_filetype( $file_name ); @@ -4594,7 +4594,7 @@ final class WP_Customize_Manager { if ( $this->return_url ) { $return_url = $this->return_url; - } elseif ( $referer && ! in_array( basename( parse_url( $referer, PHP_URL_PATH ) ), $excluded_referer_basenames, true ) ) { + } elseif ( $referer && ! in_array( wp_basename( parse_url( $referer, PHP_URL_PATH ) ), $excluded_referer_basenames, true ) ) { $return_url = $referer; } elseif ( $this->preview_url ) { $return_url = $this->preview_url; diff --git a/src/wp-includes/customize/class-wp-customize-media-control.php b/src/wp-includes/customize/class-wp-customize-media-control.php index 338324fd36..98d9310494 100644 --- a/src/wp-includes/customize/class-wp-customize-media-control.php +++ b/src/wp-includes/customize/class-wp-customize-media-control.php @@ -92,7 +92,7 @@ class WP_Customize_Media_Control extends WP_Customize_Control { 'url' => $this->setting->default, 'type' => $type, 'icon' => wp_mime_type_icon( $type ), - 'title' => basename( $this->setting->default ), + 'title' => wp_basename( $this->setting->default ), ); if ( 'image' === $type ) { diff --git a/src/wp-includes/deprecated.php b/src/wp-includes/deprecated.php index 826f41c5f4..f59cff1ea4 100644 --- a/src/wp-includes/deprecated.php +++ b/src/wp-includes/deprecated.php @@ -1878,7 +1878,7 @@ function get_attachment_icon_src( $id = 0, $fullsize = false ) { if ( !$fullsize && $src = wp_get_attachment_thumb_url( $post->ID ) ) { // We have a thumbnail desired, specified and existing - $src_file = basename($src); + $src_file = wp_basename($src); } elseif ( wp_attachment_is_image( $post->ID ) ) { // We have an image without a thumbnail @@ -1888,7 +1888,7 @@ function get_attachment_icon_src( $id = 0, $fullsize = false ) { // No thumb, no image. We'll look for a mime-related icon instead. $icon_dir = apply_filters( 'icon_dir', get_template_directory() . '/images' ); - $src_file = $icon_dir . '/' . basename($src); + $src_file = $icon_dir . '/' . wp_basename($src); } if ( !isset($src) || !$src ) @@ -3058,7 +3058,7 @@ function remove_custom_background() { */ function get_theme_data( $theme_file ) { _deprecated_function( __FUNCTION__, '3.4.0', 'wp_get_theme()' ); - $theme = new WP_Theme( basename( dirname( $theme_file ) ), dirname( dirname( $theme_file ) ) ); + $theme = new WP_Theme( wp_basename( dirname( $theme_file ) ), dirname( dirname( $theme_file ) ) ); $theme_data = array( 'Name' => $theme->get('Name'), diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php index 214c134d01..4d3f46410a 100644 --- a/src/wp-includes/functions.php +++ b/src/wp-includes/functions.php @@ -2096,7 +2096,7 @@ function wp_upload_dir( $time = null, $create_dir = true, $refresh_cache = false if ( 0 === strpos( $uploads['basedir'], ABSPATH ) ) { $error_path = str_replace( ABSPATH, '', $uploads['basedir'] ) . $uploads['subdir']; } else { - $error_path = basename( $uploads['basedir'] ) . $uploads['subdir']; + $error_path = wp_basename( $uploads['basedir'] ) . $uploads['subdir']; } $uploads['error'] = sprintf( @@ -2381,7 +2381,7 @@ function wp_upload_bits( $name, $deprecated, $bits, $time = null ) { if ( 0 === strpos( $upload['basedir'], ABSPATH ) ) { $error_path = str_replace( ABSPATH, '', $upload['basedir'] ) . $upload['subdir']; } else { - $error_path = basename( $upload['basedir'] ) . $upload['subdir']; + $error_path = wp_basename( $upload['basedir'] ) . $upload['subdir']; } $message = sprintf( diff --git a/src/wp-includes/media.php b/src/wp-includes/media.php index ace9021fd7..019086c3b8 100644 --- a/src/wp-includes/media.php +++ b/src/wp-includes/media.php @@ -2871,7 +2871,7 @@ function get_attachment_taxonomies( $attachment, $output = 'names' ) { } $file = get_attached_file( $attachment->ID ); - $filename = basename( $file ); + $filename = wp_basename( $file ); $objects = array( 'attachment' ); diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php index e6ca1f2000..eb69ac727b 100644 --- a/src/wp-includes/post.php +++ b/src/wp-includes/post.php @@ -5474,7 +5474,7 @@ function wp_delete_attachment_files( $post_id, $meta, $backup_sizes, $file ) { if ( ! empty( $meta['thumb'] ) ) { // Don't delete the thumb if another attachment uses it. if ( ! $wpdb->get_row( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE meta_key = '_wp_attachment_metadata' AND meta_value LIKE %s AND post_id <> %d", '%' . $wpdb->esc_like( $meta['thumb'] ) . '%', $post_id ) ) ) { - $thumbfile = str_replace( basename( $file ), $meta['thumb'], $file ); + $thumbfile = str_replace( wp_basename( $file ), $meta['thumb'], $file ); if ( ! empty( $thumbfile ) ) { $thumbfile = path_join( $uploadpath['basedir'], $thumbfile ); $thumbdir = path_join( $uploadpath['basedir'], dirname( $file ) ); @@ -5490,7 +5490,7 @@ function wp_delete_attachment_files( $post_id, $meta, $backup_sizes, $file ) { if ( isset( $meta['sizes'] ) && is_array( $meta['sizes'] ) ) { $intermediate_dir = path_join( $uploadpath['basedir'], dirname( $file ) ); foreach ( $meta['sizes'] as $size => $sizeinfo ) { - $intermediate_file = str_replace( basename( $file ), $sizeinfo['file'], $file ); + $intermediate_file = str_replace( wp_basename( $file ), $sizeinfo['file'], $file ); if ( ! empty( $intermediate_file ) ) { $intermediate_file = path_join( $uploadpath['basedir'], $intermediate_file ); @@ -5616,7 +5616,7 @@ function wp_get_attachment_url( $attachment_id = 0 ) { $url = str_replace( $uploads['basedir'], $uploads['baseurl'], $file ); } elseif ( false !== strpos( $file, 'wp-content/uploads' ) ) { // Get the directory name relative to the basedir (back compat for pre-2.7 uploads) - $url = trailingslashit( $uploads['baseurl'] . '/' . _wp_get_attachment_relative_path( $file ) ) . basename( $file ); + $url = trailingslashit( $uploads['baseurl'] . '/' . _wp_get_attachment_relative_path( $file ) ) . wp_basename( $file ); } else { // It's a newly-uploaded file, therefore $file is relative to the basedir. $url = $uploads['baseurl'] . "/$file"; @@ -5704,7 +5704,7 @@ function wp_get_attachment_thumb_file( $post_id = 0 ) { $file = get_attached_file( $post->ID ); - if ( ! empty( $imagedata['thumb'] ) && ( $thumbfile = str_replace( basename( $file ), $imagedata['thumb'], $file ) ) && file_exists( $thumbfile ) ) { + if ( ! empty( $imagedata['thumb'] ) && ( $thumbfile = str_replace( wp_basename( $file ), $imagedata['thumb'], $file ) ) && file_exists( $thumbfile ) ) { /** * Filters the attachment thumbnail file path. * @@ -5744,7 +5744,7 @@ function wp_get_attachment_thumb_url( $post_id = 0 ) { return false; } - $url = str_replace( basename( $url ), basename( $thumb ), $url ); + $url = str_replace( wp_basename( $url ), wp_basename( $thumb ), $url ); /** * Filters the attachment thumbnail URL. @@ -5896,7 +5896,7 @@ function wp_mime_type_icon( $mime = 0 ) { $uri = array_shift( $dirs ); if ( $dh = opendir( $dir ) ) { while ( false !== $file = readdir( $dh ) ) { - $file = basename( $file ); + $file = wp_basename( $file ); if ( substr( $file, 0, 1 ) == '.' ) { continue; } @@ -5915,9 +5915,9 @@ function wp_mime_type_icon( $mime = 0 ) { } $types = array(); - // Icon basename - extension = MIME wildcard. + // Icon wp_basename - extension = MIME wildcard. foreach ( $icon_files as $file => $uri ) { - $types[ preg_replace( '/^([^.]*).*$/', '$1', basename( $file ) ) ] =& $icon_files[ $file ]; + $types[ preg_replace( '/^([^.]*).*$/', '$1', wp_basename( $file ) ) ] =& $icon_files[ $file ]; } if ( ! empty( $mime ) ) { diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php index 640979cb7a..22a9483550 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php @@ -114,7 +114,7 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { return $file; } - $name = basename( $file['file'] ); + $name = wp_basename( $file['file'] ); $name_parts = pathinfo( $name ); $name = trim( substr( $name, 0, -( 1 + strlen( $name_parts['extension'] ) ) ) ); @@ -143,7 +143,7 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { $attachment->guid = $url; if ( empty( $attachment->post_title ) ) { - $attachment->post_title = preg_replace( '/\.[^.]+$/', '', basename( $file ) ); + $attachment->post_title = preg_replace( '/\.[^.]+$/', '', wp_basename( $file ) ); } // $post_parent is inherited from $attachment['post_parent']. diff --git a/tests/phpunit/includes/abstract-testcase.php b/tests/phpunit/includes/abstract-testcase.php index c90a1614e8..7858862bc9 100644 --- a/tests/phpunit/includes/abstract-testcase.php +++ b/tests/phpunit/includes/abstract-testcase.php @@ -1062,7 +1062,7 @@ abstract class WP_UnitTestCase_Base extends PHPUnit_Framework_TestCase { } $attachment = array( - 'post_title' => basename( $upload['file'] ), + 'post_title' => wp_basename( $upload['file'] ), 'post_content' => '', 'post_type' => 'attachment', 'post_parent' => $parent_post_id, diff --git a/tests/phpunit/includes/factory/class-wp-unittest-factory-for-attachment.php b/tests/phpunit/includes/factory/class-wp-unittest-factory-for-attachment.php index d9072fcb9d..f02b3e26b8 100644 --- a/tests/phpunit/includes/factory/class-wp-unittest-factory-for-attachment.php +++ b/tests/phpunit/includes/factory/class-wp-unittest-factory-for-attachment.php @@ -46,7 +46,7 @@ class WP_UnitTest_Factory_For_Attachment extends WP_UnitTest_Factory_For_Post { */ function create_upload_object( $file, $parent = 0 ) { $contents = file_get_contents( $file ); - $upload = wp_upload_bits( basename( $file ), null, $contents ); + $upload = wp_upload_bits( wp_basename( $file ), null, $contents ); $type = ''; if ( ! empty( $upload['type'] ) ) { @@ -59,7 +59,7 @@ class WP_UnitTest_Factory_For_Attachment extends WP_UnitTest_Factory_For_Post { } $attachment = array( - 'post_title' => basename( $upload['file'] ), + 'post_title' => wp_basename( $upload['file'] ), 'post_content' => '', 'post_type' => 'attachment', 'post_parent' => $parent, diff --git a/tests/phpunit/tests/ajax/Attachments.php b/tests/phpunit/tests/ajax/Attachments.php index cf11ddc5a0..79e78e7fd8 100644 --- a/tests/phpunit/tests/ajax/Attachments.php +++ b/tests/phpunit/tests/ajax/Attachments.php @@ -29,7 +29,7 @@ class Tests_Ajax_Attachments extends WP_Ajax_UnitTestCase { $filename = DIR_TESTDATA . '/images/canola.jpg'; $contents = file_get_contents( $filename ); - $upload = wp_upload_bits( basename( $filename ), null, $contents ); + $upload = wp_upload_bits( wp_basename( $filename ), null, $contents ); $attachment = $this->_make_attachment( $upload ); // Set up a default request @@ -80,7 +80,7 @@ class Tests_Ajax_Attachments extends WP_Ajax_UnitTestCase { $filename = DIR_TESTDATA . '/formatting/entities.txt'; $contents = file_get_contents( $filename ); - $upload = wp_upload_bits( basename( $filename ), null, $contents ); + $upload = wp_upload_bits( wp_basename( $filename ), null, $contents ); $attachment = $this->_make_attachment( $upload ); // Set up a default request diff --git a/tests/phpunit/tests/ajax/MediaEdit.php b/tests/phpunit/tests/ajax/MediaEdit.php index a55e3829a8..b36f342158 100644 --- a/tests/phpunit/tests/ajax/MediaEdit.php +++ b/tests/phpunit/tests/ajax/MediaEdit.php @@ -32,7 +32,7 @@ class Tests_Ajax_MediaEdit extends WP_Ajax_UnitTestCase { $filename = DIR_TESTDATA . '/images/canola.jpg'; $contents = file_get_contents( $filename ); - $upload = wp_upload_bits( basename( $filename ), null, $contents ); + $upload = wp_upload_bits( wp_basename( $filename ), null, $contents ); $id = $this->_make_attachment( $upload ); $_REQUEST['action'] = 'image-editor'; @@ -63,7 +63,7 @@ class Tests_Ajax_MediaEdit extends WP_Ajax_UnitTestCase { $filename = DIR_TESTDATA . '/images/canola.jpg'; $contents = file_get_contents( $filename ); - $upload = wp_upload_bits( basename( $filename ), null, $contents ); + $upload = wp_upload_bits( wp_basename( $filename ), null, $contents ); $id = $this->_make_attachment( $upload ); $_REQUEST['action'] = 'image-editor'; diff --git a/tests/phpunit/tests/blocks/block-parser.php b/tests/phpunit/tests/blocks/block-parser.php index 8ab5b6b536..fba13b0c71 100644 --- a/tests/phpunit/tests/blocks/block-parser.php +++ b/tests/phpunit/tests/blocks/block-parser.php @@ -85,7 +85,7 @@ class WP_Test_Block_Parser extends WP_UnitTestCase { * @return string The cleaned fixture name. */ protected function clean_fixture_filename( $filename ) { - $filename = basename( $filename ); + $filename = wp_basename( $filename ); $filename = preg_replace( '/\..+$/', '', $filename ); return $filename; } diff --git a/tests/phpunit/tests/blocks/render.php b/tests/phpunit/tests/blocks/render.php index be41a4bb9a..e7dc724740 100644 --- a/tests/phpunit/tests/blocks/render.php +++ b/tests/phpunit/tests/blocks/render.php @@ -358,7 +358,7 @@ class WP_Test_Block_Render extends WP_UnitTestCase { * @return string The cleaned fixture name. */ protected function clean_fixture_filename( $filename ) { - $filename = basename( $filename ); + $filename = wp_basename( $filename ); $filename = preg_replace( '/\..+$/', '', $filename ); return $filename; } diff --git a/tests/phpunit/tests/general/template.php b/tests/phpunit/tests/general/template.php index d5752fc71b..8e0567c82e 100644 --- a/tests/phpunit/tests/general/template.php +++ b/tests/phpunit/tests/general/template.php @@ -231,7 +231,7 @@ class Tests_General_Template extends WP_UnitTestCase { $filename = DIR_TESTDATA . '/images/test-image.jpg'; $contents = file_get_contents( $filename ); - $upload = wp_upload_bits( basename( $filename ), null, $contents ); + $upload = wp_upload_bits( wp_basename( $filename ), null, $contents ); $this->site_icon_url = $upload['url']; // Save the data @@ -409,7 +409,7 @@ class Tests_General_Template extends WP_UnitTestCase { function _insert_custom_logo() { $filename = DIR_TESTDATA . '/images/test-image.jpg'; $contents = file_get_contents( $filename ); - $upload = wp_upload_bits( basename( $filename ), null, $contents ); + $upload = wp_upload_bits( wp_basename( $filename ), null, $contents ); // Save the data. $this->custom_logo_url = $upload['url']; diff --git a/tests/phpunit/tests/image/editor.php b/tests/phpunit/tests/image/editor.php index 680070c728..35242ad3e0 100644 --- a/tests/phpunit/tests/image/editor.php +++ b/tests/phpunit/tests/image/editor.php @@ -130,16 +130,16 @@ class Tests_Image_Editor extends WP_Image_UnitTestCase { ); // Test with no parameters - $this->assertEquals( 'canola-100x50.jpg', basename( $editor->generate_filename() ) ); + $this->assertEquals( 'canola-100x50.jpg', wp_basename( $editor->generate_filename() ) ); // Test with a suffix only - $this->assertEquals( 'canola-new.jpg', basename( $editor->generate_filename( 'new' ) ) ); + $this->assertEquals( 'canola-new.jpg', wp_basename( $editor->generate_filename( 'new' ) ) ); // Test with a destination dir only $this->assertEquals( trailingslashit( realpath( get_temp_dir() ) ), trailingslashit( realpath( dirname( $editor->generate_filename( null, get_temp_dir() ) ) ) ) ); // Test with a suffix only - $this->assertEquals( 'canola-100x50.png', basename( $editor->generate_filename( null, null, 'png' ) ) ); + $this->assertEquals( 'canola-100x50.png', wp_basename( $editor->generate_filename( null, null, 'png' ) ) ); // Combo! $this->assertEquals( trailingslashit( realpath( get_temp_dir() ) ) . 'canola-new.png', $editor->generate_filename( 'new', realpath( get_temp_dir() ), 'png' ) ); diff --git a/tests/phpunit/tests/image/intermediateSize.php b/tests/phpunit/tests/image/intermediateSize.php index 95ee173edd..ec0b818a9e 100644 --- a/tests/phpunit/tests/image/intermediateSize.php +++ b/tests/phpunit/tests/image/intermediateSize.php @@ -17,7 +17,7 @@ class Tests_Image_Intermediate_Size extends WP_UnitTestCase { public function _make_attachment( $file, $parent_post_id = 0 ) { $contents = file_get_contents( $file ); - $upload = wp_upload_bits( basename( $file ), null, $contents ); + $upload = wp_upload_bits( wp_basename( $file ), null, $contents ); return parent::_make_attachment( $upload, $parent_post_id ); } diff --git a/tests/phpunit/tests/image/resize.php b/tests/phpunit/tests/image/resize.php index 003f50e3ad..2cbd5a2505 100644 --- a/tests/phpunit/tests/image/resize.php +++ b/tests/phpunit/tests/image/resize.php @@ -29,7 +29,7 @@ abstract class WP_Tests_Image_Resize_UnitTestCase extends WP_Image_UnitTestCase function test_resize_jpg() { $image = $this->resize_helper( DIR_TESTDATA . '/images/test-image.jpg', 25, 25 ); - $this->assertEquals( 'test-image-25x25.jpg', basename( $image ) ); + $this->assertEquals( 'test-image-25x25.jpg', wp_basename( $image ) ); list($w, $h, $type) = getimagesize( $image ); $this->assertEquals( 25, $w ); $this->assertEquals( 25, $h ); @@ -45,7 +45,7 @@ abstract class WP_Tests_Image_Resize_UnitTestCase extends WP_Image_UnitTestCase $this->fail( sprintf( 'No PNG support in the editor engine %s on this system', $this->editor_engine ) ); } - $this->assertEquals( 'test-image-25x25.png', basename( $image ) ); + $this->assertEquals( 'test-image-25x25.png', wp_basename( $image ) ); list($w, $h, $type) = getimagesize( $image ); $this->assertEquals( 25, $w ); $this->assertEquals( 25, $h ); @@ -61,7 +61,7 @@ abstract class WP_Tests_Image_Resize_UnitTestCase extends WP_Image_UnitTestCase $this->fail( sprintf( 'No GIF support in the editor engine %s on this system', $this->editor_engine ) ); } - $this->assertEquals( 'test-image-25x25.gif', basename( $image ) ); + $this->assertEquals( 'test-image-25x25.gif', wp_basename( $image ) ); list($w, $h, $type) = getimagesize( $image ); $this->assertEquals( 25, $w ); $this->assertEquals( 25, $h ); @@ -81,7 +81,7 @@ abstract class WP_Tests_Image_Resize_UnitTestCase extends WP_Image_UnitTestCase function test_resize_thumb_128x96() { $image = $this->resize_helper( DIR_TESTDATA . '/images/2007-06-17DSC_4173.JPG', 128, 96 ); - $this->assertEquals( '2007-06-17DSC_4173-64x96.jpg', basename( $image ) ); + $this->assertEquals( '2007-06-17DSC_4173-64x96.jpg', wp_basename( $image ) ); list($w, $h, $type) = getimagesize( $image ); $this->assertEquals( 64, $w ); $this->assertEquals( 96, $h ); @@ -93,7 +93,7 @@ abstract class WP_Tests_Image_Resize_UnitTestCase extends WP_Image_UnitTestCase function test_resize_thumb_128x0() { $image = $this->resize_helper( DIR_TESTDATA . '/images/2007-06-17DSC_4173.JPG', 128, 0 ); - $this->assertEquals( '2007-06-17DSC_4173-128x193.jpg', basename( $image ) ); + $this->assertEquals( '2007-06-17DSC_4173-128x193.jpg', wp_basename( $image ) ); list($w, $h, $type) = getimagesize( $image ); $this->assertEquals( 128, $w ); $this->assertEquals( 193, $h ); @@ -105,7 +105,7 @@ abstract class WP_Tests_Image_Resize_UnitTestCase extends WP_Image_UnitTestCase function test_resize_thumb_0x96() { $image = $this->resize_helper( DIR_TESTDATA . '/images/2007-06-17DSC_4173.JPG', 0, 96 ); - $this->assertEquals( '2007-06-17DSC_4173-64x96.jpg', basename( $image ) ); + $this->assertEquals( '2007-06-17DSC_4173-64x96.jpg', wp_basename( $image ) ); list($w, $h, $type) = getimagesize( $image ); $this->assertEquals( 64, $w ); $this->assertEquals( 96, $h ); @@ -117,7 +117,7 @@ abstract class WP_Tests_Image_Resize_UnitTestCase extends WP_Image_UnitTestCase function test_resize_thumb_150x150_crop() { $image = $this->resize_helper( DIR_TESTDATA . '/images/2007-06-17DSC_4173.JPG', 150, 150, true ); - $this->assertEquals( '2007-06-17DSC_4173-150x150.jpg', basename( $image ) ); + $this->assertEquals( '2007-06-17DSC_4173-150x150.jpg', wp_basename( $image ) ); list($w, $h, $type) = getimagesize( $image ); $this->assertEquals( 150, $w ); $this->assertEquals( 150, $h ); @@ -129,7 +129,7 @@ abstract class WP_Tests_Image_Resize_UnitTestCase extends WP_Image_UnitTestCase function test_resize_thumb_150x100_crop() { $image = $this->resize_helper( DIR_TESTDATA . '/images/2007-06-17DSC_4173.JPG', 150, 100, true ); - $this->assertEquals( '2007-06-17DSC_4173-150x100.jpg', basename( $image ) ); + $this->assertEquals( '2007-06-17DSC_4173-150x100.jpg', wp_basename( $image ) ); list($w, $h, $type) = getimagesize( $image ); $this->assertEquals( 150, $w ); $this->assertEquals( 100, $h ); @@ -141,7 +141,7 @@ abstract class WP_Tests_Image_Resize_UnitTestCase extends WP_Image_UnitTestCase function test_resize_thumb_50x150_crop() { $image = $this->resize_helper( DIR_TESTDATA . '/images/2007-06-17DSC_4173.JPG', 50, 150, true ); - $this->assertEquals( '2007-06-17DSC_4173-50x150.jpg', basename( $image ) ); + $this->assertEquals( '2007-06-17DSC_4173-50x150.jpg', wp_basename( $image ) ); list($w, $h, $type) = getimagesize( $image ); $this->assertEquals( 50, $w ); $this->assertEquals( 150, $h ); diff --git a/tests/phpunit/tests/image/siteIcon.php b/tests/phpunit/tests/image/siteIcon.php index 509b69f975..891b2095fc 100644 --- a/tests/phpunit/tests/image/siteIcon.php +++ b/tests/phpunit/tests/image/siteIcon.php @@ -101,7 +101,7 @@ class Tests_WP_Site_Icon extends WP_UnitTestCase { function test_create_attachment_object() { $attachment_id = $this->_insert_attachment(); $parent_url = get_post( $attachment_id )->guid; - $cropped = str_replace( basename( $parent_url ), 'cropped-test-image.jpg', $parent_url ); + $cropped = str_replace( wp_basename( $parent_url ), 'cropped-test-image.jpg', $parent_url ); $object = $this->wp_site_icon->create_attachment_object( $cropped, $attachment_id ); @@ -115,7 +115,7 @@ class Tests_WP_Site_Icon extends WP_UnitTestCase { function test_insert_cropped_attachment() { $attachment_id = $this->_insert_attachment(); $parent_url = get_post( $attachment_id )->guid; - $cropped = str_replace( basename( $parent_url ), 'cropped-test-image.jpg', $parent_url ); + $cropped = str_replace( wp_basename( $parent_url ), 'cropped-test-image.jpg', $parent_url ); $object = $this->wp_site_icon->create_attachment_object( $cropped, $attachment_id ); $cropped_id = $this->wp_site_icon->insert_attachment( $object, $cropped ); @@ -163,7 +163,7 @@ class Tests_WP_Site_Icon extends WP_UnitTestCase { $filename = DIR_TESTDATA . '/images/test-image.jpg'; $contents = file_get_contents( $filename ); - $upload = wp_upload_bits( basename( $filename ), null, $contents ); + $upload = wp_upload_bits( wp_basename( $filename ), null, $contents ); $this->attachment_id = $this->_make_attachment( $upload ); return $this->attachment_id; diff --git a/tests/phpunit/tests/media.php b/tests/phpunit/tests/media.php index d9c34e5b9d..857de42386 100644 --- a/tests/phpunit/tests/media.php +++ b/tests/phpunit/tests/media.php @@ -1524,7 +1524,7 @@ EOF; // Copy hash generation method used in wp_save_image(). $hash = 'e' . time() . rand( 100, 999 ); - $filename_base = basename( $image_meta['file'], '.png' ); + $filename_base = wp_basename( $image_meta['file'], '.png' ); // Add the hash to the image URL $image_url = str_replace( $filename_base, $filename_base . '-' . $hash, $image_url ); diff --git a/tests/phpunit/tests/post/attachments.php b/tests/phpunit/tests/post/attachments.php index 08e44500f8..70255d5bec 100644 --- a/tests/phpunit/tests/post/attachments.php +++ b/tests/phpunit/tests/post/attachments.php @@ -27,7 +27,7 @@ class Tests_Post_Attachments extends WP_UnitTestCase { $filename = ( DIR_TESTDATA . '/images/test-image.jpg' ); $contents = file_get_contents( $filename ); - $upload = wp_upload_bits( basename( $filename ), null, $contents ); + $upload = wp_upload_bits( wp_basename( $filename ), null, $contents ); $this->assertTrue( empty( $upload['error'] ) ); $id = $this->_make_attachment( $upload ); @@ -39,17 +39,17 @@ class Tests_Post_Attachments extends WP_UnitTestCase { // medium, medium_large, and full size will both point to the original $downsize = image_downsize( $id, 'medium' ); - $this->assertEquals( basename( $upload['file'] ), basename( $downsize[0] ) ); + $this->assertEquals( wp_basename( $upload['file'] ), wp_basename( $downsize[0] ) ); $this->assertEquals( 50, $downsize[1] ); $this->assertEquals( 50, $downsize[2] ); $downsize = image_downsize( $id, 'medium_large' ); - $this->assertEquals( basename( $upload['file'] ), basename( $downsize[0] ) ); + $this->assertEquals( wp_basename( $upload['file'] ), wp_basename( $downsize[0] ) ); $this->assertEquals( 50, $downsize[1] ); $this->assertEquals( 50, $downsize[2] ); $downsize = image_downsize( $id, 'full' ); - $this->assertEquals( basename( $upload['file'] ), basename( $downsize[0] ) ); + $this->assertEquals( wp_basename( $upload['file'] ), wp_basename( $downsize[0] ) ); $this->assertEquals( 50, $downsize[1] ); $this->assertEquals( 50, $downsize[2] ); @@ -66,7 +66,7 @@ class Tests_Post_Attachments extends WP_UnitTestCase { $filename = ( DIR_TESTDATA . '/images/a2-small.jpg' ); $contents = file_get_contents( $filename ); - $upload = wp_upload_bits( basename( $filename ), null, $contents ); + $upload = wp_upload_bits( wp_basename( $filename ), null, $contents ); $this->assertTrue( empty( $upload['error'] ) ); $id = $this->_make_attachment( $upload ); @@ -86,23 +86,23 @@ class Tests_Post_Attachments extends WP_UnitTestCase { // image_downsize() should return the correct images and sizes $downsize = image_downsize( $id, 'thumbnail' ); - $this->assertEquals( 'a2-small-150x150.jpg', basename( $downsize[0] ) ); + $this->assertEquals( 'a2-small-150x150.jpg', wp_basename( $downsize[0] ) ); $this->assertEquals( 150, $downsize[1] ); $this->assertEquals( 150, $downsize[2] ); // medium, medium_large, and full will both point to the original $downsize = image_downsize( $id, 'medium' ); - $this->assertEquals( 'a2-small.jpg', basename( $downsize[0] ) ); + $this->assertEquals( 'a2-small.jpg', wp_basename( $downsize[0] ) ); $this->assertEquals( 400, $downsize[1] ); $this->assertEquals( 300, $downsize[2] ); $downsize = image_downsize( $id, 'medium_large' ); - $this->assertEquals( 'a2-small.jpg', basename( $downsize[0] ) ); + $this->assertEquals( 'a2-small.jpg', wp_basename( $downsize[0] ) ); $this->assertEquals( 400, $downsize[1] ); $this->assertEquals( 300, $downsize[2] ); $downsize = image_downsize( $id, 'full' ); - $this->assertEquals( 'a2-small.jpg', basename( $downsize[0] ) ); + $this->assertEquals( 'a2-small.jpg', wp_basename( $downsize[0] ) ); $this->assertEquals( 400, $downsize[1] ); $this->assertEquals( 300, $downsize[2] ); @@ -122,7 +122,7 @@ class Tests_Post_Attachments extends WP_UnitTestCase { $filename = ( DIR_TESTDATA . '/images/2007-06-17DSC_4173.JPG' ); $contents = file_get_contents( $filename ); - $upload = wp_upload_bits( basename( $filename ), null, $contents ); + $upload = wp_upload_bits( wp_basename( $filename ), null, $contents ); $this->assertTrue( empty( $upload['error'] ) ); $id = $this->_make_attachment( $upload ); @@ -146,22 +146,22 @@ class Tests_Post_Attachments extends WP_UnitTestCase { // image_downsize() should return the correct images and sizes $downsize = image_downsize( $id, 'thumbnail' ); - $this->assertEquals( '2007-06-17DSC_4173-150x150.jpg', basename( $downsize[0] ) ); + $this->assertEquals( '2007-06-17DSC_4173-150x150.jpg', wp_basename( $downsize[0] ) ); $this->assertEquals( 150, $downsize[1] ); $this->assertEquals( 150, $downsize[2] ); $downsize = image_downsize( $id, 'medium' ); - $this->assertEquals( '2007-06-17DSC_4173-400x602.jpg', basename( $downsize[0] ) ); + $this->assertEquals( '2007-06-17DSC_4173-400x602.jpg', wp_basename( $downsize[0] ) ); $this->assertEquals( 400, $downsize[1] ); $this->assertEquals( 602, $downsize[2] ); $downsize = image_downsize( $id, 'medium_large' ); - $this->assertEquals( '2007-06-17DSC_4173-600x904.jpg', basename( $downsize[0] ) ); + $this->assertEquals( '2007-06-17DSC_4173-600x904.jpg', wp_basename( $downsize[0] ) ); $this->assertEquals( 600, $downsize[1] ); $this->assertEquals( 904, $downsize[2] ); $downsize = image_downsize( $id, 'full' ); - $this->assertEquals( '2007-06-17DSC_4173.jpg', basename( $downsize[0] ) ); + $this->assertEquals( '2007-06-17DSC_4173.jpg', wp_basename( $downsize[0] ) ); $this->assertEquals( 680, $downsize[1] ); $this->assertEquals( 1024, $downsize[2] ); } @@ -181,7 +181,7 @@ class Tests_Post_Attachments extends WP_UnitTestCase { $filename = ( DIR_TESTDATA . '/images/2007-06-17DSC_4173.JPG' ); $contents = file_get_contents( $filename ); - $upload = wp_upload_bits( basename( $filename ), null, $contents ); + $upload = wp_upload_bits( wp_basename( $filename ), null, $contents ); $this->assertTrue( empty( $upload['error'] ) ); $id = $this->_make_attachment( $upload ); @@ -224,7 +224,7 @@ class Tests_Post_Attachments extends WP_UnitTestCase { $filename = ( DIR_TESTDATA . '/images/test-image.jpg' ); $contents = file_get_contents( $filename ); - $upload = wp_upload_bits( basename( $filename ), null, $contents ); + $upload = wp_upload_bits( wp_basename( $filename ), null, $contents ); $this->assertTrue( empty( $upload['error'] ) ); $upload['url'] = ''; @@ -241,7 +241,7 @@ class Tests_Post_Attachments extends WP_UnitTestCase { $filename = ( DIR_TESTDATA . '/images/test-image.jpg' ); $contents = file_get_contents( $filename ); - $upload = wp_upload_bits( basename( $filename ), null, $contents ); + $upload = wp_upload_bits( wp_basename( $filename ), null, $contents ); $this->assertTrue( empty( $upload['error'] ) ); $id = $this->_make_attachment( $upload ); @@ -267,7 +267,7 @@ class Tests_Post_Attachments extends WP_UnitTestCase { $filename = ( DIR_TESTDATA . '/images/test-image.jpg' ); $contents = file_get_contents( $filename ); - $upload = wp_upload_bits( basename( $filename ), null, $contents ); + $upload = wp_upload_bits( wp_basename( $filename ), null, $contents ); $this->assertTrue( empty( $upload['error'] ) ); $attachment_id = $this->_make_attachment( $upload ); @@ -299,7 +299,7 @@ class Tests_Post_Attachments extends WP_UnitTestCase { $filename = DIR_TESTDATA . '/images/test-image.jpg'; $contents = file_get_contents( $filename ); - $upload = wp_upload_bits( basename( $filename ), null, $contents ); + $upload = wp_upload_bits( wp_basename( $filename ), null, $contents ); $this->assertTrue( empty( $upload['error'] ) ); // Set attachment ID. @@ -324,7 +324,7 @@ class Tests_Post_Attachments extends WP_UnitTestCase { $filename = DIR_TESTDATA . '/images/test-image.jpg'; $contents = file_get_contents( $filename ); - $upload = wp_upload_bits( basename( $filename ), null, $contents ); + $upload = wp_upload_bits( wp_basename( $filename ), null, $contents ); $this->assertTrue( empty( $upload['error'] ) ); // Set attachment ID. @@ -349,7 +349,7 @@ class Tests_Post_Attachments extends WP_UnitTestCase { $filename = ( DIR_TESTDATA . '/images/test-image.jpg' ); $contents = file_get_contents( $filename ); - $upload = wp_upload_bits( basename( $filename ), null, $contents ); + $upload = wp_upload_bits( wp_basename( $filename ), null, $contents ); $this->assertTrue( empty( $upload['error'] ) ); // Set attachment ID @@ -377,7 +377,7 @@ class Tests_Post_Attachments extends WP_UnitTestCase { $filename = ( DIR_TESTDATA . '/images/test-image.jpg' ); $contents = file_get_contents( $filename ); - $upload = wp_upload_bits( basename( $filename ), null, $contents ); + $upload = wp_upload_bits( wp_basename( $filename ), null, $contents ); $this->assertTrue( empty( $upload['error'] ) ); // Set attachment ID. @@ -405,7 +405,7 @@ class Tests_Post_Attachments extends WP_UnitTestCase { $filename = ( DIR_TESTDATA . '/images/test-image.jpg' ); $contents = file_get_contents( $filename ); - $upload = wp_upload_bits( basename( $filename ), null, $contents ); + $upload = wp_upload_bits( wp_basename( $filename ), null, $contents ); $this->assertTrue( empty( $upload['error'] ) ); // Set attachment ID @@ -432,7 +432,7 @@ class Tests_Post_Attachments extends WP_UnitTestCase { $filename = ( DIR_TESTDATA . '/images/test-image.jpg' ); $contents = file_get_contents( $filename ); - $upload = wp_upload_bits( basename( $filename ), null, $contents ); + $upload = wp_upload_bits( wp_basename( $filename ), null, $contents ); $this->assertTrue( empty( $upload['error'] ) ); // Set attachment ID @@ -454,7 +454,7 @@ class Tests_Post_Attachments extends WP_UnitTestCase { $filename = DIR_TESTDATA . '/images/test-image.jpg'; $contents = file_get_contents( $filename ); - $upload = wp_upload_bits( basename( $filename ), null, $contents ); + $upload = wp_upload_bits( wp_basename( $filename ), null, $contents ); $attachment_id = $this->_make_attachment( $upload ); $this->assertTrue( wp_attachment_is_image( $attachment_id ) ); @@ -472,7 +472,7 @@ class Tests_Post_Attachments extends WP_UnitTestCase { $filename = DIR_TESTDATA . '/images/test-image.psd'; $contents = file_get_contents( $filename ); - $upload = wp_upload_bits( basename( $filename ), null, $contents ); + $upload = wp_upload_bits( wp_basename( $filename ), null, $contents ); $attachment_id = $this->_make_attachment( $upload ); $this->assertFalse( wp_attachment_is_image( $attachment_id ) ); @@ -489,13 +489,13 @@ class Tests_Post_Attachments extends WP_UnitTestCase { $filename = DIR_TESTDATA . '/images/test-image.jpg'; $contents = file_get_contents( $filename ); - $upload = wp_upload_bits( basename( $filename ), null, $contents ); + $upload = wp_upload_bits( wp_basename( $filename ), null, $contents ); $this->assertFalse( $upload['error'] ); add_filter( 'upload_mimes', array( $this, 'blacklist_jpg_mime_type' ) ); - $upload = wp_upload_bits( basename( $filename ), null, $contents ); + $upload = wp_upload_bits( wp_basename( $filename ), null, $contents ); remove_filter( 'upload_mimes', array( $this, 'blacklist_jpg_mime_type' ) ); diff --git a/tests/phpunit/tests/rest-api/rest-attachments-controller.php b/tests/phpunit/tests/rest-api/rest-attachments-controller.php index 0ec277ab3a..3ad2b09a72 100644 --- a/tests/phpunit/tests/rest-api/rest-attachments-controller.php +++ b/tests/phpunit/tests/rest-api/rest-attachments-controller.php @@ -1435,7 +1435,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control ) ); - $filename = basename( $this->test_file2 ); + $filename = wp_basename( $this->test_file2 ); $request = new WP_REST_Request( 'GET', '/wp/v2/media' ); $request->set_param( 'search', $filename ); diff --git a/tests/phpunit/tests/xmlrpc/wp/getMediaItem.php b/tests/phpunit/tests/xmlrpc/wp/getMediaItem.php index e036a7f4b9..7c46ded316 100644 --- a/tests/phpunit/tests/xmlrpc/wp/getMediaItem.php +++ b/tests/phpunit/tests/xmlrpc/wp/getMediaItem.php @@ -20,7 +20,7 @@ class Tests_XMLRPC_wp_getMediaItem extends WP_XMLRPC_UnitTestCase { $filename = ( DIR_TESTDATA . '/images/waffles.jpg' ); $contents = file_get_contents( $filename ); - $upload = wp_upload_bits( basename( $filename ), null, $contents ); + $upload = wp_upload_bits( wp_basename( $filename ), null, $contents ); $this->attachment_id = $this->_make_attachment( $upload, self::$post_id ); $this->attachment_data = get_post( $this->attachment_id, ARRAY_A );