Released Static::Simple 0.08 - Added tests for everything except Apache support
Andy Grundman [Wed, 7 Sep 2005 22:49:40 +0000 (22:49 +0000)]
18 files changed:
Changes
MANIFEST
MANIFEST.SKIP [new file with mode: 0644]
TODO [deleted file]
t/04static.t [new file with mode: 0644]
t/05dirs.t [new file with mode: 0644]
t/06include_path.t [new file with mode: 0644]
t/07mime_types.t [new file with mode: 0644]
t/lib/TestApp.pm [new file with mode: 0644]
t/lib/TestApp/root/always-static/test [new file with mode: 0644]
t/lib/TestApp/root/css/static.css [new file with mode: 0644]
t/lib/TestApp/root/files/bad.gif [new file with mode: 0644]
t/lib/TestApp/root/files/err.omg [new file with mode: 0644]
t/lib/TestApp/root/files/static.css [new file with mode: 0644]
t/lib/TestApp/root/images/bad.gif [new file with mode: 0644]
t/lib/TestApp/root/images/catalyst.png [new file with mode: 0644]
t/lib/TestApp/root/incpath/incpath.css [new file with mode: 0644]
t/lib/TestApp/root/overlay/overlay.jpg [new file with mode: 0644]

diff --git a/Changes b/Changes
index d2e11a0..90d6e0b 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,6 +1,7 @@
 Revision history for Perl extension Catalyst::Plugin::Static::Simple
 
-0.08    
+0.08    2005-09-07 18:50:00
+        - Added tests for everything except Apache support.
 
 0.07    2005-09-05 21:05:00
         - POD fixes. (Thomas L. Shinnick)
index 3114263..9536001 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -4,8 +4,21 @@ lib/Catalyst/Plugin/Static/Simple.pm
 Makefile.PL
 MANIFEST                       This list of files
 META.yml
-TODO
 README
 t/01use.t
 t/02pod.t
 t/03podcoverage.t
