actually use the new keywords
[catagits/Catalyst-Runtime.git] / t / undef-params.t
1 use warnings;
2 use strict ;
3 use Test::More;
4 use HTTP::Request::Common;
5 use Plack::Test;
6
7 # If someone does $c->req->params(undef) you don't get a very good
8 # error message.  This is a test to see if the proposed change improves
9 # that.
10
11
12 {
13   package MyApp::Controller::Root;
14   $INC{'MyApp/Controller/Root.pm'} = __FILE__;
15
16   use base 'Catalyst::Controller';
17
18   sub test :Local {
19     my ($self, $c) = @_;
20     my $value = $c->req->param(undef);
21
22     $c->response->body("This is the body");
23   }
24
25   sub set_params :Local {
26     my ($self, $c) = @_;
27     $c->req->param(foo => 'a', 'b', 'c');
28     $c->res->body(join ',', $c->req->param('foo'));
29   }
30
31   package MyApp;
32   use Catalyst;
33
34   $SIG{__WARN__} = sub {
35     my $error = shift;
36     Test::More::is($error, "You called ->params with an undefined value at t/undef-params.t line 20.\n");
37   };
38
39   MyApp->setup, 'setup app';
40 }
41
42 ok my $psgi = MyApp->psgi_app, 'build psgi app';
43
44 test_psgi $psgi, sub {
45     my $cb = shift;
46
47     {
48       my $res = $cb->(GET "/root/test");
49       is $res->code, 200, 'OK';
50     }
51
52     {
53       my $res = $cb->(GET "/root/set_params");
54       is $res->code, 200, 'OK';
55       is $res->content, 'a,b,c';
56     }
57 };
58
59 done_testing;