~ubuntu-branches/ubuntu/wily/librouter-simple-perl/wily

« back to all changes in this revision

Viewing changes to t/01_simple.t

  • Committer: Package Import Robot
  • Author(s): Florian Schlichting
  • Date: 2012-06-04 21:31:28 UTC
  • Revision ID: package-import@ubuntu.com-20120604213128-tmi08jxwpq0mnuh5
Tags: upstream-0.09
ImportĀ upstreamĀ versionĀ 0.09

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
use strict;
 
2
use warnings;
 
3
use Router::Simple;
 
4
use Test::More;
 
5
 
 
6
my $r = Router::Simple->new();
 
7
$r->connect('home', '/' => {controller => 'Root', action => 'show'}, {method => 'GET', host => 'localhost'});
 
8
$r->connect('blog_monthly', '/blog/{year}/{month}', {controller => 'Blog', action => 'monthly'}, {method => 'GET'});
 
9
$r->connect('/blog/{year:\d{1,4}}/{month:\d{2}}/{day:\d\d}', {controller => 'Blog', action => 'daily'}, {method => 'GET'});
 
10
$r->connect('/comment', {controller => 'Comment', 'action' => 'create'}, {method => 'POST'});
 
11
$r->connect('/', {controller => 'Root', 'action' => 'show_sub'}, {method => 'GET', host => 'sub.localhost'});
 
12
$r->connect(qr{^/belongs/([a-z]+)/([a-z]+)$}, {controller => 'May', action => 'show'});
 
13
$r->connect('/:controller/:action');
 
14
 
 
15
is_deeply(
 
16
    $r->match( +{ REQUEST_METHOD => 'GET', PATH_INFO => '/', HTTP_HOST => 'localhost'} ),
 
17
    {
 
18
        controller => 'Root',
 
19
        action     => 'show',
 
20
    }
 
21
);
 
22
is_deeply(
 
23
    $r->match( +{ PATH_INFO => '/blog/2010/03', HTTP_HOST => 'localhost', REQUEST_METHOD => 'GET' } ) || undef,
 
24
    {
 
25
        controller => 'Blog',
 
26
        action     => 'monthly',
 
27
        year => 2010,
 
28
        month => '03'
 
29
    },
 
30
    'blog monthly'
 
31
);
 
32
is_deeply(
 
33
    $r->match( +{ PATH_INFO => '/blog/2010/03/04', HTTP_HOST => 'localhost', REQUEST_METHOD => 'GET' } ) || undef,
 
34
    {
 
35
        controller => 'Blog',
 
36
        action     => 'daily',
 
37
        year => 2010, month => '03', day => '04',
 
38
    },
 
39
    'daily'
 
40
);
 
41
is_deeply(
 
42
    $r->match( +{ PATH_INFO => '/blog/2010/03', HTTP_HOST => 'localhost', REQUEST_METHOD => 'POST' } ) || undef,
 
43
    undef
 
44
);
 
45
is_deeply(
 
46
    $r->match( +{ PATH_INFO => '/comment', HTTP_HOST => 'localhost', REQUEST_METHOD => 'POST' } ) || undef,
 
47
    {
 
48
        controller => 'Comment',
 
49
        action     => 'create',
 
50
    }
 
51
);
 
52
is_deeply(
 
53
    $r->match( +{ PATH_INFO => '/', HTTP_HOST => 'sub.localhost', REQUEST_METHOD => 'GET' } ) || undef,
 
54
    {
 
55
        controller => 'Root',
 
56
        action     => 'show_sub',
 
57
    }
 
58
);
 
59
is_deeply(
 
60
    $r->match( +{ PATH_INFO => '/belongs/to/us', HTTP_HOST => 'localhost', REQUEST_METHOD => 'GET' } ) || undef,
 
61
    {
 
62
        controller => 'May',
 
63
        action     => 'show',
 
64
        splat      => ['to', 'us'],
 
65
    }
 
66
);
 
67
is_deeply(
 
68
    $r->match( +{ PATH_INFO => '/foo/bar', HTTP_HOST => 'localhost', REQUEST_METHOD => 'GET' } ) || undef,
 
69
    {
 
70
        controller => 'foo',
 
71
        action     => 'bar',
 
72
    }
 
73
);
 
74
 
 
75
done_testing;