File: useless_set_headers.t

package info (click to toggle)
libcatalyst-perl 5.90132-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,016 kB
  • sloc: perl: 11,061; makefile: 7
file content (67 lines) | stat: -rw-r--r-- 1,698 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
use warnings;
use strict;
use Test::More;
use HTTP::Request::Common;

{
  package TestAppStats::Log;
  $INC{'TestAppStats/Log.pm'} = __FILE__;

  use base qw/Catalyst::Log/;

  my @warn;

  sub my_warnings { $warn[0] };
  sub warn { shift; push(@warn, @_) }

  package MyApp::Controller::Root;
  $INC{'MyApp/Controller/Root.pm'} = __FILE__;

  use base 'Catalyst::Controller';

  sub get_header_ok :Local {
    my ($self, $c) = @_;
    $c->res->body('get_header_ok');
  }

  sub set_header_nok :Local {
    my ($self, $c) = @_;
    $c->res->body('set_header_nok');
  }

  package MyApp;
  $INC{'MyApp.pm'} = __FILE__;

  use Catalyst;
  use Moose;

  sub debug { 1 }

  __PACKAGE__->log(TestAppStats::Log->new('warn'));

  after 'finalize' => sub {
    my ($c) = @_;
    if($c->res->body eq 'set_header_nok') {
      Test::More::ok 1, 'got this far'; # got this far
      $c->res->header('REQUEST_METHOD', 'bad idea');
    } elsif($c->res->body eq 'get_header_ok') {
      Test::More::ok $c->res->header('x-catalyst'), 'Can query a header without causing trouble';
    }
  };

  MyApp->setup;
}

use Catalyst::Test 'MyApp';

ok request(GET '/root/get_header_ok'), 'got good request for get_header_ok';
ok !TestAppStats::Log::my_warnings, 'no warnings';
ok request(GET '/root/set_header_nok'), 'got good request for set_header_nok';
ok TestAppStats::Log::my_warnings, 'has a warning';
like TestAppStats::Log::my_warnings, qr'Useless setting a header value after finalize_headers', 'got expected warnings';

# We need to specify the number in order to be sure we are testing
# it all correctly.  If you change the number of tests please keep
# this up to date.  DO NOT REMOVE THIS!

done_testing(7);