test case boilerplate
John Napiorkowski [Wed, 23 Oct 2013 17:13:48 +0000 (12:13 -0500)]
t/content_negotiation.t [new file with mode: 0644]
t/lib/TestContentNegotiation.pm [new file with mode: 0644]
t/lib/TestContentNegotiation/Controller/Root.pm [new file with mode: 0644]

diff --git a/t/content_negotiation.t b/t/content_negotiation.t
new file mode 100644 (file)
index 0000000..38eb181
--- /dev/null
@@ -0,0 +1,14 @@
+#!/usr/bin/env perl
+
+use warnings;
+use strict;
+
+use FindBin;
+use Test::More;
+use HTTP::Request::Common;
+
+use lib "$FindBin::Bin/lib";
+use Catalyst::Test 'TestContentNegotiation';
+
+
+done_testing;
diff --git a/t/lib/TestContentNegotiation.pm b/t/lib/TestContentNegotiation.pm
new file mode 100644 (file)
index 0000000..e126dcd
--- /dev/null
@@ -0,0 +1,13 @@
+package TestContentNegotiation;
+
+use Moose;
+use Catalyst;
+
+extends 'Catalyst';
+
+__PACKAGE__->config(
+  'Controller::Root', { namespace => '' },
+);
+
+__PACKAGE__->setup;
+
diff --git a/t/lib/TestContentNegotiation/Controller/Root.pm b/t/lib/TestContentNegotiation/Controller/Root.pm
new file mode 100644 (file)
index 0000000..ab8e0eb
--- /dev/null
@@ -0,0 +1,50 @@
+package TestContentNegotiation::Controller::Root;
+
+use Moose;
+use MooseX::MethodAttributes;
+
+extends 'Catalyst::Controller';
+
+sub start :Chained(/) PathPrefix CaptureArgs(0) { }
+
+    sub is_json       : Chained('start') PathPart('') Consumes('application/json') Args(0) { pop->res->body('is_json') }
+    sub is_urlencoded : Chained('start') PathPart('') Consumes('application/x-www-form-urlencoded') Args(0) { pop->res->body('is_urlencoded') }
+    sub is_multipart  : Chained('start') PathPart('') Consumes('multipart/form-data') Args(0) { pop->res->body('is_multipart') }
+      
+    sub under :Chained('start') CaptureArgs(0) { }
+
+      sub is_json_under       : Chained('under') PathPart('') Consumes(JSON) Args(0) { pop->res->body('is_json') }
+      sub is_urlencoded_under : Chained('under') PathPart('') Consumes(UrlEncoded) Args(0) { pop->res->body('is_urlencoded') }
+      sub is_multipart_under  : Chained('under') PathPart('') Consumes(Multipart) Args(0) { pop->res->body('is_multipart') }
+
+      ## Or allow more than one type
+    
+    sub multi :Chained('start') CaptureArgs(0) { }
+      
+    sub is_more_than_one_1
+      : Chained('multi') PathPart('')
+      : Consumes('application/x-www-form-urlencoded')
+      : Consumes('multipart/form-data')
+      : Args(0)
+    {
+      pop->res->body('formdata1');
+    }
+
+    sub is_more_than_one_2
+      : Chained('multi') PathPart('')
+      : Consumes('HTMLForm')
+      : Args(0)
+    {
+      pop->res->body('formdata2');
+    }
+
+    sub is_more_than_one_3
+      : Chained('multi') PathPart('')
+      : Consumes('application/x-www-form-urlencoded,multipart/form-data')
+      : Args(0)
+    {
+      pop->res->body('formdata3');
+    }
+
+
+__PACKAGE__->meta->make_immutable;