Skip to content

Commit

Permalink
Copy image, because otherwise it will be deleted. (#1005)
Browse files Browse the repository at this point in the history
The sideload logic of WordPress deletes the source file and that might cause issues in local tests. This change generates a copy of the image to use that in tests.
  • Loading branch information
pfefferle authored Nov 20, 2024
1 parent 314c731 commit 4727fd2
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions tests/class-test-activitypub-post.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,17 @@ public function test_block_attachments_with_fallback() {
* @return int|WP_Error The attachment ID on success. The value 0 or WP_Error on failure.
*/
public function create_upload_object( $file, $parent_id = 0 ) {
if ( ! class_exists( 'WP_Filesystem_Direct' ) ) {
require ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php';
require ABSPATH . 'wp-admin/includes/class-wp-filesystem-direct.php';
}

$dest = dirname( $file ) . DIRECTORY_SEPARATOR . 'test-temp.jpg';
$fs = new \WP_Filesystem_Direct( array() );
$fs->copy( $file, $dest );

$file = $dest;

$file_array = array(
'name' => wp_basename( $file ),
'tmp_name' => $file,
Expand Down

0 comments on commit 4727fd2

Please sign in to comment.