File: 003_messy_paths.t

package info (click to toggle)
libpath-router-perl 0.15-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 276 kB
  • sloc: perl: 1,863; makefile: 2
file content (96 lines) | stat: -rw-r--r-- 1,973 bytes parent folder | download | duplicates (5)
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
#!/usr/bin/perl

use strict;
use warnings;

use Test::More 1.001013;
use Test::Path::Router;
#use Data::Dumper;

use Path::Router;

=pod

This test how the router fairs with messy URIs

=cut

my $router = Path::Router->new;
isa_ok($router, 'Path::Router');

# create some routes

$router->add_route('blog' => (
    defaults       => {
        controller => 'blog',
        action     => '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}/,
    }
));

$router->add_route('blog/:action/:id' => (
    defaults       => {
        controller => 'blog',
    },
    validations => {
        action  => qr/\D+/,
        id      => qr/\d+/
    }
));

# run it through some tests

path_ok($router, '/blog/', '... this path is valid');
path_ok($router, './blog/', '... this path is valid');
path_ok($router, '///.///.///blog//.//', '... this path is valid');
path_ok($router, '/blog/./show/.//./20', '... this path is valid');
path_ok($router, '/blog/./2006/.//./20////////10', '... this path is valid');

path_is($router,
    '/blog/',
    {
        controller => 'blog',
        action     => 'index',
    },
'... this path matches the mapping');

path_is($router,
    '///.///.///blog//.//',
    {
        controller => 'blog',
        action     => 'index',
    },
'... this path matches the mapping');

path_is($router,
    '/blog/./show/.//./20',
    {
        controller => 'blog',
        action     => 'show',
        id         => 20,
    },
'... this path matches the mapping');

path_is($router,
    '/blog/./2006/.//./20////////10',
    {
        controller => 'blog',
        action     => 'show_date',
        year       => 2006,
        month      => 20,
        day        => 10,
    },
'... this path matches the mapping');

done_testing;