| 1339 | // Non-image file not allowed even if it's named like one. |
| 1340 | array( |
| 1341 | DIR_TESTDATA . '/export/crazy-cdata.xml', |
| 1342 | 'crazy-cdata.jpg', |
| 1343 | array( |
| 1344 | 'ext' => false, |
| 1345 | 'type' => false, |
| 1346 | 'proper_filename' => false, |
| 1347 | ), |
| 1348 | ), |
| 1349 | // Non-image file not allowed if it's named like something else. |
| 1350 | array( |
| 1351 | DIR_TESTDATA . '/export/crazy-cdata.xml', |
| 1352 | 'crazy-cdata.doc', |
| 1353 | array( |
| 1354 | 'ext' => false, |
| 1355 | 'type' => false, |
| 1356 | 'proper_filename' => false, |
| 1357 | ), |
| 1358 | ), |
| 1359 | // Assorted text/* sample files |
| 1360 | array( |
| 1361 | DIR_TESTDATA . '/uploads/test.vtt', |
| 1362 | 'test.vtt', |
| 1363 | array( |
| 1364 | 'ext' => 'vtt', |
| 1365 | 'type' => 'text/vtt', |
| 1366 | 'proper_filename' => false, |
| 1367 | ), |
| 1368 | ), |
| 1369 | array( |
| 1370 | DIR_TESTDATA . '/uploads/test.csv', |
| 1371 | 'test.csv', |
| 1372 | array( |
| 1373 | 'ext' => 'csv', |
| 1374 | 'type' => 'text/csv', |
| 1375 | 'proper_filename' => false, |
| 1376 | ), |
| 1377 | ), |
| 1422 | /** |
| 1423 | * @ticket 45615 |
| 1424 | * @dataProvider _wp_check_filetype_and_ext_unsupported |
| 1425 | */ |
| 1426 | function test_wp_check_filetype_and_ext_unsupported_unfiltered( $file, $filename, $expected ) { |
| 1427 | |
| 1428 | // Without a filter adding these file types to the allowed mime_types list, they should all be rejected. |
| 1429 | |
| 1430 | $expected_failure = array( |
| 1431 | 'ext' => false, |
| 1432 | 'type' => false, |
| 1433 | 'proper_filename' => false, |
| 1434 | ); |
| 1435 | |
| 1436 | |
| 1437 | $this->assertEquals( $expected_failure, wp_check_filetype_and_ext( $file, $filename ) ); |
| 1438 | } |
| 1439 | |
| 1440 | /** |
| 1441 | * @ticket 45615 |
| 1442 | * @dataProvider _wp_check_filetype_and_ext_unsupported |
| 1443 | */ |
| 1444 | function test_wp_check_filetype_and_ext_unsupported_filtered( $file, $filename, $expected ) { |
| 1445 | |
| 1446 | // With a filter these should succeed |
| 1447 | $ext = $expected['ext']; |
| 1448 | $mime_type = $expected['type']; |
| 1449 | $filter = function( $mimes ) use ( $ext, $mime_type ) { |
| 1450 | $mimes[ $ext ] = $mime_type; |
| 1451 | return $mimes; |
| 1452 | }; |
| 1453 | |
| 1454 | add_filter( 'upload_mimes', $filter ); |
| 1455 | |
| 1456 | $this->assertEquals( $expected, wp_check_filetype_and_ext( $file, $filename ) ); |
| 1457 | |
| 1458 | remove_filter( 'upload_mimes', $filter ); |
| 1459 | } |
| 1460 | |
| 1461 | /** |
| 1462 | * Data providor for 'test_wp_check_filetype_and_ext_unsupported_filtered' |
| 1463 | * |
| 1464 | * @return array An array of unsupported file types added through filters. |
| 1465 | */ |
| 1466 | public function _wp_check_filetype_and_ext_unsupported() { |
| 1467 | $data = array( |
| 1468 | array( |
| 1469 | DIR_TESTDATA . '/uploads/test.json', |
| 1470 | 'test.json', |
| 1471 | array( |
| 1472 | 'ext' => 'json', |
| 1473 | 'type' => 'text/plain', |
| 1474 | 'proper_filename' => false, |
| 1475 | ), |
| 1476 | ), |
| 1477 | ); |
| 1478 | |
| 1479 | return $data; |
| 1480 | } |
| 1481 | |