default services conflit ?

This commit is contained in:
armansansd
2022-04-27 11:30:43 +02:00
parent 28190a5749
commit 8bb1064a3b
8132 changed files with 900138 additions and 426 deletions

View File

@@ -0,0 +1,275 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mime-info [
<!ELEMENT mime-info (mime-type)+>
<!ATTLIST mime-info xmlns CDATA #FIXED "http://www.freedesktop.org/standards/shared-mime-info">
<!ELEMENT mime-type (comment+, (acronym,expanded-acronym)? , (icon? | generic-icon? | glob | magic | treemagic | root-XML | alias | sub-class-of)*)>
<!ATTLIST mime-type type CDATA #REQUIRED>
<!-- a comment describing a document with the respective MIME type. Example: "WMV video" -->
<!ELEMENT comment (#PCDATA)>
<!ATTLIST comment xml:lang CDATA #IMPLIED>
<!-- a comment describing the respective unexpanded MIME type acronym. Example: "WMV" -->
<!ELEMENT acronym (#PCDATA)>
<!ATTLIST acronym xml:lang CDATA #IMPLIED>
<!-- a comment describing the respective expanded MIME type acronym. Example: "Windows Media Video" -->
<!ELEMENT expanded-acronym (#PCDATA)>
<!ATTLIST expanded-acronym xml:lang CDATA #IMPLIED>
<!ELEMENT icon EMPTY>
<!ATTLIST icon name CDATA #REQUIRED>
<!-- a generic icon name as per the Icon Naming Specification, only required if computing
it from the mime-type would not work, See "generic-icon" in the Shared Mime Specification -->
<!ELEMENT generic-icon EMPTY>
<!ATTLIST generic-icon name (application-x-executable|audio-x-generic|folder|font-x-generic|image-x-generic|package-x-generic|text-html|text-x-generic|text-x-generic-template|text-x-script|video-x-generic|x-office-address-book|x-office-calendar|x-office-document|x-office-presentation|x-office-spreadsheet) #REQUIRED>
<!ELEMENT glob EMPTY>
<!ATTLIST glob pattern CDATA #REQUIRED>
<!ATTLIST glob weight CDATA "50">
<!ATTLIST glob case-sensitive CDATA #IMPLIED>
<!ELEMENT magic (match)+>
<!ATTLIST magic priority CDATA "50">
<!ELEMENT match (match)*>
<!ATTLIST match offset CDATA #REQUIRED>
<!ATTLIST match type (string|big16|big32|little16|little32|host16|host32|byte) #REQUIRED>
<!ATTLIST match value CDATA #REQUIRED>
<!ATTLIST match mask CDATA #IMPLIED>
<!ELEMENT treemagic (treematch)+>
<!ATTLIST treemagic priority CDATA "50">
<!ELEMENT treematch (treematch)*>
<!ATTLIST treematch path CDATA #REQUIRED>
<!ATTLIST treematch type (file|directory|link) #IMPLIED>
<!ATTLIST treematch match-case (true|false) #IMPLIED>
<!ATTLIST treematch executable (true|false) #IMPLIED>
<!ATTLIST treematch non-empty (true|false) #IMPLIED>
<!ATTLIST treematch mimetype CDATA #IMPLIED>
<!ELEMENT root-XML EMPTY>
<!ATTLIST root-XML namespaceURI CDATA #REQUIRED>
<!ATTLIST root-XML localName CDATA #REQUIRED>
<!ELEMENT alias EMPTY>
<!ATTLIST alias type CDATA #REQUIRED>
<!ELEMENT sub-class-of EMPTY>
<!ATTLIST sub-class-of type CDATA #REQUIRED>
]>
<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
<mime-type type="application/x-atari-2600-rom">
<comment>Atari 2600</comment>
<comment xml:lang="ast">Atari 2600</comment>
<comment xml:lang="ca">Atari 2600</comment>
<comment xml:lang="cs">Atari 2600</comment>
<comment xml:lang="da">Atari 2600</comment>
<comment xml:lang="de">Atari 2600</comment>
<comment xml:lang="en_GB">Atari 2600</comment>
<comment xml:lang="es">Atari 2600</comment>
<comment xml:lang="eu">Atari 2600</comment>
<comment xml:lang="fi">Atari 2600</comment>
<comment xml:lang="fr">Atari 2600</comment>
<comment xml:lang="ga">Atari 2600</comment>
<comment xml:lang="he">אטארי 2600</comment>
<comment xml:lang="hr">Atari 2600</comment>
<comment xml:lang="hu">Atari 2600</comment>
<comment xml:lang="id">Atari 2600</comment>
<comment xml:lang="it">Atari 2600</comment>
<comment xml:lang="kk">Atari 2600</comment>
<comment xml:lang="ko">Atari 2600</comment>
<comment xml:lang="oc">Atari 2600</comment>
<comment xml:lang="pl">Atari 2600</comment>
<comment xml:lang="pt_BR">Atari 2600</comment>
<comment xml:lang="ru">Atari 2600</comment>
<comment xml:lang="sk">Atari 2600</comment>
<comment xml:lang="sr">Атари 2600</comment>
<comment xml:lang="sv">Atari 2600</comment>
<comment xml:lang="tr">Atari 2600</comment>
<comment xml:lang="uk">Atari 2600</comment>
<comment xml:lang="zh_CN">雅达利 2600</comment>
<comment xml:lang="zh_TW">Atari 2600</comment>
<generic-icon name="application-x-executable"/>
<glob pattern="*.a26"/>
</mime-type>
<mime-type type="text/htmlh">
<comment>help page</comment>
<comment xml:lang="ar">صفحة المساعدة</comment>
<comment xml:lang="az">yardım səhifəsi</comment>
<comment xml:lang="be@latin">staronka dapamohi</comment>
<comment xml:lang="bg">Страница от помощта</comment>
<comment xml:lang="ca">pàgina d'ajuda</comment>
<comment xml:lang="cs">stránka nápovědy</comment>
<comment xml:lang="cy">tudalen gymorth</comment>
<comment xml:lang="da">hjælpeside</comment>
<comment xml:lang="de">Hilfeseite</comment>
<comment xml:lang="el">Σελίδα βοήθειας</comment>
<comment xml:lang="en_GB">help page</comment>
<comment xml:lang="eo">help-paĝo</comment>
<comment xml:lang="es">página de ayuda</comment>
<comment xml:lang="eu">laguntzako orria</comment>
<comment xml:lang="fi">ohjesivu</comment>
<comment xml:lang="fo">hjálparsíða</comment>
<comment xml:lang="fr">page d'aide</comment>
<comment xml:lang="ga">leathanach cabhrach</comment>
<comment xml:lang="gl">páxina de axuda</comment>
<comment xml:lang="he">דף עזרה</comment>
<comment xml:lang="hr">Stranica pomoći</comment>
<comment xml:lang="hu">súgóoldal</comment>
<comment xml:lang="ia">Pagina de adjuta</comment>
<comment xml:lang="id">halaman bantuan</comment>
<comment xml:lang="it">Pagina di aiuto</comment>
<comment xml:lang="ja">ヘルプページ</comment>
<comment xml:lang="kk">анықтама парағы</comment>
<comment xml:lang="ko">도움말 페이지</comment>
<comment xml:lang="lt">žinyno puslapis</comment>
<comment xml:lang="lv">palīdzības lapa</comment>
<comment xml:lang="ms">Halaman bantuan</comment>
<comment xml:lang="nb">hjelpside</comment>
<comment xml:lang="nl">hulppagina</comment>
<comment xml:lang="nn">hjelpeside</comment>
<comment xml:lang="oc">pagina d'ajuda</comment>
<comment xml:lang="pl">Strona pomocy</comment>
<comment xml:lang="pt">página de ajuda</comment>
<comment xml:lang="pt_BR">Página de ajuda</comment>
<comment xml:lang="ro">pagină de ajutor</comment>
<comment xml:lang="ru">Страница справки</comment>
<comment xml:lang="sk">Stránka Pomocníka</comment>
<comment xml:lang="sl">stran pomoči</comment>
<comment xml:lang="sq">Faqe ndihme</comment>
<comment xml:lang="sr">страница помоћи</comment>
<comment xml:lang="sv">hjälpsida</comment>
<comment xml:lang="tr">yardım sayfası</comment>
<comment xml:lang="uk">сторінка довідки</comment>
<comment xml:lang="vi">trang trợ giúp</comment>
<comment xml:lang="zh_CN">帮助页面</comment>
<comment xml:lang="zh_TW">求助頁面</comment>
<sub-class-of type="text/plain"/>
</mime-type>
<mime-type type="text/plain">
<comment>plain text document</comment>
<comment xml:lang="ar">مستند نصي مجرد</comment>
<comment xml:lang="ast">documentu de testu planu</comment>
<comment xml:lang="be@latin">prosty tekstavy dakument</comment>
<comment xml:lang="bg">Документ с неформатиран текст</comment>
<comment xml:lang="ca">document de text pla</comment>
<comment xml:lang="cs">prostý textový dokument</comment>
<comment xml:lang="da">rent tekstdokument</comment>
<comment xml:lang="de">Einfaches Textdokument</comment>
<comment xml:lang="el">Έγγραφο απλού κειμένου</comment>
<comment xml:lang="en_GB">plain text document</comment>
<comment xml:lang="eo">plata teksta dokumento</comment>
<comment xml:lang="es">documento de texto sencillo</comment>
<comment xml:lang="eu">testu soileko dokumentua</comment>
<comment xml:lang="fi">perustekstiasiakirja</comment>
<comment xml:lang="fr">document texte brut</comment>
<comment xml:lang="ga">cáipéis ghnáth-théacs</comment>
<comment xml:lang="gl">documento de texto sinxelo</comment>
<comment xml:lang="he">מסמך טקסט פשוט</comment>
<comment xml:lang="hr">Običan tekstovni dokument</comment>
<comment xml:lang="hu">egyszerű szöveg</comment>
<comment xml:lang="ia">Documento de texto simple</comment>
<comment xml:lang="id">dokumen teks polos</comment>
<comment xml:lang="it">Documento in testo semplice</comment>
<comment xml:lang="ja">平文テキストドキュメント</comment>
<comment xml:lang="kk">мәтіндік құжаты</comment>
<comment xml:lang="ko">일반 텍스트 문서</comment>
<comment xml:lang="lt">paprastas tekstinis dokumentas</comment>
<comment xml:lang="lv">vienkāršs teksta dokuments</comment>
<comment xml:lang="ms">Dokumen teks jernih</comment>
<comment xml:lang="nb">vanlig tekstdokument</comment>
<comment xml:lang="nl">plattetekst-document</comment>
<comment xml:lang="nn">vanleg tekstdokument</comment>
<comment xml:lang="oc">document tèxte brut</comment>
<comment xml:lang="pl">Zwykły dokument tekstowy</comment>
<comment xml:lang="pt">documento em texto simples</comment>
<comment xml:lang="pt_BR">Documento de Texto</comment>
<comment xml:lang="ro">document text simplu</comment>
<comment xml:lang="ru">Текстовый документ</comment>
<comment xml:lang="sk">Obyčajný textový dokument</comment>
<comment xml:lang="sl">običajna besedilna datoteka</comment>
<comment xml:lang="sq">Dokument në tekst të thjeshtë</comment>
<comment xml:lang="sr">обичан текстуални документ</comment>
<comment xml:lang="sv">vanligt textdokument</comment>
<comment xml:lang="tr">düz metin belgesi</comment>
<comment xml:lang="uk">звичайний текстовий документ</comment>
<comment xml:lang="vi">tài liệu nhập thô</comment>
<comment xml:lang="zh_CN">纯文本文档</comment>
<comment xml:lang="zh_TW">純文字文件</comment>
<magic priority="50">
<match value="This is TeX," type="string" offset="0"/>
<match value="This is METAFONT," type="string" offset="0"/>
</magic>
<glob pattern="*.txt"/>
<glob pattern="*.asc"/>
<glob pattern="*,v"/>
</mime-type>
<mime-type type="application/pdf">
<comment>PDF document</comment>
<comment xml:lang="ar">مستند PDF</comment>
<comment xml:lang="ast">Documentu PDF</comment>
<comment xml:lang="be@latin">Dakument PDF</comment>
<comment xml:lang="bg">Документ — PDF</comment>
<comment xml:lang="ca">document PDF</comment>
<comment xml:lang="cs">dokument PDF</comment>
<comment xml:lang="cy">Dogfen PDF</comment>
<comment xml:lang="da">PDF-dokument</comment>
<comment xml:lang="de">PDF-Dokument</comment>
<comment xml:lang="el">Έγγραφο PDF</comment>
<comment xml:lang="en_GB">PDF document</comment>
<comment xml:lang="eo">PDF-dokumento</comment>
<comment xml:lang="es">documento PDF</comment>
<comment xml:lang="eu">PDF dokumentua</comment>
<comment xml:lang="fi">PDF-asiakirja</comment>
<comment xml:lang="fo">PDF skjal</comment>
<comment xml:lang="fr">document PDF</comment>
<comment xml:lang="ga">cáipéis PDF</comment>
<comment xml:lang="gl">documento PDF</comment>
<comment xml:lang="he">מסמך PDF</comment>
<comment xml:lang="hr">PDF dokument</comment>
<comment xml:lang="hu">PDF-dokumentum</comment>
<comment xml:lang="ia">Documento PDF</comment>
<comment xml:lang="id">Dokumen PDF</comment>
<comment xml:lang="it">Documento PDF</comment>
<comment xml:lang="ja">PDF ドキュメント</comment>
<comment xml:lang="kk">PDF құжаты</comment>
<comment xml:lang="ko">PDF 문서</comment>
<comment xml:lang="lt">PDF dokumentas</comment>
<comment xml:lang="lv">PDF dokuments</comment>
<comment xml:lang="ms">Dokumen PDF</comment>
<comment xml:lang="nb">PDF-dokument</comment>
<comment xml:lang="nl">PDF-document</comment>
<comment xml:lang="nn">PDF-dokument</comment>
<comment xml:lang="oc">document PDF</comment>
<comment xml:lang="pl">Dokument PDF</comment>
<comment xml:lang="pt">documento PDF</comment>
<comment xml:lang="pt_BR">Documento PDF</comment>
<comment xml:lang="ro">Document PDF</comment>
<comment xml:lang="ru">Документ PDF</comment>
<comment xml:lang="sk">Dokument PDF</comment>
<comment xml:lang="sl">Dokument PDF</comment>
<comment xml:lang="sq">Dokument PDF</comment>
<comment xml:lang="sr">ПДФ документ</comment>
<comment xml:lang="sv">PDF-dokument</comment>
<comment xml:lang="tr">PDF belgesi</comment>
<comment xml:lang="uk">документ PDF</comment>
<comment xml:lang="vi">Tài liệu PDF</comment>
<comment xml:lang="zh_CN">PDF 文档</comment>
<comment xml:lang="zh_TW">PDF 文件</comment>
<acronym>PDF</acronym>
<expanded-acronym>Portable Document Format</expanded-acronym>
<generic-icon name="x-office-document"/>
<magic priority="50">
<match value="%PDF-" type="string" offset="0:1024"/>
</magic>
<glob pattern="*.pdf"/>
<alias type="application/x-pdf"/>
<alias type="image/pdf"/>
<alias type="application/acrobat"/>
<alias type="application/nappdf"/>
</mime-type>
</mime-info>

View File

@@ -0,0 +1,8 @@
# This file maps Internet media types to unique file extension(s).
#
# This is a subset version for testing purposes.
#
# MIME type (lowercased) Extensions
# ============================================ ==========
image/jpeg jpeg jpg jpe
text/plain txt

View File

@@ -0,0 +1,22 @@
# This file maps Internet media types to unique file extension(s).
#
# This is a subset version for testing purposes.
# MIME type (lowercased) Extensions
# ============================================ ==========
# application/edi-consent
# application/edi-x12
# application/edifact
application/octet-stream bin dms lrf mar so dist distz pkg bpk dump elc deploy
application/pls+xml pls
audio/midi mid midi kar rmi
# audio/mobile-xmf
audio/mp4 m4a mp4a
image/jpeg jpeg jpg jpe
image/sgi sgi
image/svg+xml svg svgz
# image/t38
image/tiff tiff tif
text/css css
text/csv csv
text/plain txt text conf def list log in

View File

@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mime-info [
<!ELEMENT mime-info (mime-type)+>
<!ATTLIST mime-info xmlns CDATA #FIXED "http://www.freedesktop.org/standards/shared-mime-info">
<!ELEMENT mime-type (comment+, (acronym,expanded-acronym)? , (icon? | generic-icon? | glob | magic | treemagic | root-XML | alias | sub-class-of)*)>
<!ATTLIST mime-type type CDATA #REQUIRED>
<!-- a comment describing a document with the respective MIME type. Example: "WMV video" -->
<!ELEMENT comment (#PCDATA)>
<!ATTLIST comment xml:lang CDATA #IMPLIED>
<!-- a comment describing the respective unexpanded MIME type acronym. Example: "WMV" -->
<!ELEMENT acronym (#PCDATA)>
<!ATTLIST acronym xml:lang CDATA #IMPLIED>
<!-- a comment describing the respective expanded MIME type acronym. Example: "Windows Media Video" -->
<!ELEMENT expanded-acronym (#PCDATA)>
<!ATTLIST expanded-acronym xml:lang CDATA #IMPLIED>
<!ELEMENT icon EMPTY>
<!ATTLIST icon name CDATA #REQUIRED>
<!-- a generic icon name as per the Icon Naming Specification, only required if computing
it from the mime-type would not work, See "generic-icon" in the Shared Mime Specification -->
<!ELEMENT generic-icon EMPTY>
<!ATTLIST generic-icon name (application-x-executable|audio-x-generic|folder|font-x-generic|image-x-generic|package-x-generic|text-html|text-x-generic|text-x-generic-template|text-x-script|video-x-generic|x-office-address-book|x-office-calendar|x-office-document|x-office-presentation|x-office-spreadsheet) #REQUIRED>
<!ELEMENT glob EMPTY>
<!ATTLIST glob pattern CDATA #REQUIRED>
<!ATTLIST glob weight CDATA "50">
<!ATTLIST glob case-sensitive CDATA #IMPLIED>
<!ELEMENT magic (match)+>
<!ATTLIST magic priority CDATA "50">
<!ELEMENT match (match)*>
<!ATTLIST match offset CDATA #REQUIRED>
<!ATTLIST match type (string|big16|big32|little16|little32|host16|host32|byte) #REQUIRED>
<!ATTLIST match value CDATA #REQUIRED>
<!ATTLIST match mask CDATA #IMPLIED>
<!ELEMENT treemagic (treematch)+>
<!ATTLIST treemagic priority CDATA "50">
<!ELEMENT treematch (treematch)*>
<!ATTLIST treematch path CDATA #REQUIRED>
<!ATTLIST treematch type (file|directory|link) #IMPLIED>
<!ATTLIST treematch match-case (true|false) #IMPLIED>
<!ATTLIST treematch executable (true|false) #IMPLIED>
<!ATTLIST treematch non-empty (true|false) #IMPLIED>
<!ATTLIST treematch mimetype CDATA #IMPLIED>
<!ELEMENT root-XML EMPTY>
<!ATTLIST root-XML namespaceURI CDATA #REQUIRED>
<!ATTLIST root-XML localName CDATA #REQUIRED>
<!ELEMENT alias EMPTY>
<!ATTLIST alias type CDATA #REQUIRED>
<!ELEMENT sub-class-of EMPTY>
<!ATTLIST sub-class-of type CDATA #REQUIRED>
]>
<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
</mime-info>

View File

@@ -0,0 +1,45 @@
<?php
namespace FileEye\MimeMap\Test;
use FileEye\MimeMap\Extension;
use FileEye\MimeMap\MappingException;
class ExtensionTest extends MimeMapTestBase
{
public function testGetDefaultType()
{
$this->assertSame('text/plain', (new Extension('txt'))->getDefaultType());
$this->assertSame('text/plain', (new Extension('TXT'))->getDefaultType());
$this->assertSame('image/png', (new Extension('png'))->getDefaultType());
$this->assertSame('application/vnd.oasis.opendocument.text', (new Extension('odt'))->getDefaultType());
}
public function testGetStrictDefaultTypeUnknownExtension()
{
$this->expectException(MappingException::class);
$this->assertSame('application/octet-stream', (new Extension('ohmygodthatisnoextension'))->getDefaultType());
}
public function testGetNoStrictDefaultTypeUnknownExtension()
{
$this->assertSame('application/octet-stream', (new Extension('ohmygodthatisnoextension'))->getDefaultType(false));
}
public function testGetTypes()
{
$this->assertSame(['text/vnd.dvb.subtitle', 'image/vnd.dvb.subtitle', 'text/x-microdvd', 'text/x-mpsub', 'text/x-subviewer'], (new Extension('sub'))->getTypes());
$this->assertSame(['text/vnd.dvb.subtitle', 'image/vnd.dvb.subtitle', 'text/x-microdvd', 'text/x-mpsub', 'text/x-subviewer'], (new Extension('sUb'))->getTypes());
}
public function testGetStrictTypesUnknownExtension()
{
$this->expectException(MappingException::class);
$this->assertSame(['application/octet-stream'], (new Extension('ohmygodthatisnoextension'))->getTypes());
}
public function testGetNoStrictTypesUnknownExtension()
{
$this->assertSame(['application/octet-stream'], (new Extension('ohmygodthatisnoextension'))->getTypes(false));
}
}

View File

@@ -0,0 +1,301 @@
<?php
namespace FileEye\MimeMap\Test;
use FileEye\MimeMap\Extension;
use FileEye\MimeMap\MalformedTypeException;
use FileEye\MimeMap\MapHandler;
use FileEye\MimeMap\MappingException;
use FileEye\MimeMap\Type;
/**
* @backupStaticAttributes enabled
*/
class MapHandlerTest extends MimeMapTestBase
{
protected $map;
public function fcSetUp()
{
$this->map = MapHandler::map();
}
public function testMap()
{
$this->assertStringContainsString('DefaultMap.php', $this->map->getFileName());
}
public function testSort()
{
$this->map->addTypeExtensionMapping('aaa/aaa', '000a')->sort();
$this->assertSame('aaa/aaa', $this->map->listTypes()[0]);
$this->assertSame('000a', $this->map->listExtensions()[0]);
}
public function testAdd()
{
// Adding a new type with a new extension.
$this->map->addTypeExtensionMapping('bingo/bongo', 'bngbng');
$this->assertSame(['bngbng'], (new Type('bingo/bongo'))->getExtensions());
$this->assertSame('bngbng', (new Type('bingo/bongo'))->getDefaultExtension());
$this->assertSame(['bingo/bongo'], (new Extension('bngbng'))->getTypes());
$this->assertSame('bingo/bongo', (new Extension('bngbng'))->getDefaultType());
// Adding an already existing mapping should not duplicate entries.
$this->map->addTypeExtensionMapping('bingo/bongo', 'bngbng');
$this->assertSame(['bngbng'], (new Type('bingo/bongo'))->getExtensions());
$this->assertSame(['bingo/bongo'], (new Extension('bngbng'))->getTypes());
// Adding another extension to existing type.
$this->map->addTypeExtensionMapping('bingo/bongo', 'bigbog');
$this->assertSame(['bngbng', 'bigbog'], (new Type('bingo/bongo'))->getExtensions());
$this->assertSame(['bingo/bongo'], (new Extension('bigbog'))->getTypes());
// Adding another type to existing extension.
$this->map->addTypeExtensionMapping('boing/being', 'bngbng');
$this->assertSame(['bngbng'], (new Type('boing/being'))->getExtensions());
$this->assertSame(['bingo/bongo', 'boing/being'], (new Extension('bngbng'))->getTypes());
}
public function testRemove()
{
$this->assertSame(['txt', 'text', 'conf', 'def', 'list', 'log', 'in', 'asc'], (new Type('text/plain'))->getExtensions());
$this->assertSame('txt', (new Type('text/plain'))->getDefaultExtension());
$this->assertSame(['text/plain'], (new Extension('txt'))->getTypes());
$this->assertSame('text/plain', (new Extension('txt'))->getDefaultType());
// Remove an existing type-extension pair.
$this->assertTrue($this->map->removeTypeExtensionMapping('text/plain', 'txt'));
$this->assertSame(['text', 'conf', 'def', 'list', 'log', 'in', 'asc'], (new Type('text/plain'))->getExtensions());
$this->assertSame('text', (new Type('text/plain'))->getDefaultExtension());
$this->assertSame(['application/octet-stream'], (new Extension('txt'))->getTypes(false));
$this->assertSame('application/octet-stream', (new Extension('txt'))->getDefaultType(false));
// Try removing a non-existing extension.
$this->assertFalse($this->map->removeTypeExtensionMapping('text/plain', 'axx'));
// Remove an existing alias.
$this->assertSame(['application/x-pdf', 'image/pdf', 'application/acrobat', 'application/nappdf'], (new Type('application/pdf'))->getAliases());
$this->assertTrue($this->map->removeTypeAlias('application/pdf', 'application/x-pdf'));
$this->assertSame(['image/pdf', 'application/acrobat', 'application/nappdf'], (new Type('application/pdf'))->getAliases());
// Try removing a non-existing alias.
$this->assertFalse($this->map->removeTypeAlias('application/pdf', 'foo/bar'));
$this->assertSame(['image/pdf', 'application/acrobat', 'application/nappdf'], (new Type('application/pdf'))->getAliases());
// Remove an existing type.
$this->assertTrue($this->map->removeType('text/plain'));
$this->assertSame([], (new Type('text/plain'))->getExtensions(false));
$this->assertSame(null, (new Type('text/plain'))->getDefaultExtension(false));
$this->assertSame(['application/octet-stream'], (new Extension('DEf'))->getTypes(false));
$this->assertSame('application/octet-stream', (new Extension('DeF'))->getDefaultType(false));
// Remove an existing type with aliases.
$this->assertTrue($this->map->hasAlias('text/x-markdown'));
$this->assertTrue($this->map->removeType('text/markdown'));
$this->assertFalse($this->map->hasAlias('text/x-markdown'));
$this->assertSame([], (new Type('text/markdown'))->getExtensions(false));
$this->assertSame(null, (new Type('text/markdown'))->getDefaultExtension(false));
$this->assertSame([], (new Type('text/x-markdown'))->getExtensions(false));
$this->assertSame(null, (new Type('text/x-markdown'))->getDefaultExtension(false));
$this->assertSame(['application/octet-stream'], (new Extension('MD'))->getTypes(false));
$this->assertSame('application/octet-stream', (new Extension('md'))->getDefaultType(false));
// Try removing a non-existing type.
$this->assertFalse($this->map->removeType('axx/axx'));
}
public function testHasType()
{
$this->assertTrue($this->map->hasType('text/plain'));
$this->assertFalse($this->map->hasType('foo/bar'));
}
public function testHasAlias()
{
$this->assertTrue($this->map->hasAlias('application/acrobat'));
$this->assertFalse($this->map->hasAlias('foo/bar'));
}
public function testHasExtension()
{
$this->assertTrue($this->map->hasExtension('jpg'));
$this->assertFalse($this->map->hasExtension('jpgjpg'));
}
public function testSetExtensionDefaultType()
{
$this->assertSame(['text/vnd.dvb.subtitle', 'image/vnd.dvb.subtitle', 'text/x-microdvd', 'text/x-mpsub', 'text/x-subviewer'], (new Extension('sub'))->getTypes());
$this->map->setExtensionDefaultType('SUB', 'image/vnd.dvb.subtitle');
$this->assertSame(['image/vnd.dvb.subtitle', 'text/vnd.dvb.subtitle', 'text/x-microdvd', 'text/x-mpsub', 'text/x-subviewer'], (new Extension('SUB'))->getTypes());
}
public function testReAddAliasToType()
{
$this->assertSame(['image/psd', 'image/x-psd', 'image/photoshop', 'image/x-photoshop', 'application/photoshop', 'application/x-photoshop',], (new Type('image/vnd.adobe.photoshop'))->getAliases());
$this->map->addTypeAlias('image/vnd.adobe.photoshop', 'application/x-photoshop');
$this->assertSame(['image/psd', 'image/x-psd', 'image/photoshop', 'image/x-photoshop', 'application/photoshop', 'application/x-photoshop',], (new Type('image/vnd.adobe.photoshop'))->getAliases());
}
public function testAddAliasToMultipleTypes()
{
$this->assertSame([], (new Type('text/plain'))->getAliases());
$this->bcSetExpectedException(MappingException::class, "Cannot set 'application/x-photoshop' as alias for 'text/plain', it is an alias of 'image/vnd.adobe.photoshop' already");
$this->map->addTypeAlias('text/plain', 'application/x-photoshop');
$this->assertSame([], (new Type('text/plain'))->getAliases());
}
public function testAddAliasToMissingType()
{
$this->bcSetExpectedException(MappingException::class, "Cannot set 'baz/qoo' as alias for 'bar/foo', 'bar/foo' not defined");
$this->map->addTypeAlias('bar/foo', 'baz/qoo');
}
public function testAddAliasIsATypeAlready()
{
$this->bcSetExpectedException(MappingException::class, "Cannot set 'text/plain' as alias for 'text/richtext', 'text/plain' is already defined as a type");
$this->map->addTypeAlias('text/richtext', 'text/plain');
}
public function testAddDescriptionToAlias()
{
$this->bcSetExpectedException(MappingException::class, "Cannot add description for 'application/acrobat', 'application/acrobat' is an alias");
$this->map->addTypeDescription('application/acrobat', 'description of alias');
}
public function testSetExtensionDefaultTypeNoExtension()
{
$this->expectException(MappingException::class);
$this->map->setExtensionDefaultType('zxzx', 'image/vnd.dvb.subtitle');
}
public function testSetExtensionDefaultTypeNoType()
{
$this->expectException(MappingException::class);
$this->map->setExtensionDefaultType('sub', 'image/bingo');
}
/**
* Check that a type alias can be set as extension default.
*/
public function testSetExtensionDefaultTypeToAlias()
{
$this->assertSame(['application/pdf'], (new Extension('pdf'))->getTypes());
$this->map->setExtensionDefaultType('pdf', 'application/x-pdf');
$this->assertSame(['application/x-pdf', 'application/pdf'], (new Extension('pdf'))->getTypes());
$this->assertSame('application/x-pdf', (new Extension('pdf'))->getDefaultType());
$this->map->setExtensionDefaultType('pdf', 'image/pdf');
$this->assertSame(['image/pdf', 'application/x-pdf', 'application/pdf'], (new Extension('pdf'))->getTypes());
$this->assertSame('image/pdf', (new Extension('pdf'))->getDefaultType());
// Remove the alias, should be removed from extension types.
$this->assertTrue($this->map->removeTypeAlias('application/pdf', 'application/x-pdf'));
$this->assertSame(['image/pdf', 'application/pdf'], (new Extension('pdf'))->getTypes());
$this->assertSame('image/pdf', (new Extension('pdf'))->getDefaultType());
// Add a fake MIME type to 'psd', an alias to that, then remove
// 'image/vnd.adobe.photoshop'.
$this->assertSame(['image/vnd.adobe.photoshop'], (new Extension('psd'))->getTypes());
$this->assertSame('image/vnd.adobe.photoshop', (new Extension('psd'))->getDefaultType());
$this->map->setExtensionDefaultType('psd', 'image/psd');
$this->assertSame(['image/psd', 'image/vnd.adobe.photoshop'], (new Extension('psd'))->getTypes());
$this->assertSame('image/psd', (new Extension('psd'))->getDefaultType());
$this->map->addTypeExtensionMapping('bingo/bongo', 'psd');
$this->assertSame(['image/psd', 'image/vnd.adobe.photoshop', 'bingo/bongo'], (new Extension('psd'))->getTypes());
$this->map->addTypeAlias('bingo/bongo', 'bar/foo');
$this->assertSame(['image/psd', 'image/vnd.adobe.photoshop', 'bingo/bongo'], (new Extension('psd'))->getTypes());
$this->map->setExtensionDefaultType('psd', 'bar/foo');
$this->assertSame(['bar/foo', 'image/psd', 'image/vnd.adobe.photoshop', 'bingo/bongo'], (new Extension('psd'))->getTypes());
$this->assertTrue($this->map->removeType('image/vnd.adobe.photoshop'));
$this->assertSame(['bar/foo', 'bingo/bongo'], (new Extension('psd'))->getTypes());
}
/**
* Check removing an aliased type mapping.
*/
public function testRemoveAliasedTypeMapping()
{
$this->map->addTypeExtensionMapping('bingo/bongo', 'psd');
$this->assertSame(['image/vnd.adobe.photoshop', 'bingo/bongo'], (new Extension('psd'))->getTypes());
$this->map->addTypeAlias('bingo/bongo', 'bar/foo');
$this->assertSame(['image/vnd.adobe.photoshop', 'bingo/bongo'], (new Extension('psd'))->getTypes());
$this->map->setExtensionDefaultType('psd', 'bar/foo');
$this->assertSame(['bar/foo', 'image/vnd.adobe.photoshop', 'bingo/bongo'], (new Extension('psd'))->getTypes());
$this->map->removeTypeExtensionMapping('bar/foo', 'psd');
$this->assertSame(['image/vnd.adobe.photoshop', 'bingo/bongo'], (new Extension('psd'))->getTypes());
}
/**
* Check that a removing a type mapping also remove its aliases.
*/
public function testRemoveUnaliasedTypeMapping()
{
// Add a fake MIME type to 'psd', an alias to that, then remove
// 'image/vnd.adobe.photoshop'.
$this->map->addTypeExtensionMapping('bingo/bongo', 'psd');
$this->assertSame(['image/vnd.adobe.photoshop', 'bingo/bongo'], (new Extension('psd'))->getTypes());
$this->map->addTypeAlias('bingo/bongo', 'bar/foo');
$this->assertSame(['image/vnd.adobe.photoshop', 'bingo/bongo'], (new Extension('psd'))->getTypes());
$this->map->setExtensionDefaultType('psd', 'bar/foo');
$this->assertSame(['bar/foo', 'image/vnd.adobe.photoshop', 'bingo/bongo'], (new Extension('psd'))->getTypes());
$this->map->removeTypeExtensionMapping('bingo/bongo', 'psd');
$this->assertSame(['image/vnd.adobe.photoshop'], (new Extension('psd'))->getTypes());
}
public function testSetExtensionDefaultTypeToInvalidAlias()
{
$this->bcSetExpectedException(MappingException::class, "Cannot set 'image/psd' as default type for extension 'pdf', its unaliased type 'image/vnd.adobe.photoshop' is not associated to 'pdf'");
$this->map->setExtensionDefaultType('pdf', 'image/psd');
}
public function testSetTypeDefaultExtension()
{
$this->assertSame(['jpeg', 'jpg', 'jpe'], (new Type('image/jpeg'))->getExtensions());
$this->map->setTypeDefaultExtension('image/jpeg', 'jpg');
$this->assertSame(['jpg', 'jpeg', 'jpe'], (new Type('image/JPEG'))->getExtensions());
}
public function testSetTypeDefaultExtensionNoExtension()
{
$this->expectException(MappingException::class);
$this->map->setTypeDefaultExtension('image/jpeg', 'zxzx');
}
public function testSetTypeDefaultExtensionNoType()
{
$this->expectException(MappingException::class);
$this->map->setTypeDefaultExtension('image/bingo', 'jpg');
}
public function testAddExtensionToAlias()
{
$this->bcSetExpectedException(MappingException::class, "Cannot map 'pdf' to 'application/acrobat', 'application/acrobat' is an alias");
$this->map->addTypeExtensionMapping('application/acrobat', 'pdf');
}
/**
* Data provider for testAddMalformedTypeExtensionMapping.
*/
public function malformedTypeProvider()
{
return [
'empty string' => [''],
'n' => ['n'],
'no media' => ['/n'],
'no sub type' => ['n/'],
'no comment closing bracket a' => ['image (open ()/*'],
'no comment closing bracket b' => ['image / * (open (())'],
];
}
/**
* @dataProvider malformedTypeProvider
*/
public function testAddMalformedTypeExtensionMapping($type)
{
$this->expectException(MalformedTypeException::class);
$this->map->addTypeExtensionMapping($type, 'xxx');
}
}

View File

@@ -0,0 +1,144 @@
<?php
namespace FileEye\MimeMap\Test;
use Symfony\Component\Filesystem\Filesystem;
use FileEye\MimeMap\MapHandler;
use FileEye\MimeMap\MapUpdater;
/**
* @coversDefaultClass \FileEye\MimeMap\MapUpdater
* @backupStaticAttributes enabled
*/
class MapUpdaterTest extends MimeMapTestBase
{
protected $newMap;
protected $updater;
protected $fileSystem;
public function fcSetUp()
{
$this->updater = new MapUpdater();
$this->updater->selectBaseMap(MapUpdater::DEFAULT_BASE_MAP_CLASS);
$this->newMap = $this->updater->getMap();
$this->assertInstanceOf(MapUpdater::DEFAULT_BASE_MAP_CLASS, $this->newMap);
$this->fileSystem = new Filesystem();
}
public function fcTearDown()
{
$this->assertInstanceOf(MapUpdater::DEFAULT_BASE_MAP_CLASS, $this->newMap);
$this->newMap->reset();
}
public function testLoadMapFromApacheFile()
{
$this->updater->loadMapFromApacheFile(dirname(__FILE__) . '/../fixtures/min.mime-types.txt');
$expected = [
't' => [
'image/jpeg' => ['e' => ['jpeg', 'jpg', 'jpe']],
'text/plain' => ['e' => ['txt']],
],
'e' => [
'jpe' => ['t' => ['image/jpeg']],
'jpeg' => ['t' => ['image/jpeg']],
'jpg' => ['t' => ['image/jpeg']],
'txt' => ['t' => ['text/plain']],
],
];
$this->assertSame($expected, $this->newMap->getMapArray());
$this->assertSame(['image/jpeg', 'text/plain'], $this->newMap->listTypes());
$this->assertSame(['jpe', 'jpeg', 'jpg', 'txt'], $this->newMap->listExtensions());
$this->assertSame([], $this->newMap->listAliases());
}
public function testLoadMapFromApacheFileZeroLines()
{
$this->updater->loadMapFromApacheFile(dirname(__FILE__) . '/../fixtures/zero.mime-types.txt');
$this->assertSame([], $this->newMap->getMapArray());
}
public function testApplyOverridesFailure()
{
$this->updater->loadMapFromFreedesktopFile(dirname(__FILE__) . '/../fixtures/min.freedesktop.xml');
$errors = $this->updater->applyOverrides([['addTypeExtensionMapping', ['application/x-pdf', 'pdf']]]);
$this->assertSame(["Cannot map 'pdf' to 'application/x-pdf', 'application/x-pdf' is an alias"], $errors);
}
public function testLoadMapFromFreedesktopFile()
{
$this->updater->applyOverrides([['addTypeExtensionMapping', ['application/x-pdf', 'pdf']]]);
$errors = $this->updater->loadMapFromFreedesktopFile(dirname(__FILE__) . '/../fixtures/min.freedesktop.xml');
$this->assertSame(["Cannot set 'application/x-pdf' as alias for 'application/pdf', 'application/x-pdf' is already defined as a type"], $errors);
$expected = [
't' => [
'application/pdf' => [
'a' => ['image/pdf', 'application/acrobat', 'application/nappdf'],
'desc' => ['PDF document', 'PDF: Portable Document Format'],
'e' => ['pdf']
],
'application/x-atari-2600-rom' => [
'desc' => ['Atari 2600'],
'e' => ['a26']
],
'application/x-pdf' => [
'e' => ['pdf']
],
'text/plain' => [
'desc' => ['plain text document'],
'e' => ['txt', 'asc']
],
],
'e' => [
'a26' => ['t' => ['application/x-atari-2600-rom']],
'asc' => ['t' => ['text/plain']],
'pdf' => ['t' => ['application/x-pdf', 'application/pdf']],
'txt' => ['t' => ['text/plain']],
],
'a' => [
'application/acrobat' => ['t' => ['application/pdf']],
'application/nappdf' => ['t' => ['application/pdf']],
'image/pdf' => ['t' => ['application/pdf']],
],
];
$this->assertSame($expected, $this->newMap->getMapArray());
$this->assertSame(['application/pdf', 'application/x-atari-2600-rom', 'application/x-pdf', 'text/plain'], $this->newMap->listTypes());
$this->assertSame(['a26', 'asc', 'pdf', 'txt'], $this->newMap->listExtensions());
$this->assertSame(['application/acrobat', 'application/nappdf', 'image/pdf'], $this->newMap->listAliases());
}
public function testLoadMapFromFreedesktopFileZeroLines()
{
$this->updater->loadMapFromFreedesktopFile(dirname(__FILE__) . '/../fixtures/zero.freedesktop.xml');
$this->assertSame([], $this->newMap->getMapArray());
}
public function testEmptyMapNotWriteable()
{
$this->expectException('LogicException');
$this->assertNull($this->newMap->getFileName());
}
public function testWriteMapToPhpClassFile()
{
$this->fileSystem->copy(__DIR__ . '/../../src/Map/MiniMap.php.test', __DIR__ . '/../../src/Map/MiniMap.php');
MapHandler::setDefaultMapClass('\FileEye\MimeMap\Map\MiniMap');
$map_a = MapHandler::map();
$this->assertStringContainsString('src/Map/MiniMap.php', $map_a->getFileName());
$content = file_get_contents($map_a->getFileName());
$this->assertStringNotContainsString('text/plain', $content);
$this->updater->loadMapFromApacheFile(dirname(__FILE__) . '/../fixtures/min.mime-types.txt');
$this->updater->applyOverrides([['addTypeExtensionMapping', ['bing/bong', 'binbon']]]);
$this->updater->writeMapToPhpClassFile($map_a->getFileName());
$content = file_get_contents($map_a->getFileName());
$this->assertStringContainsString('text/plain', $content);
$this->assertStringContainsString('bing/bong', $content);
$this->assertStringContainsString('binbon', $content);
$this->fileSystem->remove(__DIR__ . '/../../src/Map/MiniMap.php');
}
public function testGetDefaultMapBuildFile()
{
$this->assertStringContainsString('default_map_build.yml', MapUpdater::getDefaultMapBuildFile());
}
}

View File

@@ -0,0 +1,27 @@
<?php
namespace FileEye\MimeMap\Test;
use FileEye\MimeMap\Extension;
use PHPUnit\Framework\TestCase;
use PHPUnit\Runner\Version;
// In order to manage different method signatures between PHPUnit versions, we
// dynamically load a compatibility trait dependent on the PHPUnit runner
// version.
// phpcs:disable
if (!trait_exists('FileEye\MimeMap\Test\PhpunitCompatibilityTrait', false)) {
if (class_exists('PHPUnit\Runner\Version') && version_compare(Version::id(), '8.0.0', '>=')) {
class_alias('FileEye\MimeMap\Test\Phpunit8CompatibilityTrait', 'FileEye\MimeMap\Test\PhpunitCompatibilityTrait');
} elseif (class_exists('PHPUnit\Runner\Version') && version_compare(Version::id(), '7.0.0', '>=')) {
class_alias('FileEye\MimeMap\Test\Phpunit7CompatibilityTrait', 'FileEye\MimeMap\Test\PhpunitCompatibilityTrait');
} else {
class_alias('FileEye\MimeMap\Test\Phpunit5CompatibilityTrait', 'FileEye\MimeMap\Test\PhpunitCompatibilityTrait');
}
}
// phpcs:enable
class MimeMapTestBase extends TestCase
{
use PhpunitCompatibilityTrait;
}

View File

@@ -0,0 +1,81 @@
<?php
namespace FileEye\MimeMap\Test;
// PHPUnit compatibility trait for PHPUnit 5.
trait Phpunit5CompatibilityTrait
{
/**
* Checks if the trait is used in a class that has a method.
*
* @param string $method
* Method to check.
*
* @return bool
* TRUE if the method is supported, FALSE if not.
*/
private function supports($method)
{
// Get the parent class of the currently running test class.
$parent = get_parent_class($this);
// Ensure that the method_exists() check on the createMock method is carried
// out on the first parent of $this that does not have access to this
// trait's methods. This is because the trait also has a method called
// createMock(). Most often the check will be made on
// \PHPUnit\Framework\TestCase.
while (method_exists($parent, 'supports')) {
$parent = get_parent_class($parent);
}
return method_exists($parent, $method);
}
public function setUp()
{
parent::setUp();
if (method_exists($this, 'fcSetUp')) {
$this->fcSetUp();
}
}
public function tearDown()
{
if (method_exists($this, 'fcTearDown')) {
$this->fcTearDown();
}
parent::tearDown();
}
public function bcSetExpectedException($exceptionName, $exceptionMessage = '', $exceptionCode = null)
{
if ($this->supports('expectException')) {
parent::expectException($exceptionName);
if ($exceptionMessage) {
parent::expectExceptionMessage($exceptionMessage);
}
if ($exceptionCode !== null) {
parent::expectExceptionCode($exceptionCode);
}
} else {
parent::setExpectedException($exceptionName, $exceptionMessage, $exceptionCode);
}
}
public function expectException($exception)
{
if ($this->supports('expectException')) {
parent::expectException($exception);
} else {
parent::setExpectedException($exception);
}
}
public function assertStringContainsString($needle, $haystack, $message = '')
{
parent::assertContains($needle, $haystack, $message);
}
public function assertStringNotContainsString($needle, $haystack, $message = '')
{
parent::assertNotContains($needle, $haystack, $message);
}
}

View File

@@ -0,0 +1,34 @@
<?php
namespace FileEye\MimeMap\Test;
// PHPUnit compatibility trait for PHPUnit 7.
trait Phpunit7CompatibilityTrait
{
public function setUp()
{
parent::setUp();
if (method_exists($this, 'fcSetUp')) {
$this->fcSetUp();
}
}
public function tearDown()
{
if (method_exists($this, 'fcTearDown')) {
$this->fcTearDown();
}
parent::tearDown();
}
public function bcSetExpectedException($exceptionName, $exceptionMessage = '', $exceptionCode = null)
{
parent::expectException($exceptionName);
if ($exceptionMessage) {
parent::expectExceptionMessage($exceptionMessage);
}
if ($exceptionCode !== null) {
parent::expectExceptionCode($exceptionCode);
}
}
}

View File

@@ -0,0 +1,34 @@
<?php
namespace FileEye\MimeMap\Test;
// PHPUnit compatibility trait for PHPUnit 8.
trait Phpunit8CompatibilityTrait
{
public function setUp(): void
{
parent::setUp();
if (method_exists($this, 'fcSetUp')) {
$this->fcSetUp();
}
}
public function tearDown(): void
{
if (method_exists($this, 'fcTearDown')) {
$this->fcTearDown();
}
parent::tearDown();
}
public function bcSetExpectedException($exceptionName, $exceptionMessage = '', $exceptionCode = null)
{
parent::expectException($exceptionName);
if ($exceptionMessage) {
parent::expectExceptionMessage($exceptionMessage);
}
if ($exceptionCode !== null) {
parent::expectExceptionCode($exceptionCode);
}
}
}

View File

@@ -0,0 +1,35 @@
<?php
namespace FileEye\MimeMap\Test;
use FileEye\MimeMap\Type;
use FileEye\MimeMap\TypeParameter;
class TypeParameterTest extends MimeMapTestBase
{
public function testHasComment()
{
$mt = new Type('image/png; a="parameter" (with a comment)');
$this->assertSame('a', $mt->getParameter('a')->getName());
$this->assertSame('parameter', $mt->getParameter('a')->getValue());
$this->assertTrue($mt->getParameter('a')->hasComment());
$this->assertSame('with a comment', $mt->getParameter('a')->getComment());
$mt = new Type('image/png;param=foo(with a comment)');
$this->assertSame('param', $mt->getParameter('param')->getName());
$this->assertSame('foo', $mt->getParameter('param')->getValue());
$this->assertTrue($mt->getParameter('param')->hasComment());
$this->assertSame('with a comment', $mt->getParameter('param')->getComment());
}
public function testHasCommentNegative()
{
$mt = new Type('image/png; a="parameter"');
$this->assertSame('a', $mt->getParameter('a')->getName());
$this->assertSame('parameter', $mt->getParameter('a')->getValue());
$this->assertFalse($mt->getParameter('a')->hasComment());
$mt = new Type('image/png;foo=bar');
$this->assertSame('foo', $mt->getParameter('foo')->getName());
$this->assertSame('bar', $mt->getParameter('foo')->getValue());
$this->assertFalse($mt->getParameter('foo')->hasComment());
}
}

View File

@@ -0,0 +1,657 @@
<?php
namespace FileEye\MimeMap\Test;
use FileEye\MimeMap\MalformedTypeException;
use FileEye\MimeMap\MappingException;
use FileEye\MimeMap\Type;
use FileEye\MimeMap\TypeParameter;
class TypeTest extends MimeMapTestBase
{
/**
* Data provider for testParse.
*/
public function parseProvider()
{
return [
'application/ogg;description=Hello there!;asd=fgh' => [
'application/ogg;description=Hello there!;asd=fgh',
[
'application/ogg',
'application/ogg; description="Hello there!"; asd="fgh"',
'application/ogg; description="Hello there!"; asd="fgh"',
],
['application', null],
['ogg', null],
true,
[
'description' => ['Hello there!', null],
'asd' => ['fgh', null],
],
],
'text/plain' => [
'text/plain',
[
'text/plain',
'text/plain',
'text/plain',
],
['text', null],
['plain', null],
false,
[],
],
'text/plain;a=b' => [
'text/plain;a=b',
[
'text/plain',
'text/plain; a="b"',
'text/plain; a="b"',
],
['text', null],
['plain', null],
true,
[
'a' => ['b', null],
],
],
'application/ogg' => [
'application/ogg',
[
'application/ogg',
'application/ogg',
'application/ogg',
],
['application', null],
['ogg', null],
false,
[],
],
'*/*' => [
'*/*',
[
'*/*',
'*/*',
'*/*',
],
['*', null],
['*', null],
false,
[],
],
'n/n' => [
'n/n',
[
'n/n',
'n/n',
'n/n',
],
['n', null],
['n', null],
false,
[],
],
'(UTF-8 Plain Text) text / plain ; charset = utf-8' => [
'(UTF-8 Plain Text) text / plain ; charset = utf-8',
[
'text/plain',
'text/plain; charset="utf-8"',
'text (UTF-8 Plain Text)/plain; charset="utf-8"',
],
['text', 'UTF-8 Plain Text'],
['plain', null],
true,
[
'charset' => ['utf-8', null],
],
],
'text (Text) / plain ; charset = utf-8' => [
'text (Text) / plain ; charset = utf-8',
[
'text/plain',
'text/plain; charset="utf-8"',
'text (Text)/plain; charset="utf-8"',
],
['text', 'Text'],
['plain', null],
true,
[
'charset' => ['utf-8', null],
],
],
'text / (Plain) plain ; charset = utf-8' => [
'text / (Plain) plain ; charset = utf-8',
[
'text/plain',
'text/plain; charset="utf-8"',
'text/plain (Plain); charset="utf-8"',
],
['text', null],
['plain', 'Plain'],
true,
[
'charset' => ['utf-8', null],
],
],
'text / plain (Plain Text) ; charset = utf-8' => [
'text / plain (Plain Text) ; charset = utf-8',
[
'text/plain',
'text/plain; charset="utf-8"',
'text/plain (Plain Text); charset="utf-8"',
],
['text', null],
['plain', 'Plain Text'],
true,
[
'charset' => ['utf-8', null],
],
],
'text / plain ; (Charset=utf-8) charset = utf-8' => [
'text / plain ; (Charset=utf-8) charset = utf-8',
[
'text/plain',
'text/plain; charset="utf-8"',
'text/plain; charset="utf-8" (Charset=utf-8)',
],
['text', null],
['plain', null],
true,
[
'charset' => ['utf-8', 'Charset=utf-8'],
],
],
'text / plain ; charset (Charset) = utf-8' => [
'text / plain ; charset (Charset) = utf-8',
[
'text/plain',
'text/plain; charset="utf-8"',
'text/plain; charset="utf-8" (Charset)',
],
['text', null],
['plain', null],
true,
[
'charset' => ['utf-8', 'Charset'],
],
],
'text / plain ; charset = (UTF8) utf-8' => [
'text / plain ; charset = (UTF8) utf-8',
[
'text/plain',
'text/plain; charset="utf-8"',
'text/plain; charset="utf-8" (UTF8)',
],
['text', null],
['plain', null],
true,
[
'charset' => ['utf-8', 'UTF8'],
],
],
'text / plain ; charset = utf-8 (UTF-8 Plain Text)' => [
'text / plain ; charset = utf-8 (UTF-8 Plain Text)',
[
'text/plain',
'text/plain; charset="utf-8"',
'text/plain; charset="utf-8" (UTF-8 Plain Text)',
],
['text', null],
['plain', null],
true,
[
'charset' => ['utf-8', 'UTF-8 Plain Text'],
],
],
'application/x-foobar;description="bbgh(kdur"' => [
'application/x-foobar;description="bbgh(kdur"',
[
'application/x-foobar',
'application/x-foobar; description="bbgh(kdur"',
'application/x-foobar; description="bbgh(kdur"',
],
['application', null],
['x-foobar', null],
true,
[
'description' => ['bbgh(kdur', null],
],
],
'application/x-foobar;description="a \"quoted string\""' => [
'application/x-foobar;description="a \"quoted string\""',
[
'application/x-foobar',
'application/x-foobar; description="a \"quoted string\""',
'application/x-foobar; description="a \"quoted string\""',
],
['application', null],
['x-foobar', null],
true,
[
'description' => ['a "quoted string"', null],
],
],
'text/xml;description=test' => [
'text/xml;description=test',
[
'text/xml',
'text/xml; description="test"',
'text/xml; description="test"',
],
['text', null],
['xml', null],
true,
[
'description' => ['test', null],
],
],
'text/xml;one=test;two=three' => [
'text/xml;one=test;two=three',
[
'text/xml',
'text/xml; one="test"; two="three"',
'text/xml; one="test"; two="three"',
],
['text', null],
['xml', null],
true,
[
'one' => ['test', null],
'two' => ['three', null],
],
],
'text/xml;one="test";two="three"' => [
'text/xml;one="test";two="three"',
[
'text/xml',
'text/xml; one="test"; two="three"',
'text/xml; one="test"; two="three"',
],
['text', null],
['xml', null],
true,
[
'one' => ['test', null],
'two' => ['three', null],
],
],
'text/xml; this="is"; a="parameter" (with a comment)' => [
'text/xml; this="is"; a="parameter" (with a comment)',
[
'text/xml',
'text/xml; this="is"; a="parameter"',
'text/xml; this="is"; a="parameter" (with a comment)',
],
['text', null],
['xml', null],
true,
[
'this' => ['is', null],
'a' => ['parameter', 'with a comment'],
],
],
// Various edge cases.
'null' => [
null,
[
null,
null,
null,
],
[null, null],
[null, null],
false,
[],
],
'text/plain; charset="utf-8" (UTF/8)' => [
'text/plain; charset="utf-8" (UTF/8)',
[
'text/plain',
'text/plain; charset="utf-8"',
'text/plain; charset="utf-8" (UTF/8)',
],
['text', null],
['plain', null],
true,
[
'charset' => ['utf-8', 'UTF/8'],
],
],
'appf/xml; a=b; b="parameter" (with; a comment) ;c=d; e=f (;) ; g=h ' => [
'appf/xml; a=b; b="parameter" (with; a comment) ;c=d; e=f (;) ; g=h ',
[
'appf/xml',
'appf/xml; a="b"; b="parameter"; c="d"; e="f"; g="h"',
'appf/xml; a="b"; b="parameter" (with; a comment); c="d"; e="f" (;); g="h"',
],
['appf', null],
['xml', null],
true,
[
'a' => ['b', null],
'b' => ['parameter', 'with; a comment'],
'c' => ['d', null],
'e' => ['f', ';'],
'g' => ['h', null],
],
],
'text/(abc)def(ghi)' => [
'text/(abc)def(ghi)',
[
'text/def',
'text/def',
'text/def (abc ghi)',
],
['text', null],
['def', 'abc ghi'],
false,
[],
],
'text/(abc)def' => [
'text/(abc)def',
[
'text/def',
'text/def',
'text/def (abc)',
],
['text', null],
['def', 'abc'],
false,
[],
],
'text/def(ghi)' => [
'text/def(ghi)',
[
'text/def',
'text/def',
'text/def (ghi)',
],
['text', null],
['def', 'ghi'],
false,
[],
],
'text/plain;a=(\)abc)def(\()' => [
'text/plain;a=(\)abc)def(\()',
[
'text/plain',
'text/plain; a="def"',
'text/plain; a="def" (\)abc \()',
],
['text', null],
['plain', null],
true,
[
'a' => ['def', '\)abc \('],
],
],
'text/plain;a=\\foo(abc)' => [
'text/plain;a=\\foo(abc)',
[
'text/plain',
'text/plain; a="foo"',
'text/plain; a="foo" (abc)',
],
['text', null],
['plain', null],
true,
[
'a' => ['foo', 'abc'],
],
],
'text/plain;a=(a"bc\)def")def' => [
'text/plain;a=(a"bc\)def")def',
[
'text/plain',
'text/plain; a="def"',
'text/plain; a="def" (a"bc\)def")',
],
['text', null],
['plain', null],
true,
[
'a' => ['def', 'a"bc\)def"'],
],
],
'text/plain;a="(abc)def"' => [
'text/plain;a="(abc)def"',
[
'text/plain',
'text/plain; a="(abc)def"',
'text/plain; a="(abc)def"',
],
['text', null],
['plain', null],
true,
[
'a' => ['(abc)def', null],
],
],
];
}
/**
* @dataProvider parseProvider
*/
public function testParse($type, array $expectedToString, array $expectedMedia, array $expectedSubType, $expectedHasParameters, array $expectedParameters)
{
$mt = new Type($type);
$this->assertSame($expectedMedia[0], $mt->getMedia());
$this->assertSame($expectedMedia[1], $mt->getMediaComment());
$this->assertSame($expectedSubType[0], $mt->getSubType());
$this->assertSame($expectedSubType[1], $mt->getSubTypeComment());
$this->assertSame($expectedHasParameters, $mt->hasParameters());
$this->assertSame(count($expectedParameters), count($mt->getParameters()));
foreach ($expectedParameters as $name => $param) {
$this->assertTrue(isset($mt->getParameters()[$name]));
$this->assertInstanceOf(TypeParameter::class, $mt->getParameter($name));
$this->assertSame($name, $mt->getParameter($name)->getName());
$this->assertSame($param[0], $mt->getParameter($name)->getValue());
$this->assertSame($param[1], $mt->getParameter($name)->getComment());
}
$this->assertSame($expectedToString[0], $mt->toString(Type::SHORT_TEXT));
$this->assertSame($expectedToString[1], $mt->toString(Type::FULL_TEXT));
$this->assertSame($expectedToString[2], $mt->toString(Type::FULL_TEXT_WITH_COMMENTS));
}
/**
* Data provider for testParseMalformed.
*/
public function parseMalformedProvider()
{
return [
'empty string' => [''],
'n' => ['n'],
'no media' => ['/n'],
'no sub type' => ['n/'],
'no comment closing bracket a' => ['image (open ()/*'],
'no comment closing bracket b' => ['image / * (open (())'],
];
}
/**
* @dataProvider parseMalformedProvider
*/
public function testParseMalformed($type)
{
$this->expectException(MalformedTypeException::class);
new Type($type);
}
public function testParseAgain()
{
$mt = new Type('application/ogg;description=Hello there!;asd=fgh');
$this->assertSame(2, count($mt->getParameters()));
$mt = new Type('text/plain;hello=there!');
$this->assertSame(1, count($mt->getParameters()));
}
public function testGetDescription()
{
$this->assertNull((new Type('*/*'))->getDescription());
$this->assertNull((new Type('image/*'))->getDescription());
$this->assertNull((new Type('application/java*'))->getDescription());
$this->assertNull((new Type('application/x-t3vm-image'))->getDescription());
$this->assertSame('HTML document', (new Type('text/html'))->getDescription());
$this->assertSame('HTML document, HTML: HyperText Markup Language', (new Type('text/html'))->getDescription(true));
$this->assertSame('GPX geographic data', (new Type('application/gpx+xml'))->getDescription());
$this->assertSame('GPX geographic data, GPX: GPS Exchange Format', (new Type('application/gpx+xml'))->getDescription(true));
$this->assertSame('GPX geographic data', (new Type('application/gpx'))->getDescription());
$this->assertSame('GPX geographic data, GPX: GPS Exchange Format', (new Type('application/gpx'))->getDescription(true));
$this->assertSame('GPX geographic data', (new Type('application/x-gpx'))->getDescription());
$this->assertSame('GPX geographic data, GPX: GPS Exchange Format', (new Type('application/x-gpx'))->getDescription(true));
}
public function testSetComment()
{
$type = new Type('text/x-test');
$type->setMediaComment('media comment');
$this->assertSame('text (media comment)/x-test', $type->toString(Type::FULL_TEXT_WITH_COMMENTS));
$type->setSubTypeComment('subtype comment');
$this->assertSame('text (media comment)/x-test (subtype comment)', $type->toString(Type::FULL_TEXT_WITH_COMMENTS));
$type->setMediaComment(null);
$this->assertSame('text/x-test (subtype comment)', $type->toString(Type::FULL_TEXT_WITH_COMMENTS));
$type->setSubTypeComment(null);
$this->assertSame('text/x-test', $type->toString(Type::FULL_TEXT_WITH_COMMENTS));
}
public function testIsExperimental()
{
$this->assertTrue((new Type('text/x-test'))->isExperimental());
$this->assertTrue((new Type('image/X-test'))->isExperimental());
$this->assertFalse((new Type('text/plain'))->isExperimental());
}
public function testIsVendor()
{
$this->assertTrue((new Type('application/vnd.openoffice'))->isVendor());
$this->assertFalse((new Type('application/vendor.openoffice'))->isVendor());
$this->assertFalse((new Type('vnd/fsck'))->isVendor());
}
public function testIsWildcard()
{
$this->assertTrue((new Type('*/*'))->isWildcard());
$this->assertTrue((new Type('image/*'))->isWildcard());
$this->assertFalse((new Type('text/plain'))->isWildcard());
$this->assertTrue((new Type('application/java*'))->isWildcard());
$this->assertTrue((new Type('application/java-*'))->isWildcard());
}
public function testIsAlias()
{
$this->assertFalse((new Type('*/*'))->isAlias());
$this->assertFalse((new Type('image/*'))->isAlias());
$this->assertFalse((new Type('text/plain'))->isAlias());
$this->assertFalse((new Type('application/java*'))->isAlias());
$this->assertTrue((new Type('text/x-markdown'))->isAlias());
}
public function testWildcardMatch()
{
$this->assertTrue((new Type('image/png'))->wildcardMatch('*/*'));
$this->assertTrue((new Type('image/png'))->wildcardMatch('image/*'));
$this->assertFalse((new Type('text/plain'))->wildcardMatch('image/*'));
$this->assertFalse((new Type('image/png'))->wildcardMatch('image/foo'));
$this->assertTrue((new Type('application/javascript'))->wildcardMatch('application/java*'));
$this->assertTrue((new Type('application/java-serialized-object'))->wildcardMatch('application/java-*'));
$this->assertFalse((new Type('application/javascript'))->wildcardMatch('application/java-*'));
}
public function testAddParameter()
{
$mt = new Type('image/png; foo=bar');
$mt->addParameter('baz', 'val', 'this is a comment');
$res = $mt->toString(Type::FULL_TEXT_WITH_COMMENTS);
$this->assertStringContainsString('foo=', $res);
$this->assertStringContainsString('bar', $res);
$this->assertStringContainsString('baz=', $res);
$this->assertStringContainsString('val', $res);
$this->assertStringContainsString('(this is a comment)', $res);
$this->assertSame('image/png; foo="bar"; baz="val" (this is a comment)', $res);
}
public function testRemoveParameter()
{
$mt = new Type('image/png; foo=bar;baz=val(this is a comment)');
$mt->removeParameter('foo');
$res = $mt->toString(Type::FULL_TEXT_WITH_COMMENTS);
$this->assertStringNotContainsString('foo=', $res);
$this->assertStringNotContainsString('bar', $res);
$this->assertStringContainsString('baz=', $res);
$this->assertSame('image/png; baz="val" (this is a comment)', $res);
}
public function testGetAliases()
{
$this->assertSame(['image/x-wmf', 'image/x-win-metafile', 'application/x-wmf', 'application/wmf', 'application/x-msmetafile'], (new Type('image/wmf'))->getAliases());
$this->assertSame([], (new Type('foo/bar'))->getAliases(false));
$this->assertSame([], (new Type('image/x-wmf'))->getAliases(false));
}
public function testGetAliasesOnAliasStrict()
{
$this->bcSetExpectedException(MappingException::class, "Cannot get aliases for 'image/x-wmf', it is an alias itself");
$this->assertSame([], (new Type('image/x-wmf'))->getAliases());
}
public function testGetAliasesOnMissingTypeStrict()
{
$this->bcSetExpectedException(MappingException::class, "No MIME type found for foo/bar in map");
$this->assertSame([], (new Type('foo/bar'))->getAliases());
}
public function testGetExtensions()
{
$this->assertEquals(['atom'], (new Type('application/atom+xml'))->getExtensions());
$this->assertEquals(['ser', 'js', 'jsm', 'mjs'], (new Type('application/java*'))->getExtensions());
$this->assertEquals(['ser'], (new Type('application/java-*'))->getExtensions());
$this->assertEquals([], (new Type('application/a000'))->getExtensions(false));
$this->assertEquals([], (new Type('application/a000-*'))->getExtensions(false));
$this->assertSame(['smi', 'smil', 'sml', 'kino'], (new Type('application/smil+xml'))->getExtensions());
$this->assertSame(['smi', 'smil', 'sml', 'kino'], (new Type('application/smil'))->getExtensions());
}
public function testGetExtensionsFail()
{
$this->expectException(MappingException::class);
$this->assertEquals([], (new Type('application/a000'))->getExtensions());
}
public function testGetDefaultExtension()
{
$this->assertEquals('atom', (new Type('application/atom+xml'))->getDefaultExtension());
$this->assertEquals('csv', (new Type('text/csv'))->getDefaultExtension());
$this->assertSame('smi', (new Type('application/smil+xml'))->getDefaultExtension());
$this->assertSame('smi', (new Type('application/smil'))->getDefaultExtension());
}
/**
* Data provider for testGetDefaultExtensionFail.
*/
public function getDefaultExtensionFailProvider()
{
return [
['*/*'],
['n/n'],
['image/*'],
['application/java*'],
];
}
/**
* @dataProvider getDefaultExtensionFailProvider
*/
public function testGetDefaultExtensionFail($type)
{
$this->expectException(MappingException::class);
$this->assertNull((new Type($type))->getDefaultExtension());
}
}

View File

@@ -0,0 +1,13 @@
<?php
namespace FileEye\MimeMap\Test;
use FileEye\MimeMap\Version;
class VersionTest extends MimeMapTestBase
{
public function testGet()
{
$this->assertNotNull(Version::get());
}
}