4 use HTTP::Request::Common;
7 package TestAppStats::Log;
8 $INC{'TestAppStats/Log.pm'} = __FILE__;
10 use base qw/Catalyst::Log/;
14 sub my_warnings { $warn[0] };
15 sub warn { shift; push(@warn, @_) }
17 package MyApp::Controller::Root;
18 $INC{'MyApp/Controller/Root.pm'} = __FILE__;
20 use base 'Catalyst::Controller';
22 sub get_header_ok :Local {
24 $c->res->body('get_header_ok');
27 sub set_header_nok :Local {
29 $c->res->body('set_header_nok');
33 $INC{'MyApp.pm'} = __FILE__;
40 __PACKAGE__->log(TestAppStats::Log->new('warn'));
42 after 'finalize' => sub {
44 if($c->res->body eq 'set_header_nok') {
45 Test::More::ok 1, 'got this far'; # got this far
46 $c->res->header('REQUEST_METHOD', 'bad idea');
47 } elsif($c->res->body eq 'get_header_ok') {
48 Test::More::ok $c->res->header('x-catalyst'), 'Can query a header without causing trouble';
55 use Catalyst::Test 'MyApp';
57 ok request(GET '/root/get_header_ok'), 'got good request for get_header_ok';
58 ok !TestAppStats::Log::my_warnings, 'no warnings';
59 ok request(GET '/root/set_header_nok'), 'got good request for set_header_nok';
60 ok TestAppStats::Log::my_warnings, 'has a warning';
61 like TestAppStats::Log::my_warnings, qr'Useless setting a header value after finalize_headers', 'got expected warnings';
63 # We need to specify the number in order to be sure we are testing
64 # it all correctly. If you change the number of tests please keep
65 # this up to date. DO NOT REMOVE THIS!