| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Tests for wp_check_filetype() |
| 5 | * |
| 6 | * @group functions.php |
| 7 | * @covers ::wp_check_filetype |
| 8 | */ |
| 9 | class Tests_Functions_wpCheckFiletype extends WP_UnitTestCase { |
| 10 | |
| 11 | public function data_url_filetypes() { |
| 12 | return array( |
| 13 | // Invalid or empty data: |
| 14 | array( null, false ), |
| 15 | array( '', false ), |
| 16 | array( ' ', false ), |
| 17 | |
| 18 | // Paths: |
| 19 | array( 'file.jpg', 'jpg' ), |
| 20 | array( 'C:\path\to\file.mp3', 'mp3' ), |
| 21 | array( 'C:\path\to\file.mp3?file.jpg', 'mp3' ), |
| 22 | array( 'C:\path\to\file.exe?file.jpg', false ), |
| 23 | array( '/file.jpg', 'jpg' ), |
| 24 | array( '/path/to/file.jpg', 'jpg' ), |
| 25 | array( '/path/to/file.jpg', 'jpg' ), |
| 26 | array( '/file.exe?file.jpg', false ), |
| 27 | |
| 28 | // Absolute URLs: |
| 29 | array( 'http://example.com', false ), |
| 30 | array( 'http://example.com/', false ), |
| 31 | array( 'http://example.com/wibble', false ), |
| 32 | array( 'http://example.com/wibble/', false ), |
| 33 | array( 'http://example.com/wibble.wobble', false ), |
| 34 | array( 'http://example.com/wibble.mp3', 'mp3' ), |
| 35 | array( 'http://example.com/wibble.mp3#wobble', 'mp3' ), |
| 36 | array( 'http://example.com/wibble.mp3?wobble=true', 'mp3' ), |
| 37 | array( 'http://example.com/wibble.mp3?wobble=true#wobble', 'mp3' ), |
| 38 | array( 'http://example.mp3', false ), |
| 39 | array( 'http://example.mp3/', false ), |
| 40 | array( 'http://example.com/file.mp3#file.jpg', 'mp3' ), |
| 41 | array( 'http://example.com/file.mp3?file.jpg', 'mp3' ), |
| 42 | array( 'http://example.com/file.exe#file.jpg', false ), |
| 43 | array( 'http://example.com/file.exe?file.jpg', false ), |
| 44 | array( 'http://example.com/file.mp3?foo=bar#?file=file.jpg', 'mp3' ), |
| 45 | array( 'http://example.com?file.jpg', false ), |
| 46 | ); |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * @dataProvider data_url_filetypes |
| 51 | * |
| 52 | * @param string $url |
| 53 | * @param string|false $expected |
| 54 | */ |
| 55 | public function test_url_ext( $url, $expected ) { |
| 56 | $filetype = wp_check_filetype( $url ); |
| 57 | $this->assertSame( $expected, $filetype['ext'] ); |
| 58 | } |
| 59 | } |