Merge pull request #2401 from jrfnl/feature/tests-reorganize-17
Tests: move file name to type tests to own file
This commit is contained in:
commit
69655d247a
|
|
@ -0,0 +1,75 @@
|
|||
<?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;
|
||||
|
||||
/**
|
||||
* Test file name to type functionality.
|
||||
*
|
||||
* @covers \PHPMailer\PHPMailer\PHPMailer::filenameToType
|
||||
*/
|
||||
final class FilenameToTypeTest extends TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Verify mapping a file name to a MIME type.
|
||||
*
|
||||
* @dataProvider dataFilenameToType
|
||||
*
|
||||
* @param string $filename Filename input.
|
||||
* @param string $expected Expected function output.
|
||||
*/
|
||||
public function testFilenameToType($filename, $expected)
|
||||
{
|
||||
$result = PHPMailer::filenameToType($filename);
|
||||
self::assertSame($expected, $result, 'Failed to map file name to a MIME type');
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
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',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -1374,17 +1374,6 @@ EOT;
|
|||
self::assertSame('飛兒樂 團光茫.mp3', $q['basename'], 'Windows basename not matched');
|
||||
self::assertSame('mp3', $q['extension'], 'Windows extension not matched');
|
||||
self::assertSame('飛兒樂 團光茫', $q['filename'], 'Windows filename not matched');
|
||||
|
||||
self::assertSame(
|
||||
'image/jpeg',
|
||||
PHPMailer::filenameToType('abc.jpg?xyz=1'),
|
||||
'Query string not ignored in filename'
|
||||
);
|
||||
self::assertSame(
|
||||
'application/octet-stream',
|
||||
PHPMailer::filenameToType('abc.xyzpdq'),
|
||||
'Default MIME type not applied to unknown extension'
|
||||
);
|
||||
}
|
||||
|
||||
public function testBadSMTP()
|
||||
|
|
|
|||
Loading…
Reference in New Issue