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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
|
#!/usr/bin/perl
use strict;
use warnings;
use Test::More 1.001013;
use Test::Path::Router;
use Path::Router;
for my $inline (0, 1) {
my $INDEX = bless {} => 'Blog::Index';
my $SHOW_DATE = bless {} => 'Blog::ShowDate';
my $GENERAL = bless {} => 'Blog::Controller';
my $router = Path::Router->new(inline => $inline);
isa_ok($router, 'Path::Router');
# create some routes
$router->add_route('blog' => (
defaults => {
controller => 'blog',
action => 'index',
},
target => $INDEX,
));
$router->add_route('blog/:year/:month/:day' => (
defaults => {
controller => 'blog',
action => 'show_date',
},
validations => {
year => qr/\d{4}/,
month => qr/\d{1,2}/,
day => qr/\d{1,2}/,
},
target => $SHOW_DATE,
));
$router->add_route('blog/:action/:id' => (
defaults => {
controller => 'blog',
},
validations => {
action => qr/\D+/,
id => qr/\d+/
},
target => $GENERAL
));
my $suffix = '';
$suffix = ' (inline)' if $inline;
{
my $match = $router->match('/blog/');
isa_ok($match, 'Path::Router::Route::Match');
is($match->route->target, $INDEX, '... got the right target' . $suffix);
is_deeply(
$match->mapping,
{
controller => 'blog',
action => 'index',
},
'... got the right mapping' . $suffix
);
}
{
my $match = $router->match('/blog/2006/12/1');
isa_ok($match, 'Path::Router::Route::Match');
is($match->route->target, $SHOW_DATE, '... got the right target' . $suffix);
is_deeply(
$match->mapping,
{
controller => 'blog',
action => 'show_date',
year => 2006,
month => 12,
day => 1,
},
'... got the right mapping' . $suffix
);
}
{
my $match = $router->match('/blog/show/5');
isa_ok($match, 'Path::Router::Route::Match');
is($match->route->target, $GENERAL, '... got the right target' . $suffix);
is_deeply(
$match->mapping,
{
controller => 'blog',
action => 'show',
id => 5,
},
'... got the right mapping' . $suffix
);
}
{
my $match = $router->match('/blog/show/0');
isa_ok($match, 'Path::Router::Route::Match');
is($match->route->target, $GENERAL, '... got the right target' . $suffix);
is_deeply(
$match->mapping,
{
controller => 'blog',
action => 'show',
id => 0,
},
'... got the right mapping' . $suffix
);
}
}
done_testing;
|