+t/04static.t
+t/05dirs.t
+t/06include_path.t
+t/07mime_types.t
+t/lib/TestApp.pm
+t/lib/TestApp/root/always-static/test
+t/lib/TestApp/root/css/static.css
+t/lib/TestApp/root/files/bad.gif
+t/lib/TestApp/root/files/err.omg
+t/lib/TestApp/root/files/static.css
+t/lib/TestApp/root/images/bad.gif
+t/lib/TestApp/root/images/catalyst.png
+t/lib/TestApp/root/incpath/incpath.css
+t/lib/TestApp/root/overlay/overlay.jpg
diff --git a/MANIFEST.SKIP b/MANIFEST.SKIP
new file mode 100644 (file)
index 0000000..4d0c740
--- /dev/null
@@ -0,0 +1,29 @@
+# Avoid version control files.
+\bRCS\b
+\bCVS\b
+,v$
+\B\.svn\b
+
+# Avoid Makemaker generated and utility files.
+\bMakefile$
+\bblib
+\bMakeMaker-\d
+\bpm_to_blib$
+\bblibdirs$
+^MANIFEST\.SKIP$
+
+# Avoid Module::Build generated and utility files.
+\bBuild$
+\b_build
+
+# Avoid temp and backup files.
+~$
+\.tmp$
+\.old$
+\.bak$
+\#$
+\b\.#
+
+# Don't ship the test db
+^t/var
+
diff --git a/TODO b/TODO
deleted file mode 100644 (file)
index ea56858..0000000
--- a/TODO
+++ /dev/null
@@ -1 +0,0 @@
-[ ] See if it's possible to get RequireSSL to play nice with Static::Simple files
diff --git a/t/04static.t b/t/04static.t
new file mode 100644 (file)
index 0000000..edb8974
--- /dev/null
@@ -0,0 +1,23 @@
+#!perl\r
+\r
+use strict;\r
+use warnings;\r
+\r
+use FindBin;\r
+use lib "$FindBin::Bin/lib";\r
+\r
+use Test::More tests => 7;\r
+use Catalyst::Test 'TestApp';\r
+\r
+# test getting a css file\r
+ok( my $res = request('http://localhost/files/static.css'), 'request ok' );\r
+is( $res->content_type, 'text/css', 'content-type text/css ok' );\r
+like( $res->content, qr/background/, 'content of css ok' );\r
+\r
+# test a non-existent file\r
+ok( $res = request('http://localhost/files/404.txt'), 'request ok' );\r
+is( $res->content, 'default', 'default handler for non-existent content ok' );\r
+\r
+# test unknown extension\r
+ok( $res = request('http://localhost/files/err.omg'), 'request ok' );\r
+is( $res->content_type, 'text/plain', 'unknown extension as text/plain ok' );\r
diff --git a/t/05dirs.t b/t/05dirs.t
new file mode 100644 (file)
index 0000000..fa5db8a
--- /dev/null
@@ -0,0 +1,33 @@
+#!perl\r
+\r
+use strict;\r
+use warnings;\r
+\r
+use FindBin;\r
+use lib "$FindBin::Bin/lib";\r
+\r
+use Test::More tests => 8;\r
+use Catalyst::Test 'TestApp';\r
+\r
+# test defined static dirs\r
+TestApp->config->{static}->{dirs} = [\r
+    'always-static',\r
+    qr/^images/,\r
+    'qr/^css/',\r
+];\r
+\r
+# a file with no extension will return text/plain\r
+ok( my $res = request('http://localhost/always-static/test'), 'request ok' );\r
+is( $res->content_type, 'text/plain', 'text/plain ok' );\r
+\r
+# a missing file in a defined static dir will return 404\r
+ok( $res = request('http://localhost/always-static/404.txt'), 'request ok' );\r
+is( $res->code, 404, '404 ok' );\r
+\r
+# qr regex test\r
+ok( $res = request('http://localhost/images/catalyst.png'), 'request ok' );\r
+is( $res->content_type, 'image/png', 'qr regex path ok' );\r
+\r
+# eval regex test\r
+ok( $res = request('http://localhost/css/static.css'), 'request ok' );\r
+like( $res->content, qr/background/, 'eval regex path ok' );\r
diff --git a/t/06include_path.t b/t/06include_path.t
new file mode 100644 (file)
index 0000000..144f39a
--- /dev/null
@@ -0,0 +1,29 @@
+#!perl\r
+\r
+use strict;\r
+use warnings;\r
+\r
+use FindBin;\r
+use lib "$FindBin::Bin/lib";\r
+\r
+use Test::More tests => 6;\r
+use Catalyst::Test 'TestApp';\r
+\r
+# test altenate root dirs\r
+TestApp->config->{static}->{include_path} = [\r
+    TestApp->config->{root} . '/overlay',\r
+    \&TestApp::incpath_generator,\r
+    TestApp->config->{root},\r
+];\r
+\r
+# test overlay dir\r
+ok( my $res = request('http://localhost/overlay.jpg'), 'request ok' );\r
+is( $res->content_type, 'image/jpeg', 'overlay path ok' );\r
+\r
+# test incpath_generator\r
+ok( $res = request('http://localhost/incpath.css'), 'request ok' );\r
+is( $res->content_type, 'text/css', 'incpath coderef ok' );\r
+\r
+# test passthrough to root\r
+ok( $res = request('http://localhost/images/bad.gif'), 'request ok' );\r
+is( $res->content_type, 'image/gif', 'root path ok' );\r
diff --git a/t/07mime_types.t b/t/07mime_types.t
new file mode 100644 (file)
index 0000000..4652494
--- /dev/null
@@ -0,0 +1,22 @@
+#!perl\r
+\r
+use strict;\r
+use warnings;\r
+\r
+use FindBin;\r
+use lib "$FindBin::Bin/lib";\r
+\r
+use Test::More tests => 4;\r
+use Catalyst::Test 'TestApp';\r
+\r
+# test custom MIME types\r
+TestApp->config->{static}->{mime_types} = {\r
+    omg => 'holy/crap',\r
+    gif => 'patents/are-evil',\r
+};\r
+\r
+ok( my $res = request('http://localhost/files/err.omg'), 'request ok' );\r
+is( $res->content_type, 'holy/crap', 'custom MIME type ok' );\r
+\r
+ok( $res = request('http://localhost/files/bad.gif'), 'request ok' );\r
+is( $res->content_type, 'patents/are-evil', 'custom MIME type overlay ok' );\r
diff --git a/t/lib/TestApp.pm b/t/lib/TestApp.pm
new file mode 100644 (file)
index 0000000..ff23ab8
--- /dev/null
@@ -0,0 +1,26 @@
+package TestApp;\r
+\r
+use strict;\r
+use Catalyst;\r
+\r
+our $VERSION = '0.01';\r
+\r
+TestApp->config(\r
+    name => 'TestApp',\r
+);\r
+\r
+TestApp->setup( qw/Static::Simple/ );\r
+\r
+sub incpath_generator {\r
+    my $c = shift;\r
+    \r
+    return [ $c->config->{root} . '/incpath' ];\r
+}\r
+\r
+sub default : Private {\r
+    my ( $self, $c ) = @_;\r
+    \r
+    $c->res->output( 'default' );\r
+}\r
+\r
+1;\r
diff --git a/t/lib/TestApp/root/always-static/test b/t/lib/TestApp/root/always-static/test
new file mode 100644 (file)
index 0000000..9eb0ae4
--- /dev/null
@@ -0,0 +1 @@
+I am a text file!
diff --git a/t/lib/TestApp/root/css/static.css b/t/lib/TestApp/root/css/static.css
new file mode 100644 (file)
index 0000000..de57cdb
--- /dev/null
@@ -0,0 +1,3 @@
+body {
+    background: #fff;
+}
diff --git a/t/lib/TestApp/root/files/bad.gif b/t/lib/TestApp/root/files/bad.gif
new file mode 100644 (file)
index 0000000..de57cdb
--- /dev/null
@@ -0,0 +1,3 @@
+body {
+    background: #fff;
+}
diff --git a/t/lib/TestApp/root/files/err.omg b/t/lib/TestApp/root/files/err.omg
new file mode 100644 (file)
index 0000000..de57cdb
--- /dev/null
@@ -0,0 +1,3 @@
+body {
+    background: #fff;
+}
diff --git a/t/lib/TestApp/root/files/static.css b/t/lib/TestApp/root/files/static.css
new file mode 100644 (file)
index 0000000..de57cdb
--- /dev/null
@@ -0,0 +1,3 @@
+body {
+    background: #fff;
+}
diff --git a/t/lib/TestApp/root/images/bad.gif b/t/lib/TestApp/root/images/bad.gif
new file mode 100644 (file)
index 0000000..de57cdb
--- /dev/null
@@ -0,0 +1,3 @@
+body {
+    background: #fff;
+}
diff --git a/t/lib/TestApp/root/images/catalyst.png b/t/lib/TestApp/root/images/catalyst.png
new file mode 100644 (file)
index 0000000..464e512
Binary files /dev/null and b/t/lib/TestApp/root/images/catalyst.png differ
diff --git a/t/lib/TestApp/root/incpath/incpath.css b/t/lib/TestApp/root/incpath/incpath.css
new file mode 100644 (file)
index 0000000..de57cdb
--- /dev/null
@@ -0,0 +1,3 @@
+body {
+    background: #fff;
+}
diff --git a/t/lib/TestApp/root/overlay/overlay.jpg b/t/lib/TestApp/root/overlay/overlay.jpg
new file mode 100644 (file)
index 0000000..de57cdb
--- /dev/null
@@ -0,0 +1,3 @@
+body {
+    background: #fff;
+}