Make WordPress Core

Changeset 55464


Ignore:
Timestamp:
03/06/2023 01:08:03 PM (4 years ago)
Author:
SergeyBiryukov
Message:

Tests: Move some data providers in Tests_Functions next to the tests they are used in.

Includes renaming some data provider methods to use the data_ prefix for consistency.

Follow-up to [36832], [40124], [40397], [50810], [53457].

See #56793.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/functions.php

    r55462 r55464  
    134134         *
    135135         * @ticket 55897
    136          * @dataProvider path_join_data_provider
     136         * @dataProvider data_path_join
    137137         */
    138138        public function test_path_join( $base, $path, $expected ) {
     
    145145         * @return string[][]
    146146         */
    147         public function path_join_data_provider() {
     147        public function data_path_join() {
    148148                return array(
    149149                        // Absolute paths.
     
    11591159        /**
    11601160         * @ticket 36054
    1161          * @dataProvider datetime_provider
     1161         * @dataProvider data_mysql_to_rfc3339
    11621162         */
    11631163        public function test_mysql_to_rfc3339( $expected, $actual ) {
     
    11701170        }
    11711171
    1172         public function datetime_provider() {
     1172        public function data_mysql_to_rfc3339() {
    11731173                return array(
    11741174                        array( '2016-03-15T18:54:46', '15-03-2016 18:54:46' ),
     
    13351335        /**
    13361336         * @ticket 40017
    1337          * @dataProvider wp_get_image_mime
     1337         * @dataProvider data_wp_get_image_mime
    13381338         */
    13391339        public function test_wp_get_image_mime( $file, $expected ) {
     
    13431343
    13441344                $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;
    13451400        }
    13461401
     
    13691424
    13701425        /**
    1371          * @ticket 39550
    1372          * @dataProvider wp_check_filetype_and_ext_data
    1373          * @requires extension fileinfo
    1374          */
    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 39550
    1381          * @group ms-excluded
    1382          * @requires extension fileinfo
    1383          */
    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 39550
    1407          * @group ms-excluded
    1408          * @requires extension fileinfo
    1409          */
    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         /**
    14991426         * Data profider for test_wp_getimagesize().
    15001427         */
     
    15991526        }
    16001527
    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() {
    16021538                $data = array(
    16031539                        // Standard image.
     
    17651701
    17661702        /**
     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        /**
    17671767         * Test file path validation
    17681768         *
    17691769         * @ticket 42016
    1770          * @dataProvider data_test_validate_file()
     1770         * @dataProvider data_test_validate_file
    17711771         *
    17721772         * @param string $file          File path.
     
    19651965
    19661966        /**
    1967          * Dataprovider for test_duration_format().
     1967         * Data provider for test_duration_format().
    19681968         *
    19691969         * @return array {
Note: See TracChangeset for help on using the changeset viewer.