Make WordPress Core

Ticket #41318: 41318.1.patch

File 41318.1.patch, 1.4 KB (added by theorboman, 9 years ago)

Patch with unit tests

  • src/wp-admin/includes/file.php

     
    129129        if ( empty($folder) )
    130130                return false;
    131131
     132        $folder = untrailingslashit( $folder );
     133
    132134        if ( ! $levels )
    133135                return false;
    134136
  • tests/phpunit/tests/file.php

     
    155155                unlink($this->dir . DIRECTORY_SEPARATOR . $filename);
    156156        }
    157157
     158        function test_list_files() {
     159                $directory = '/tmp' . DIRECTORY_SEPARATOR . 'testdir';
     160
     161                $files = array(
     162                        $directory . DIRECTORY_SEPARATOR . 'test_1.txt',
     163                        $directory . DIRECTORY_SEPARATOR . 'test_2.txt',
     164                        $directory . DIRECTORY_SEPARATOR . 'test_3.txt',
     165                );
     166
     167                wp_mkdir_p( $directory );
     168                foreach ( $files as $file ) {
     169                        file_put_contents( $file, 'hi' );
     170                }
     171
     172                $listed_files = list_files( $directory );
     173                sort( $listed_files );
     174
     175                $this->assertEquals( $files, $listed_files );
     176
     177                // Test also for https://core.trac.wordpress.org/ticket/41318
     178                $listed_files = list_files( trailingslashit( $directory ) );
     179                sort( $listed_files );
     180
     181                $this->assertEquals( $files, $listed_files );
     182
     183                $this->rmdir( $directory );
     184        }
     185
    158186        /**
    159187         * @dataProvider data_wp_tempnam_filenames
    160188         */