Commit | Line | Data |
ad1783ae |
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 | |
792b40ac |
11 | plan tests => 17; |
ad1783ae |
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 | |
792b40ac |
41 | ok(!defined($dispatcher->uri_for_action($regex_action, [ 1, 2, 3 ])), |
42 | "Regex action with too many captures returns undef"); |
43 | |
ad1783ae |
44 | is($dispatcher->uri_for_action($regex_action, [ 'foo', 123 ]), |
45 | "/action/regexp/foo/123", |
46 | "Regex action interpolates captures correctly"); |
47 | |
48 | my $index_action = $dispatcher->get_action_by_path( |
49 | '/action/index/index' |
50 | ); |
51 | |
52 | ok(!defined($dispatcher->uri_for_action($index_action, [ 'foo' ])), |
53 | "no URI returned for index action when snippets are given"); |
54 | |
55 | is($dispatcher->uri_for_action($index_action), |
56 | "/action/index", |
57 | "index action returns correct path"); |
58 | |
792b40ac |
59 | my $childof_action = $dispatcher->get_action_by_path( |
60 | '/action/childof/endpoint', |
61 | ); |
62 | |
63 | ok(!defined($dispatcher->uri_for_action($childof_action)), |
64 | "ChildOf action without captures returns undef"); |
65 | |
66 | ok(!defined($dispatcher->uri_for_action($childof_action, [ 1, 2 ])), |
67 | "ChildOf action with too many captures returns undef"); |
68 | |
69 | is($dispatcher->uri_for_action($childof_action, [ 1 ]), |
70 | "/childof/foo/1/end", |
71 | "ChildOf action with correct captures returns correct path"); |
72 | |
ad1783ae |
73 | my $request = Catalyst::Request->new( { |
74 | base => URI->new('http://127.0.0.1/foo') |
75 | } ); |
76 | |
77 | my $context = TestApp->new( { |
78 | request => $request, |
79 | namespace => 'yada', |
80 | } ); |
81 | |
82 | is($context->uri_for($path_action), |
83 | "http://127.0.0.1/foo/action/relative/relative", |
84 | "uri_for correct for path action"); |
85 | |
86 | is($context->uri_for($path_action, qw/one two/, { q => 1 }), |
87 | "http://127.0.0.1/foo/action/relative/relative/one/two?q=1", |
88 | "uri_for correct for path action with args and query"); |
89 | |
90 | ok(!defined($context->uri_for($path_action, [ 'blah' ])), |
91 | "no URI returned by uri_for for Path action with snippets"); |
92 | |
93 | is($context->uri_for($regex_action, [ 'foo', 123 ], qw/bar baz/, { q => 1 }), |
94 | "http://127.0.0.1/foo/action/regexp/foo/123/bar/baz?q=1", |
95 | "uri_for correct for regex with captures, args and query"); |
792b40ac |
96 | |
97 | is($context->uri_for($childof_action, [ 1 ], 2, { q => 1 }), |
98 | "http://127.0.0.1/foo/childof/foo/1/end/2?q=1", |
99 | "uri_for correct for childof with captures, args and query"); |