Make WordPress Core

Changeset 55244


Ignore:
Timestamp:
02/07/2023 03:15:49 AM (2 years ago)
Author:
peterwilsoncc
Message:

Filesystem API: Add test for uncovered WP_Error in move_dir().

Introduces a test for the WP_Error object destination_not_deleted_move_dir in the move_dir() function.

Follow up to [55226].

Props costdev, mukesh27.
Fixes #57375.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/filesystem/moveDir.php

    r55204 r55244  
    277277    }
    278278
     279    /**
     280     * Tests that `move_dir()` returns a WP_Error object when overwriting
     281     * is enabled, the destination exists, but cannot be deleted.
     282     *
     283     * @ticket 57375
     284     */
     285    public function test_should_return_wp_error_when_overwriting_is_enabled_the_destination_exists_but_cannot_be_deleted() {
     286        global $wp_filesystem;
     287        $wpfilesystem_backup = $wp_filesystem;
     288
     289        // Force failure conditions.
     290        $filesystem_mock = $this->getMockBuilder( 'WP_Filesystem_Direct' )->setConstructorArgs( array( null ) )->getMock();
     291        $filesystem_mock->expects( $this->once() )->method( 'exists' )->willReturn( true );
     292        $filesystem_mock->expects( $this->once() )->method( 'delete' )->willReturn( false );
     293        $wp_filesystem = $filesystem_mock;
     294
     295        $actual = move_dir( self::$existing_from, self::$existing_from_subdir, true );
     296
     297        // Restore the filesystem.
     298        $wp_filesystem = $wpfilesystem_backup;
     299
     300        $this->assertWPError(
     301            $actual,
     302            'A WP_Error object was not returned.'
     303        );
     304
     305        $this->assertSame(
     306            'destination_not_deleted_move_dir',
     307            $actual->get_error_code(),
     308            'An unexpected error code was returned.'
     309        );
     310    }
     311
    279312}
Note: See TracChangeset for help on using the changeset viewer.