| 1 | package Mason::t::ResolveURI; | ||||||||||||
| 2 | 1 | $Mason::t::ResolveURI::VERSION = '2.24'; | |||||||||||
| 3 | 1 | ▶ | use Test::Class::Most parent => 'Mason::Test::Class'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | |||||||||||||
| 5 | 1 | ▶ | sub test_resolve : Tests { | ||||||||||
|
Subroutine
test_resolve: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 6 | 1 | my $self = shift; | |||||||||||
| 7 | |||||||||||||
| 8 | 1 | my @interp_params = (); | |||||||||||
| 9 | 47 | ▶ | my $try = sub { | ||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=17.9
| |||||||||||||
| 10 | 47 | my ( $run_path, $existing_paths, $resolve_path, $path_info ) = @_; | |||||||||||
| 11 | 47 | ▶ | $path_info ||= ''; | ||||||||||
|
Condition100%2/2
$path_info ||= ""
MC/DC100%1/1
$path_info ||= ""
$path_info
Truth table100%2/2
A
A= $path_info
| |||||||||||||
| 12 | |||||||||||||
| 13 | 47 | $self->setup_dirs(@interp_params); | |||||||||||
| 14 | 47 | foreach my $existing_path (@$existing_paths) { | |||||||||||
| 15 | 53 | my $allow_path_info = 0; | |||||||||||
| 16 | 53 | ▶ | if ( $existing_path =~ /=1$/ ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 17 | 9 | substr( $existing_path, -2, 2 ) = ''; | |||||||||||
| 18 | 9 | $allow_path_info = 1; | |||||||||||
| 19 | } | ||||||||||||
| 20 | $self->add_comp( | ||||||||||||
| 21 | 53 | ▶ | path => $existing_path, | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 22 | src => join( "", | ||||||||||||
| 23 | ( $allow_path_info ? "<%class>method allow_path_info { 1 }</%class>\n" : "" ), | ||||||||||||
| 24 | "path: <% \$self->cmeta->path %>; path_info: <% \$m->path_info %>" ) | ||||||||||||
| 25 | ); | ||||||||||||
| 26 | } | ||||||||||||
| 27 | 47 | my $desc = sprintf( "run %s against %s", $run_path, join( ",", @$existing_paths ) ); | |||||||||||
| 28 | 47 | ▶ | if ( defined($resolve_path) ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 29 | 31 | my $good = "path: $resolve_path; path_info: $path_info"; | |||||||||||
| 30 | 31 | is( $self->interp->run($run_path)->output, $good, "$desc = matched $good" ); | |||||||||||
| 31 | } | ||||||||||||
| 32 | else { | ||||||||||||
| 33 | 16 | ▶ | throws_ok { $self->interp->run($run_path)->output } | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 34 | 16 | qr/could not resolve request path/, | |||||||||||
| 35 | "$desc = failed to match"; | ||||||||||||
| 36 | } | ||||||||||||
| 37 | 1 | }; | |||||||||||
| 38 | |||||||||||||
| 39 | 1 | my $run_path = '/foo/bar/baz'; | |||||||||||
| 40 | |||||||||||||
| 41 | 1 | $try->( $run_path, ['/foo/bar/baz.mc'], '/foo/bar/baz.mc', '' ); | |||||||||||
| 42 | 1 | $try->( $run_path, ['/foo/bar/baz/dhandler.mc'], '/foo/bar/baz/dhandler.mc', '' ); | |||||||||||
| 43 | 1 | $try->( $run_path, ['/foo/bar/baz/index.mc'], '/foo/bar/baz/index.mc', '' ); | |||||||||||
| 44 | 1 | $try->( $run_path, ['/foo/bar.mc=1'], '/foo/bar.mc', 'baz' ); | |||||||||||
| 45 | 1 | $try->( $run_path, ['/foo/bar/dhandler.mc'], '/foo/bar/dhandler.mc', 'baz' ); | |||||||||||
| 46 | 1 | $try->( $run_path, ['/foo.mc=1'], '/foo.mc', 'bar/baz' ); | |||||||||||
| 47 | 1 | $try->( $run_path, ['/foo/dhandler.mc'], '/foo/dhandler.mc', 'bar/baz' ); | |||||||||||
| 48 | 1 | $try->( $run_path, ['/dhandler.mc'], '/dhandler.mc', 'foo/bar/baz' ); | |||||||||||
| 49 | 1 | $try->( $run_path, [ '/dhandler.mc', '/foo/dhandler.mc' ], '/foo/dhandler.mc', 'bar/baz' ); | |||||||||||
| 50 | 1 | $try->( $run_path, [ '/foo/dhandler.mc', '/foo/bar.mc=1' ], '/foo/bar.mc', 'baz' ); | |||||||||||
| 51 | 1 | $try->( $run_path, [ '/foo/dhandler.mc', '/foo/bar.mc' ], '/foo/dhandler.mc', 'bar/baz' ); | |||||||||||
| 52 | |||||||||||||
| 53 | # Not found | ||||||||||||
| 54 | 1 | $try->( $run_path, ['/foo/bar.mc'], undef ); | |||||||||||
| 55 | 1 | $try->( $run_path, ['/foo.mc'], undef ); | |||||||||||
| 56 | 1 | $try->( $run_path, ['/foo/bar/baz/blarg.mc'], undef ); | |||||||||||
| 57 | 1 | $try->( $run_path, ['/foo/bar/baz/blarg/dhandler.mc'], undef ); | |||||||||||
| 58 | 1 | $try->( $run_path, ['/foo/bar/baz'], undef ); | |||||||||||
| 59 | 1 | $try->( $run_path, ['/foo/dhandler'], undef ); | |||||||||||
| 60 | 1 | $try->( $run_path, ['/foo/bar/index.mc'], undef ); | |||||||||||
| 61 | 1 | $try->( $run_path, ['/foo/blarg.mc'], undef ); | |||||||||||
| 62 | 1 | $try->( $run_path, ['/foo/blarg/dhandler.mc'], undef ); | |||||||||||
| 63 | |||||||||||||
| 64 | # Can't access autobase or dhandler directly, but can access index | ||||||||||||
| 65 | 1 | $try->( '/foo/Base', ['/foo/Base.mc'], undef ); | |||||||||||
| 66 | 1 | $try->( '/foo/dhandler', ['/foo/dhandler.mc'], '/foo/dhandler.mc', 'dhandler' ); | |||||||||||
| 67 | 1 | $try->( '/foo/index', ['/foo/index.mc'], '/foo/index.mc' ); | |||||||||||
| 68 | |||||||||||||
| 69 | # no autoextend_run_path | ||||||||||||
| 70 | 1 | @interp_params = ( autoextend_request_path => 0, top_level_extensions => ['.html'] ); | |||||||||||
| 71 | 1 | $try->( '/foo/bar/baz.html', ['/foo/bar/baz.html'], '/foo/bar/baz.html', '' ); | |||||||||||
| 72 | 1 | $try->( '/foo/bar/baz.html', ['/foo/bar/baz.html.mc'], undef ); | |||||||||||
| 73 | 1 | $try->( "/foo.mc/bar.mi", ['/foo.mc/bar.mi'], undef ); | |||||||||||
| 74 | 1 | @interp_params = ( autoextend_request_path => 0, top_level_extensions => [] ); | |||||||||||
| 75 | 1 | $try->( '/foo/bar/baz.html', ['/foo/bar/baz.html'], '/foo/bar/baz.html', '' ); | |||||||||||
| 76 | 1 | $try->( "/foo.mc/bar.mi", ['/foo.mc/bar.mi'], '/foo.mc/bar.mi', '' ); | |||||||||||
| 77 | |||||||||||||
| 78 | # dhandler_names | ||||||||||||
| 79 | 1 | @interp_params = ( dhandler_names => ['dhandler'] ); | |||||||||||
| 80 | 1 | $try->( $run_path, ['/foo/bar/baz/dhandler.mc'], undef ); | |||||||||||
| 81 | 1 | $try->( $run_path, ['/foo/bar/baz/dhandler'], '/foo/bar/baz/dhandler', '' ); | |||||||||||
| 82 | 1 | $try->( $run_path, ['/foo/bar/dhandler'], '/foo/bar/dhandler', 'baz' ); | |||||||||||
| 83 | |||||||||||||
| 84 | # index_names | ||||||||||||
| 85 | 1 | @interp_params = ( index_names => [ 'index', 'index2' ] ); | |||||||||||
| 86 | 1 | $try->( $run_path, ['/foo/bar/baz/index.mc'], undef ); | |||||||||||
| 87 | 1 | $try->( $run_path, ['/foo/bar/baz/index'], '/foo/bar/baz/index', '' ); | |||||||||||
| 88 | 1 | $try->( $run_path, ['/foo/bar/baz/index2'], '/foo/bar/baz/index2', '' ); | |||||||||||
| 89 | 1 | $try->( $run_path, [ '/foo/bar/baz/index2', '/foo/bar/baz/index' ], '/foo/bar/baz/index', '' ); | |||||||||||
| 90 | |||||||||||||
| 91 | # trailing slashes | ||||||||||||
| 92 | 1 | $try->( '/foo', ['/foo.mc=1'], '/foo.mc', '' ); | |||||||||||
| 93 | 1 | $try->( '/foo/', ['/foo.mc=1'], '/foo.mc', '/' ); | |||||||||||
| 94 | 1 | $try->( '/foo/bar', ['/foo.mc=1'], '/foo.mc', 'bar' ); | |||||||||||
| 95 | 1 | $try->( '/foo/bar/', ['/foo.mc=1'], '/foo.mc', 'bar/' ); | |||||||||||
| 96 | 1 | $try->( '/foo/', ['/foo.mc'], undef ); | |||||||||||
| 97 | 1 | @interp_params = ( dhandler_names => ['dhandler'] ); | |||||||||||
| 98 | 1 | $try->( '/foo/', ['/foo/dhandler'], '/foo/dhandler', '/' ); | |||||||||||
| 99 | 1 | $try->( '/foo/bar', ['/foo/dhandler'], '/foo/dhandler', 'bar' ); | |||||||||||
| 100 | 1 | $try->( '/foo/bar/', ['/foo/dhandler'], '/foo/dhandler', 'bar/' ); | |||||||||||
| 101 | 1 | @interp_params = ( index_names => ['index'] ); | |||||||||||
| 102 | 1 | $try->( '/foo/', ['/foo/index'], undef ); | |||||||||||
| 103 | 1 | $try->( '/foo/', ['/foo/index=1'], '/foo/index', '/' ); | |||||||||||
| 104 | 1 | @interp_params = ( dhandler_names => ['dhandler'], index_names => ['index'] ); | |||||||||||
| 105 | 1 | $try->( '/foo/', [ '/foo/dhandler', '/foo/index' ], '/foo/dhandler', '/' ); | |||||||||||
| 106 | 1 | $try->( '/foo/', [ '/foo/dhandler', '/foo/index=1' ], '/foo/index', '/' ); | |||||||||||
| 107 | 1 | ▶ | } | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 108 | |||||||||||||
| 109 | 1 | ▶ | sub test_decline : Tests { | ||||||||||
|
Subroutine
test_decline: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 110 | 1 | my $self = shift; | |||||||||||
| 111 | |||||||||||||
| 112 | 1 | my @existing_paths = | |||||||||||
| 113 | qw(/foo/bar.mc /foo/bar/dhandler.mc /foo/bar/index.mc /foo.mc /foo/dhandler.mc /dhandler.mc); | ||||||||||||
| 114 | 1 | my @paths_to_decline = (); | |||||||||||
| 115 | 1 | my $run_path = '/foo/bar'; | |||||||||||
| 116 | |||||||||||||
| 117 | 7 | ▶ | my $try = sub { | ||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.1
| |||||||||||||
| 118 | 7 | my ( $resolve_path, $path_info ) = @_; | |||||||||||
| 119 | 7 | my %paths_to_decline_hash = map { ( $_, 1 ) } @paths_to_decline; | |||||||||||
| 120 | |||||||||||||
| 121 | 7 | $self->setup_dirs(); | |||||||||||
| 122 | 7 | foreach my $existing_path (@existing_paths) { | |||||||||||
| 123 | my $component = | ||||||||||||
| 124 | 42 | ▶ | $paths_to_decline_hash{$existing_path} | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 125 | ? '<%perl>$m->decline();</%perl>' | ||||||||||||
| 126 | : 'path: <% $self->cmeta->path %>; path_info: <% $m->path_info %>'; | ||||||||||||
| 127 | 42 | $self->add_comp( | |||||||||||
| 128 | path => $existing_path, | ||||||||||||
| 129 | src => $component, | ||||||||||||
| 130 | ); | ||||||||||||
| 131 | 42 | $self->add_comp( path => '/Base.mp', src => 'method allow_path_info { 1 }' ); | |||||||||||
| 132 | } | ||||||||||||
| 133 | 7 | ▶ | my $desc = sprintf( "declining: %s", join( ",", @paths_to_decline ) || '<nothing>' ); | ||||||||||
|
Condition100%2/2
join(',', @paths_to_decline) || '<nothing>'
MC/DC100%1/1
join(',', @paths_to_decline) || '<nothing>'
join(',', @paths_to_decline)
Truth table100%2/2
A
A= join(',', @paths_to_decline)
| |||||||||||||
| 134 | 7 | ▶ | if ( defined($resolve_path) ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 135 | 6 | is( $self->interp->run($run_path)->output, | |||||||||||
| 136 | "path: $resolve_path; path_info: $path_info", $desc ); | ||||||||||||
| 137 | } | ||||||||||||
| 138 | else { | ||||||||||||
| 139 | 1 | ▶ | throws_ok { $self->interp->run($run_path)->output } | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 140 | 1 | qr/could not resolve request path/, | |||||||||||
| 141 | $desc; | ||||||||||||
| 142 | } | ||||||||||||
| 143 | 7 | push( @paths_to_decline, $resolve_path ); | |||||||||||
| 144 | 1 | }; | |||||||||||
| 145 | |||||||||||||
| 146 | # Repeatedly try /foo/bar, test the expected page component, then add | ||||||||||||
| 147 | # that component to the decline list and try again. | ||||||||||||
| 148 | # | ||||||||||||
| 149 | 1 | $try->( '/foo/bar.mc', '' ); | |||||||||||
| 150 | 1 | $try->( '/foo/bar/index.mc', '' ); | |||||||||||
| 151 | 1 | $try->( '/foo/bar/dhandler.mc', '' ); | |||||||||||
| 152 | 1 | $try->( '/foo.mc', 'bar' ); | |||||||||||
| 153 | 1 | $try->( '/foo/dhandler.mc', 'bar' ); | |||||||||||
| 154 | 1 | $try->( '/dhandler.mc', 'foo/bar' ); | |||||||||||
| 155 | 1 | $try->(undef); | |||||||||||
| 156 | 1 | ▶ | } | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 157 | |||||||||||||
| 158 | 1 | 1; | |||||||||||