Changeset 55464
- Timestamp:
- 03/06/2023 01:08:03 PM (20 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/functions.php
r55462 r55464 134 134 * 135 135 * @ticket 55897 136 * @dataProvider path_join_data_provider136 * @dataProvider data_path_join 137 137 */ 138 138 public function test_path_join( $base, $path, $expected ) { … … 145 145 * @return string[][] 146 146 */ 147 public function path_join_data_provider() {147 public function data_path_join() { 148 148 return array( 149 149 // Absolute paths. … … 1159 1159 /** 1160 1160 * @ticket 36054 1161 * @dataProvider dat etime_provider1161 * @dataProvider data_mysql_to_rfc3339 1162 1162 */ 1163 1163 public function test_mysql_to_rfc3339( $expected, $actual ) { … … 1170 1170 } 1171 1171 1172 public function dat etime_provider() {1172 public function data_mysql_to_rfc3339() { 1173 1173 return array( 1174 1174 array( '2016-03-15T18:54:46', '15-03-2016 18:54:46' ), … … 1335 1335 /** 1336 1336 * @ticket 40017 1337 * @dataProvider wp_get_image_mime1337 * @dataProvider data_wp_get_image_mime 1338 1338 */ 1339 1339 public function test_wp_get_image_mime( $file, $expected ) { … … 1343 1343 1344 1344 $this->assertSame( $expected, wp_get_image_mime( $file ) ); 1345 } 1346 1347 /** 1348 * Data provider for test_wp_get_image_mime(). 1349 */ 1350 public function data_wp_get_image_mime() { 1351 $data = array( 1352 // Standard JPEG. 1353 array( 1354 DIR_TESTDATA . '/images/test-image.jpg', 1355 'image/jpeg', 1356 ), 1357 // Standard GIF. 1358 array( 1359 DIR_TESTDATA . '/images/test-image.gif', 1360 'image/gif', 1361 ), 1362 // Standard PNG. 1363 array( 1364 DIR_TESTDATA . '/images/test-image.png', 1365 'image/png', 1366 ), 1367 // Image with wrong extension. 1368 array( 1369 DIR_TESTDATA . '/images/test-image-mime-jpg.png', 1370 'image/jpeg', 1371 ), 1372 // Animated WebP. 1373 array( 1374 DIR_TESTDATA . '/images/webp-animated.webp', 1375 'image/webp', 1376 ), 1377 // Lossless WebP. 1378 array( 1379 DIR_TESTDATA . '/images/webp-lossless.webp', 1380 'image/webp', 1381 ), 1382 // Lossy WebP. 1383 array( 1384 DIR_TESTDATA . '/images/webp-lossy.webp', 1385 'image/webp', 1386 ), 1387 // Transparent WebP. 1388 array( 1389 DIR_TESTDATA . '/images/webp-transparent.webp', 1390 'image/webp', 1391 ), 1392 // Not an image. 1393 array( 1394 DIR_TESTDATA . '/uploads/dashicons.woff', 1395 false, 1396 ), 1397 ); 1398 1399 return $data; 1345 1400 } 1346 1401 … … 1369 1424 1370 1425 /** 1371 * @ticket 395501372 * @dataProvider wp_check_filetype_and_ext_data1373 * @requires extension fileinfo1374 */1375 public function test_wp_check_filetype_and_ext( $file, $filename, $expected ) {1376 $this->assertSame( $expected, wp_check_filetype_and_ext( $file, $filename ) );1377 }1378 1379 /**1380 * @ticket 395501381 * @group ms-excluded1382 * @requires extension fileinfo1383 */1384 public function test_wp_check_filetype_and_ext_with_filtered_svg() {1385 $file = DIR_TESTDATA . '/uploads/video-play.svg';1386 $filename = 'video-play.svg';1387 1388 $expected = array(1389 'ext' => 'svg',1390 'type' => 'image/svg+xml',1391 'proper_filename' => false,1392 );1393 1394 add_filter(1395 'upload_mimes',1396 static function( $mimes ) {1397 $mimes['svg'] = 'image/svg+xml';1398 return $mimes;1399 }1400 );1401 1402 $this->assertSame( $expected, wp_check_filetype_and_ext( $file, $filename ) );1403 }1404 1405 /**1406 * @ticket 395501407 * @group ms-excluded1408 * @requires extension fileinfo1409 */1410 public function test_wp_check_filetype_and_ext_with_filtered_woff() {1411 $file = DIR_TESTDATA . '/uploads/dashicons.woff';1412 $filename = 'dashicons.woff';1413 1414 $woff_mime_type = 'application/font-woff';1415 1416 /*1417 * As of PHP 8.1.12, which includes libmagic/file update to version 5.42,1418 * the expected mime type for WOFF files is 'font/woff'.1419 *1420 * See https://github.com/php/php-src/issues/8805.1421 */1422 if ( PHP_VERSION_ID >= 80112 ) {1423 $woff_mime_type = 'font/woff';1424 }1425 1426 $expected = array(1427 'ext' => 'woff',1428 'type' => $woff_mime_type,1429 'proper_filename' => false,1430 );1431 1432 add_filter(1433 'upload_mimes',1434 static function( $mimes ) use ( $woff_mime_type ) {1435 $mimes['woff'] = $woff_mime_type;1436 return $mimes;1437 }1438 );1439 1440 $this->assertSame( $expected, wp_check_filetype_and_ext( $file, $filename ) );1441 }1442 1443 /**1444 * Data provider for test_wp_get_image_mime().1445 */1446 public function wp_get_image_mime() {1447 $data = array(1448 // Standard JPEG.1449 array(1450 DIR_TESTDATA . '/images/test-image.jpg',1451 'image/jpeg',1452 ),1453 // Standard GIF.1454 array(1455 DIR_TESTDATA . '/images/test-image.gif',1456 'image/gif',1457 ),1458 // Standard PNG.1459 array(1460 DIR_TESTDATA . '/images/test-image.png',1461 'image/png',1462 ),1463 // Image with wrong extension.1464 array(1465 DIR_TESTDATA . '/images/test-image-mime-jpg.png',1466 'image/jpeg',1467 ),1468 // Animated WebP.1469 array(1470 DIR_TESTDATA . '/images/webp-animated.webp',1471 'image/webp',1472 ),1473 // Lossless WebP.1474 array(1475 DIR_TESTDATA . '/images/webp-lossless.webp',1476 'image/webp',1477 ),1478 // Lossy WebP.1479 array(1480 DIR_TESTDATA . '/images/webp-lossy.webp',1481 'image/webp',1482 ),1483 // Transparent WebP.1484 array(1485 DIR_TESTDATA . '/images/webp-transparent.webp',1486 'image/webp',1487 ),1488 // Not an image.1489 array(1490 DIR_TESTDATA . '/uploads/dashicons.woff',1491 false,1492 ),1493 );1494 1495 return $data;1496 }1497 1498 /**1499 1426 * Data profider for test_wp_getimagesize(). 1500 1427 */ … … 1599 1526 } 1600 1527 1601 public function wp_check_filetype_and_ext_data() { 1528 /** 1529 * @ticket 39550 1530 * @dataProvider data_wp_check_filetype_and_ext 1531 * @requires extension fileinfo 1532 */ 1533 public function test_wp_check_filetype_and_ext( $file, $filename, $expected ) { 1534 $this->assertSame( $expected, wp_check_filetype_and_ext( $file, $filename ) ); 1535 } 1536 1537 public function data_wp_check_filetype_and_ext() { 1602 1538 $data = array( 1603 1539 // Standard image. … … 1765 1701 1766 1702 /** 1703 * @ticket 39550 1704 * @group ms-excluded 1705 * @requires extension fileinfo 1706 */ 1707 public function test_wp_check_filetype_and_ext_with_filtered_svg() { 1708 $file = DIR_TESTDATA . '/uploads/video-play.svg'; 1709 $filename = 'video-play.svg'; 1710 1711 $expected = array( 1712 'ext' => 'svg', 1713 'type' => 'image/svg+xml', 1714 'proper_filename' => false, 1715 ); 1716 1717 add_filter( 1718 'upload_mimes', 1719 static function( $mimes ) { 1720 $mimes['svg'] = 'image/svg+xml'; 1721 return $mimes; 1722 } 1723 ); 1724 1725 $this->assertSame( $expected, wp_check_filetype_and_ext( $file, $filename ) ); 1726 } 1727 1728 /** 1729 * @ticket 39550 1730 * @group ms-excluded 1731 * @requires extension fileinfo 1732 */ 1733 public function test_wp_check_filetype_and_ext_with_filtered_woff() { 1734 $file = DIR_TESTDATA . '/uploads/dashicons.woff'; 1735 $filename = 'dashicons.woff'; 1736 1737 $woff_mime_type = 'application/font-woff'; 1738 1739 /* 1740 * As of PHP 8.1.12, which includes libmagic/file update to version 5.42, 1741 * the expected mime type for WOFF files is 'font/woff'. 1742 * 1743 * See https://github.com/php/php-src/issues/8805. 1744 */ 1745 if ( PHP_VERSION_ID >= 80112 ) { 1746 $woff_mime_type = 'font/woff'; 1747 } 1748 1749 $expected = array( 1750 'ext' => 'woff', 1751 'type' => $woff_mime_type, 1752 'proper_filename' => false, 1753 ); 1754 1755 add_filter( 1756 'upload_mimes', 1757 static function( $mimes ) use ( $woff_mime_type ) { 1758 $mimes['woff'] = $woff_mime_type; 1759 return $mimes; 1760 } 1761 ); 1762 1763 $this->assertSame( $expected, wp_check_filetype_and_ext( $file, $filename ) ); 1764 } 1765 1766 /** 1767 1767 * Test file path validation 1768 1768 * 1769 1769 * @ticket 42016 1770 * @dataProvider data_test_validate_file ()1770 * @dataProvider data_test_validate_file 1771 1771 * 1772 1772 * @param string $file File path. … … 1965 1965 1966 1966 /** 1967 * Data provider for test_duration_format().1967 * Data provider for test_duration_format(). 1968 1968 * 1969 1969 * @return array {
Note: See TracChangeset
for help on using the changeset viewer.