Change configuration key to 'Plugin::Static::Simple' by default.
[catagits/Catalyst-Plugin-Static-Simple.git] / t / 05dirs.t
1 #!perl
2
3 use strict;
4 use warnings;
5
6 use FindBin;
7 use lib "$FindBin::Bin/lib";
8
9 use Test::More tests => 13;
10 use Catalyst::Test 'TestApp';
11
12 # test defined static dirs
13 TestApp->config->{'Plugin::Static::Simple'}->{dirs} = [
14     'always-static',
15     qr/^images/,
16     'qr/^css/',
17 ];
18
19 # a file with no extension will return text/plain
20 ok( my $res = request('http://localhost/always-static/test'), 'request ok' );
21 is( $res->content_type, 'text/plain', 'text/plain ok' );
22
23 # a file with an extension in ignore_extensions still gets served
24 ok( $res = request('http://localhost/always-static/test.html'), 'request ok' );
25 is( $res->code, 200, 'html file in dirs get served' );
26
27 # a missing file in a defined static dir will return 404 and text/html
28 ok( $res = request('http://localhost/always-static/404.txt'), 'request ok' );
29 is( $res->code, 404, '404 ok' );
30 is( $res->content_type, 'text/html', '404 is text/html' );
31
32 # qr regex test
33 ok( $res = request('http://localhost/images/catalyst.png'), 'request ok' );
34 is( $res->content_type, 'image/png', 'qr regex path ok' );
35
36 # eval regex test
37 ok( $res = request('http://localhost/css/static.css'), 'request ok' );
38 like( $res->content, qr/background/, 'eval regex path ok' );
39
40 # A static dir with no trailing slash is handled by Cat
41 ok( $res = request('http://localhost/always-static'), 'request ok' );
42 is( $res->content, 'default', 'content ok' );