line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mason::Plugin::RouterSimple::t::Basic; |
2
|
|
|
|
|
|
|
BEGIN { |
3
|
1
|
|
|
1
|
|
665
|
$Mason::Plugin::RouterSimple::t::Basic::VERSION = '0.07'; |
4
|
|
|
|
|
|
|
} |
5
|
1
|
|
|
1
|
|
654
|
use Test::Class::Most parent => 'Mason::Test::Class'; |
|
1
|
|
|
|
|
28038
|
|
|
1
|
|
|
|
|
7
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
__PACKAGE__->default_plugins( [ '@Default', 'RouterSimple' ] ); |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub test_routes : Tests { |
10
|
|
|
|
|
|
|
my $self = shift; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
$self->add_comp( |
13
|
|
|
|
|
|
|
path => '/foo.mc', |
14
|
|
|
|
|
|
|
src => ' |
15
|
|
|
|
|
|
|
%% route "bar"; |
16
|
|
|
|
|
|
|
%% route "wiki/:page", { action => "wiki" }; |
17
|
|
|
|
|
|
|
%% route "download/*.*", { action => "download" }; |
18
|
|
|
|
|
|
|
%% route "blog/{year:[0-9]+}/{month:[0-9]{2}}"; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
<%args> |
21
|
|
|
|
|
|
|
$.page => (default => "standard") |
22
|
|
|
|
|
|
|
</%args> |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
month = <% $.month || "undef" %> |
25
|
|
|
|
|
|
|
page = <% $.page || "standard" %> |
26
|
|
|
|
|
|
|
splat = <% $.splat ? split(",", $.splat) : "undef" %> |
27
|
|
|
|
|
|
|
action = <% $.action || "undef" %> |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
% $m->result->data->{args} = $.args; |
30
|
|
|
|
|
|
|
', |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
my $try = sub { |
34
|
|
|
|
|
|
|
my ( $path, $expect ) = @_; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
my $result; |
37
|
|
|
|
|
|
|
if ($expect) { |
38
|
|
|
|
|
|
|
my $month = $expect->{month} || "undef"; |
39
|
|
|
|
|
|
|
my $page = $expect->{page} || "standard"; |
40
|
|
|
|
|
|
|
my $splat = $expect->{splat} ? split( ',', $expect->{splat} ) : "undef"; |
41
|
|
|
|
|
|
|
my $action = $expect->{action} || "undef"; |
42
|
|
|
|
|
|
|
$self->test_comp( |
43
|
|
|
|
|
|
|
path => $path, |
44
|
|
|
|
|
|
|
expect => "month = $month\npage = $page\nsplat = $splat\naction = $action", |
45
|
|
|
|
|
|
|
expect_data => { args => { %$expect, router_result => $expect } }, |
46
|
|
|
|
|
|
|
); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
else { |
49
|
|
|
|
|
|
|
$self->test_comp( path => $path, expect_error => qr/could not resolve request path/ ); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
}; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
$try->( '/foo/bar', {} ); |
54
|
|
|
|
|
|
|
$try->( '/foo/wiki/abc', { action => 'wiki', page => 'abc' } ); |
55
|
|
|
|
|
|
|
$try->( '/foo/download/tune.mp3', { action => 'download', splat => [ 'tune', 'mp3' ] } ); |
56
|
|
|
|
|
|
|
$try->( '/foo/blog/2010/02', { year => '2010', month => '02' } ); |
57
|
|
|
|
|
|
|
$try->( '/foo/baz', undef ); |
58
|
|
|
|
|
|
|
$try->( '/foo/blog/201O/02', undef ); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub test_no_routes : Tests { |
62
|
|
|
|
|
|
|
my $self = shift; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
$self->add_comp( |
65
|
|
|
|
|
|
|
path => '/no_route.mc', |
66
|
|
|
|
|
|
|
src => '<%class>method allow_path_info { 1 }</%class> |
67
|
|
|
|
|
|
|
path_info = <% $m->path_info || "" %>', |
68
|
|
|
|
|
|
|
); |
69
|
|
|
|
|
|
|
$self->test_existing_comp( path => '/no_route', expect => 'path_info =' ); |
70
|
|
|
|
|
|
|
$self->test_existing_comp( path => '/no_route/abc', expect => 'path_info = abc' ); |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
$self->add_comp( |
73
|
|
|
|
|
|
|
path => '/no_route_or_allow.mc', |
74
|
|
|
|
|
|
|
src => 'path_info = <% $m->path_info || "" %>', |
75
|
|
|
|
|
|
|
); |
76
|
|
|
|
|
|
|
$self->test_existing_comp( path => '/no_route_or_allow', expect => 'path_info =' ); |
77
|
|
|
|
|
|
|
$self->test_existing_comp( |
78
|
|
|
|
|
|
|
path => '/no_route_or_allow/abc', |
79
|
|
|
|
|
|
|
expect_error => qr/could not resolve request path/ |
80
|
|
|
|
|
|
|
); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
1; |