tao-test/app/tao/test/unit/models/classes/websource/BaseWebsourceTest.php

69 lines
1.8 KiB
PHP

<?php
namespace oat\tao\test\model\websource;
use oat\generis\test\TestCase;
use oat\oatbox\filesystem\FileSystem;
use oat\tao\model\websource\BaseWebsource;
use oat\generis\test\MockObject;
class BaseWebsourceTest extends TestCase
{
/** @var BaseWebsource | MockObject */
private $baseWebsource;
public function setUp(): void
{
$this->baseWebsource = $this->getMockForAbstractClass(
BaseWebsource::class,
[],
'',
true,
true,
true,
['getFileSystem']
);
}
/**
* @dataProvider mimeTypeProvider
*/
public function testGetMimetype($fileName, $mimeType, $expectedMimeType)
{
$this->baseWebsource
->method('getFileSystem')
->willReturn($this->getFileSystemMockWithMimeType($mimeType))
;
$this->assertEquals($expectedMimeType, $this->baseWebsource->getMimetype($fileName));
}
public function mimeTypeProvider()
{
return [
['test.js', 'text/plain', 'text/javascript'],
['test.js', 'text/x-asm', 'text/javascript'],
['test.js', 'text/x-c', 'text/javascript'],
['test.css', 'text/plain', 'text/css'],
['test.css', 'text/x-asm', 'text/css'],
['test.svg', 'text/plain', 'image/svg+xml'],
['test.mp3', 'test/test', 'audio/mpeg'],
['test.test', 'test/test', 'test/test'],
];
}
private function getFileSystemMockWithMimeType($mimeType)
{
$fileSystemMock = $this
->getMockBuilder(FileSystem::class)
->disableOriginalConstructor()
->getMock();
$fileSystemMock
->method('getMimetype')
->willReturn($mimeType);
return $fileSystemMock;
}
}