| 1 | package Mason::Plugin::PSGIHandler::t::Basic; | ||||||||||||
| 2 | 1 | ▶ | BEGIN { | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 3 | 1 | $Mason::Plugin::PSGIHandler::t::Basic::VERSION = '0.06'; | |||||||||||
| 4 | } | ||||||||||||
| 5 | 1 | ▶ | use Test::Class::Most parent => 'Mason::Test::Class'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 1 | ▶ | use Mason::Util qw(trim); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 1 | ▶ | use HTTP::Request::Common; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | 1 | ▶ | use Plack::Test; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | |||||||||||||
| 10 | 1 | __PACKAGE__->default_plugins( [ '@Default', 'PSGIHandler' ] ); | |||||||||||
| 11 | |||||||||||||
| 12 | 6 | ▶ | sub test_psgi_comp { | ||||||||||
|
Subroutine
test_psgi_comp: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||
| 13 | 6 | my ( $self, %params ) = @_; | |||||||||||
| 14 | 6 | my $interp = $self->interp; | |||||||||||
| 15 | 6 | ▶ | my $app = sub { my $env = shift; $interp->handle_psgi($env) }; | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 16 | 6 | ▶ | my $path = $params{path} or die "must pass path"; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 17 | 6 | ( my $uri = $path ) =~ s/\.mc$//; | |||||||||||
| 18 | 6 | ▶ | my $qs = $params{qs} || ''; | ||||||||||
|
Condition100%2/2
$params{'qs'} || ''
MC/DC100%1/1
$params{'qs'} || ''
$params{'qs'}
Truth table100%2/2
A
A= $params{'qs'}
| |||||||||||||
| 19 | 6 | $self->add_comp( path => $path, src => $params{src} ); | |||||||||||
| 20 | test_psgi( | ||||||||||||
| 21 | $app, | ||||||||||||
| 22 | 6 | ▶ | sub { | ||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=18.0
| |||||||||||||
| 23 | 6 | my $cb = shift; | |||||||||||
| 24 | 6 | my $res = $cb->( GET( $uri . $qs ) ); | |||||||||||
| 25 | 6 | ▶ | if ( my $expect_content = $params{expect_content} ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 26 | 6 | ▶ | if ( ref($expect_content) eq 'Regexp' ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 27 | 1 | like( trim( $res->content ), $expect_content, "$path - content" ); | |||||||||||
| 28 | } | ||||||||||||
| 29 | else { | ||||||||||||
| 30 | 5 | is( trim( $res->content ), trim($expect_content), "$path - content" ); | |||||||||||
| 31 | } | ||||||||||||
| 32 | } | ||||||||||||
| 33 | 6 | ▶ | if ( my $expect_code = $params{expect_code} ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 34 | 6 | is( $res->code, $expect_code, "$path - code" ); | |||||||||||
| 35 | } | ||||||||||||
| 36 | 6 | ▶ | if ( my $expect_headers = $params{expect_headers} ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 37 | 2 | ▶ | while ( my ( $hdr, $value ) = each(%$expect_headers) ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 38 | 2 | cmp_deeply( $res->header($hdr), $value, "$path - header $hdr" ); | |||||||||||
| 39 | } | ||||||||||||
| 40 | } | ||||||||||||
| 41 | } | ||||||||||||
| 42 | 6 | ); | |||||||||||
| 43 | } | ||||||||||||
| 44 | |||||||||||||
| 45 | 1 | ▶ | sub test_basic : Tests(2) { | ||||||||||
|
Subroutine
test_basic: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 46 | 1 | my $self = shift; | |||||||||||
| 47 | 1 | $self->test_psgi_comp( | |||||||||||
| 48 | path => '/hi.mc', | ||||||||||||
| 49 | src => 'path = <% $m->req->path %>', | ||||||||||||
| 50 | expect_content => 'path = /hi', | ||||||||||||
| 51 | expect_code => 200 | ||||||||||||
| 52 | ); | ||||||||||||
| 53 | 1 | ▶ | } | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 54 | |||||||||||||
| 55 | 1 | ▶ | sub test_error : Tests(2) { | ||||||||||
|
Subroutine
test_error: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 56 | 1 | my $self = shift; | |||||||||||
| 57 | 1 | $self->test_psgi_comp( | |||||||||||
| 58 | path => '/die.mc', | ||||||||||||
| 59 | src => '% die "bleah";', | ||||||||||||
| 60 | expect_code => 500, | ||||||||||||
| 61 | expect_content => qr/bleah at/, | ||||||||||||
| 62 | ); | ||||||||||||
| 63 | 1 | ▶ | } | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 64 | |||||||||||||
| 65 | 1 | ▶ | sub test_not_found : Tests(2) { | ||||||||||
|
Subroutine
test_not_found: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 66 | 1 | my $self = shift; | |||||||||||
| 67 | 1 | ▶ | my $app = sub { my $env = shift; $self->interp->handle_psgi($env) }; | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 68 | test_psgi( | ||||||||||||
| 69 | $app, | ||||||||||||
| 70 | 1 | ▶ | sub { | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 71 | 1 | my $cb = shift; | |||||||||||
| 72 | 1 | my $res = $cb->( GET("/does/not/exist") ); | |||||||||||
| 73 | 1 | is( $res->code, 404, "status 404" ); | |||||||||||
| 74 | 1 | is( $res->content, '', "blank content" ); | |||||||||||
| 75 | } | ||||||||||||
| 76 | 1 | ); | |||||||||||
| 77 | 1 | ▶ | } | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 78 | |||||||||||||
| 79 | 1 | ▶ | sub test_args : Tests(2) { | ||||||||||
|
Subroutine
test_args: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 80 | 1 | my $self = shift; | |||||||||||
| 81 | 1 | $self->test_psgi_comp( | |||||||||||
| 82 | path => '/args.mc', | ||||||||||||
| 83 | qs => '?a=1&a=2&b=3&b=4&c=5&c=6&d=7&d=8', | ||||||||||||
| 84 | src => ' | ||||||||||||
| 85 | <%args> | ||||||||||||
| 86 | $.a | ||||||||||||
| 87 | $.b => (isa => "Int") | ||||||||||||
| 88 | $.c => (isa => "ArrayRef"); | ||||||||||||
| 89 | $.d => (isa => "ArrayRef[Int]"); | ||||||||||||
| 90 | </%args> | ||||||||||||
| 91 | |||||||||||||
| 92 | a = <% $.a %> | ||||||||||||
| 93 | b = <% $.b %> | ||||||||||||
| 94 | c = <% join(",", @{$.c}) %> | ||||||||||||
| 95 | d = <% join(",", @{$.d}) %> | ||||||||||||
| 96 | |||||||||||||
| 97 | % my $args = $.args; | ||||||||||||
| 98 | <% Mason::Util::dump_one_line($args) %> | ||||||||||||
| 99 | ', | ||||||||||||
| 100 | expect_content => <<EOF, | ||||||||||||
| 101 | a = 2 | ||||||||||||
| 102 | b = 4 | ||||||||||||
| 103 | c = 5,6 | ||||||||||||
| 104 | d = 7,8 | ||||||||||||
| 105 | |||||||||||||
| 106 | {a => '2',b => '4',c => ['5','6'],d => ['7','8']} | ||||||||||||
| 107 | EOF | ||||||||||||
| 108 | expect_code => 200 | ||||||||||||
| 109 | ); | ||||||||||||
| 110 | 1 | ▶ | } | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 111 | |||||||||||||
| 112 | 1 | ▶ | sub test_abort : Tests(8) { | ||||||||||
|
Subroutine
test_abort: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 113 | 1 | my $self = shift; | |||||||||||
| 114 | 1 | $self->test_psgi_comp( | |||||||||||
| 115 | path => '/redirect.mc', | ||||||||||||
| 116 | src => ' | ||||||||||||
| 117 | will not be printed | ||||||||||||
| 118 | % $m->redirect("http://www.google.com/"); | ||||||||||||
| 119 | will also not be printed | ||||||||||||
| 120 | ', | ||||||||||||
| 121 | expect_content => ' ', | ||||||||||||
| 122 | expect_code => 302, | ||||||||||||
| 123 | expect_headers => { Location => 'http://www.google.com/' }, | ||||||||||||
| 124 | ); | ||||||||||||
| 125 | 1 | $self->test_psgi_comp( | |||||||||||
| 126 | path => '/redirect_301.mc', | ||||||||||||
| 127 | src => ' | ||||||||||||
| 128 | will not be printed | ||||||||||||
| 129 | % $m->redirect("http://www.yahoo.com/", 301); | ||||||||||||
| 130 | ', | ||||||||||||
| 131 | expect_content => ' ', | ||||||||||||
| 132 | expect_code => 301, | ||||||||||||
| 133 | expect_headers => { Location => 'http://www.yahoo.com/' }, | ||||||||||||
| 134 | ); | ||||||||||||
| 135 | 1 | $self->test_psgi_comp( | |||||||||||
| 136 | path => '/not_found.mc', | ||||||||||||
| 137 | src => ' | ||||||||||||
| 138 | will not be printed | ||||||||||||
| 139 | % $m->clear_and_abort(404); | ||||||||||||
| 140 | ', | ||||||||||||
| 141 | expect_content => ' ', | ||||||||||||
| 142 | expect_code => 404, | ||||||||||||
| 143 | ); | ||||||||||||
| 144 | 1 | ▶ | } | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 145 | |||||||||||||
| 146 | 1 | 1; | |||||||||||