Debian Codegraph @

t/mime.t

raw
1 use strict;
2 use warnings;
3
4 use Test::More tests => 12;
5
6 BEGIN {
7 use_ok 'Dancer2::Core::MIME';
8 }
9
10 my $mime = Dancer2::Core::MIME->new();
11
12 is_deeply( $mime->custom_types, {}, 'user defined mime_types are empty' );
13
14 $mime->add_type( foo => 'text/foo' );
15 is_deeply( $mime->custom_types, { foo => 'text/foo' }, 'text/foo is saved' );
16 is( $mime->for_name('foo'), 'text/foo', 'mime type foo is found' );
17
18 $mime->add_alias( bar => 'foo' );
19 is( $mime->for_name('bar'), 'text/foo', 'mime type bar is found' );
20
21 is( $mime->for_file('foo.bar'),
22 'text/foo', 'mime type for extension .bar is found'
23 );
24
25 is( $mime->for_file('foobar'),
26 $mime->default, 'mime type for no extension is the default'
27 );
28
29 is( $mime->add_alias( xpto => 'BAR' ),
30 'text/foo', 'mime gets correctly lowercased for user types'
31 );
32
33 is $mime->add_alias( xpto => 'SVG' ) => 'image/svg+xml',
34 'mime gets correctly lowercased for system types';
35
36 is $mime->add_alias( zbr => 'baz' ) => $mime->default,
37 'alias of unknown mime type gets default mime type';
38
39 is $mime->name_or_type("text/zbr") => "text/zbr",
40 'name_or_type does not change if it seems a mime type string';
41
42 is $mime->name_or_type("svg") => "image/svg+xml", 'name_or_type knows svg';