first cut at :ChildOf
[catagits/Catalyst-Runtime.git] / t / unit_core_uri_for_action.t
1 #!perl
2
3 use strict;
4 use warnings;
5
6 use FindBin;
7 use lib "$FindBin::Bin/lib";
8
9 use Test::More;
10
11 plan tests => 12;
12
13 use_ok('TestApp');
14
15 my $dispatcher = TestApp->dispatcher;
16
17 my $private_action = $dispatcher->get_action_by_path(
18                        '/class_forward_test_method'
19                      );
20
21 ok(!defined($dispatcher->uri_for_action($private_action)),
22    "Private action returns undef for URI");
23
24 my $path_action = $dispatcher->get_action_by_path(
25                     '/action/testrelative/relative'
26                   );
27
28 is($dispatcher->uri_for_action($path_action), "/action/relative/relative",
29    "Public path action returns correct URI");
30
31 ok(!defined($dispatcher->uri_for_action($path_action, [ 'foo' ])),
32    "no URI returned for Path action when snippets are given");
33
34 my $regex_action = $dispatcher->get_action_by_path(
35                      '/action/regexp/one'
36                    );
37
38 ok(!defined($dispatcher->uri_for_action($regex_action)),
39    "Regex action without captures returns undef");
40
41 is($dispatcher->uri_for_action($regex_action, [ 'foo', 123 ]),
42    "/action/regexp/foo/123",
43    "Regex action interpolates captures correctly");
44
45 my $index_action = $dispatcher->get_action_by_path(
46                      '/action/index/index'
47                    );
48
49 ok(!defined($dispatcher->uri_for_action($index_action, [ 'foo' ])),
50    "no URI returned for index action when snippets are given");
51
52 is($dispatcher->uri_for_action($index_action),
53    "/action/index",
54    "index action returns correct path");
55
56 my $request = Catalyst::Request->new( {
57                 base => URI->new('http://127.0.0.1/foo')
58               } );
59
60 my $context = TestApp->new( {
61                 request => $request,
62                 namespace => 'yada',
63               } );
64
65 is($context->uri_for($path_action),
66    "http://127.0.0.1/foo/action/relative/relative",
67    "uri_for correct for path action");
68
69 is($context->uri_for($path_action, qw/one two/, { q => 1 }),
70    "http://127.0.0.1/foo/action/relative/relative/one/two?q=1",
71    "uri_for correct for path action with args and query");
72
73 ok(!defined($context->uri_for($path_action, [ 'blah' ])),
74    "no URI returned by uri_for for Path action with snippets");
75
76 is($context->uri_for($regex_action, [ 'foo', 123 ], qw/bar baz/, { q => 1 }),
77    "http://127.0.0.1/foo/action/regexp/foo/123/bar/baz?q=1",
78    "uri_for correct for regex with captures, args and query");