<?php
/**
* PHPMailer - PHP email transport unit tests.
* PHP version 5.5.
*
* @author Marcus Bointon <phpmailer@synchromedia.co.uk>
* @author Andy Prevost
* @copyright 2012 - 2020 Marcus Bointon
* @copyright 2004 - 2009 Andy Prevost
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
*/
namespace PHPMailer\Test\PHPMailer;
use PHPMailer\PHPMailer\PHPMailer;
use Yoast\PHPUnitPolyfills\TestCases\TestCase;
final class FilenameToTypeTest extends TestCase
{
public function testFilenameToType($filename, $expected)
{
$result = PHPMailer::filenameToType($filename);
self::assertSame($expected, $result, 'Failed to map file name to a MIME type');
}
public function dataFilenameToType()
{
return [
'Empty string' => [
'filename' => '',
'expected' => 'application/octet-stream',
],
'File name without query string' => [
'filename' => 'abc.png',
'expected' => 'image/png',
],
'File name with query string' => [
'filename' => 'abc.jpg?xyz=1',
'expected' => 'image/jpeg',
],
'Full path to file, linux style' => [
'filename' => '/usr/sbin/subdir/docs.pdf',
'expected' => 'application/pdf',
],
'Full path to file, windows style' => [
'filename' => 'D:\subdir\with spaces\subdir\myapp.zip',
'expected' => 'application/zip',
],
'Unknown extension, should return default MIME type' => [
'filename' => 'abc.xyzpdq',
'expected' => 'application/octet-stream',
],
];
}
}