Make WordPress Core

Ticket #47701: 47701.patch

File 47701.patch, 7.1 KB (added by pbearne, 6 years ago)

new unit test

  • tests/phpunit/tests/functions/wpGetMimeTypes.php

     
     1<?php
     2
     3/**
     4 * Test list_files().
     5 *
     6 * @group functions.php
     7 */
     8class Tests_wp_get_mime_types extends WP_UnitTestCase {
     9
     10        public function test_all_mime_match() {
     11                $extected = array(
     12                        // Image formats.
     13                        'jpg|jpeg|jpe'                 => 'image/jpeg',
     14                        'gif'                          => 'image/gif',
     15                        'png'                          => 'image/png',
     16                        'bmp'                          => 'image/bmp',
     17                        'tiff|tif'                     => 'image/tiff',
     18                        'ico'                          => 'image/x-icon',
     19                        // Video formats.
     20                        'asf|asx'                      => 'video/x-ms-asf',
     21                        'wmv'                          => 'video/x-ms-wmv',
     22                        'wmx'                          => 'video/x-ms-wmx',
     23                        'wm'                           => 'video/x-ms-wm',
     24                        'avi'                          => 'video/avi',
     25                        'divx'                         => 'video/divx',
     26                        'flv'                          => 'video/x-flv',
     27                        'mov|qt'                       => 'video/quicktime',
     28                        'mpeg|mpg|mpe'                 => 'video/mpeg',
     29                        'mp4|m4v'                      => 'video/mp4',
     30                        'ogv'                          => 'video/ogg',
     31                        'webm'                         => 'video/webm',
     32                        'mkv'                          => 'video/x-matroska',
     33                        '3gp|3gpp'                     => 'video/3gpp', // Can also be audio
     34                        '3g2|3gp2'                     => 'video/3gpp2', // Can also be audio
     35                        // Text formats.
     36                        'txt|asc|c|cc|h|srt'           => 'text/plain',
     37                        'csv'                          => 'text/csv',
     38                        'tsv'                          => 'text/tab-separated-values',
     39                        'ics'                          => 'text/calendar',
     40                        'rtx'                          => 'text/richtext',
     41                        'css'                          => 'text/css',
     42                        'htm|html'                     => 'text/html',
     43                        'vtt'                          => 'text/vtt',
     44                        'dfxp'                         => 'application/ttaf+xml',
     45                        // Audio formats.
     46                        'mp3|m4a|m4b'                  => 'audio/mpeg',
     47                        'aac'                          => 'audio/aac',
     48                        'ra|ram'                       => 'audio/x-realaudio',
     49                        'wav'                          => 'audio/wav',
     50                        'ogg|oga'                      => 'audio/ogg',
     51                        'flac'                         => 'audio/flac',
     52                        'mid|midi'                     => 'audio/midi',
     53                        'wma'                          => 'audio/x-ms-wma',
     54                        'wax'                          => 'audio/x-ms-wax',
     55                        'mka'                          => 'audio/x-matroska',
     56                        // Misc application formats.
     57                        'rtf'                          => 'application/rtf',
     58                        'js'                           => 'application/javascript',
     59                        'pdf'                          => 'application/pdf',
     60                        'swf'                          => 'application/x-shockwave-flash',
     61                        'class'                        => 'application/java',
     62                        'tar'                          => 'application/x-tar',
     63                        'zip'                          => 'application/zip',
     64                        'gz|gzip'                      => 'application/x-gzip',
     65                        'rar'                          => 'application/rar',
     66                        '7z'                           => 'application/x-7z-compressed',
     67                        'exe'                          => 'application/x-msdownload',
     68                        'psd'                          => 'application/octet-stream',
     69                        'xcf'                          => 'application/octet-stream',
     70                        // MS Office formats.
     71                        'doc'                          => 'application/msword',
     72                        'pot|pps|ppt'                  => 'application/vnd.ms-powerpoint',
     73                        'wri'                          => 'application/vnd.ms-write',
     74                        'xla|xls|xlt|xlw'              => 'application/vnd.ms-excel',
     75                        'mdb'                          => 'application/vnd.ms-access',
     76                        'mpp'                          => 'application/vnd.ms-project',
     77                        'docx'                         => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
     78                        'docm'                         => 'application/vnd.ms-word.document.macroEnabled.12',
     79                        'dotx'                         => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template',
     80                        'dotm'                         => 'application/vnd.ms-word.template.macroEnabled.12',
     81                        'xlsx'                         => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
     82                        'xlsm'                         => 'application/vnd.ms-excel.sheet.macroEnabled.12',
     83                        'xlsb'                         => 'application/vnd.ms-excel.sheet.binary.macroEnabled.12',
     84                        'xltx'                         => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template',
     85                        'xltm'                         => 'application/vnd.ms-excel.template.macroEnabled.12',
     86                        'xlam'                         => 'application/vnd.ms-excel.addin.macroEnabled.12',
     87                        'pptx'                         => 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
     88                        'pptm'                         => 'application/vnd.ms-powerpoint.presentation.macroEnabled.12',
     89                        'ppsx'                         => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow',
     90                        'ppsm'                         => 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12',
     91                        'potx'                         => 'application/vnd.openxmlformats-officedocument.presentationml.template',
     92                        'potm'                         => 'application/vnd.ms-powerpoint.template.macroEnabled.12',
     93                        'ppam'                         => 'application/vnd.ms-powerpoint.addin.macroEnabled.12',
     94                        'sldx'                         => 'application/vnd.openxmlformats-officedocument.presentationml.slide',
     95                        'sldm'                         => 'application/vnd.ms-powerpoint.slide.macroEnabled.12',
     96                        'onetoc|onetoc2|onetmp|onepkg' => 'application/onenote',
     97                        'oxps'                         => 'application/oxps',
     98                        'xps'                          => 'application/vnd.ms-xpsdocument',
     99                        // OpenOffice formats.
     100                        'odt'                          => 'application/vnd.oasis.opendocument.text',
     101                        'odp'                          => 'application/vnd.oasis.opendocument.presentation',
     102                        'ods'                          => 'application/vnd.oasis.opendocument.spreadsheet',
     103                        'odg'                          => 'application/vnd.oasis.opendocument.graphics',
     104                        'odc'                          => 'application/vnd.oasis.opendocument.chart',
     105                        'odb'                          => 'application/vnd.oasis.opendocument.database',
     106                        'odf'                          => 'application/vnd.oasis.opendocument.formula',
     107                        // WordPerfect formats.
     108                        'wp|wpd'                       => 'application/wordperfect',
     109                        // iWork formats.
     110                        'key'                          => 'application/vnd.apple.keynote',
     111                        'numbers'                      => 'application/vnd.apple.numbers',
     112                        'pages'                        => 'application/vnd.apple.pages',
     113                );
     114
     115                $this->assertSame( $extected, wp_get_mime_types() );
     116
     117        }
     118
     119        public function test_mime_filter() {
     120                add_filter( 'mime_types', function() {
     121
     122                        return 'changed';
     123                } );
     124
     125                $this->assertSame( 'changed', wp_get_mime_types() );
     126        }
     127
     128
     129}