Commit | Line | Data |
18adb1ed |
1 | use warnings; |
2 | use strict; |
3 | use Test::More; |
4 | use HTTP::Request::Common; |
5 | |
6 | { |
7 | package TestAppStats::Log; |
8 | $INC{'TestAppStats/Log.pm'} = __FILE__; |
9 | |
10 | use base qw/Catalyst::Log/; |
11 | |
12 | my @warn; |
13 | |
14 | sub my_warnings { $warn[0] }; |
15 | sub warn { shift; push(@warn, @_) } |
16 | |
17 | package MyApp::Controller::Root; |
18 | $INC{'MyApp/Controller/Root.pm'} = __FILE__; |
19 | |
20 | use base 'Catalyst::Controller'; |
21 | |
22 | sub get_header_ok :Local { |
23 | my ($self, $c) = @_; |
24 | $c->res->body('get_header_ok'); |
25 | } |
26 | |
27 | sub set_header_nok :Local { |
28 | my ($self, $c) = @_; |
29 | $c->res->body('set_header_nok'); |
30 | } |
31 | |
32 | package MyApp; |
33 | $INC{'MyApp.pm'} = __FILE__; |
34 | |
35 | use Catalyst; |
36 | use Moose; |
37 | |
38 | sub debug { 1 } |
39 | |
40 | __PACKAGE__->log(TestAppStats::Log->new); |
41 | |
42 | after 'finalize' => sub { |
43 | my ($c) = @_; |
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'; |
49 | } |
50 | }; |
51 | |
52 | MyApp->setup; |
53 | } |
54 | |
55 | use Catalyst::Test 'MyApp'; |
56 | |
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'; |
62 | |
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! |
66 | |
67 | done_testing(7); |