nuked Test::NoWarnings
[catagits/Catalyst-Runtime.git] / t / unit_core_uri_for.t
1 use strict;
2 use warnings;
3
4 use Test::More tests => 9;
5 use Test::MockObject;
6 use URI;
7
8 my $request = Test::MockObject->new;
9 $request->mock( 'base', sub { URI->new('http://127.0.0.1/foo') } );
10
11 my $context = Test::MockObject->new;
12 $context->mock( 'request',   sub { $request } );
13 $context->mock( 'namespace', sub { 'yada' } );
14
15 use_ok('Catalyst');
16
17 is(
18     Catalyst::uri_for( $context, '/bar/baz' )->as_string,
19     'http://127.0.0.1/foo/bar/baz',
20     'URI for absolute path'
21 );
22
23 is(
24     Catalyst::uri_for( $context, 'bar/baz' )->as_string,
25     'http://127.0.0.1/foo/yada/bar/baz',
26     'URI for relative path'
27 );
28
29 is(
30     Catalyst::uri_for( $context, '', 'arg1', 'arg2' )->as_string,
31     'http://127.0.0.1/foo/yada/arg1/arg2',
32     'URI for undef action with args'
33 );
34
35
36 is( Catalyst::uri_for( $context, '../quux' )->as_string,
37     'http://127.0.0.1/foo/quux', 'URI for relative dot path' );
38
39 is(
40     Catalyst::uri_for( $context, 'quux', { param1 => 'value1' } )->as_string,
41     'http://127.0.0.1/foo/yada/quux?param1=value1',
42     'URI for undef action with query params'
43 );
44
45 # test with utf-8
46 is(
47     Catalyst::uri_for( $context, 'quux', { param1 => "\x{2620}" } )->as_string,
48     'http://127.0.0.1/foo/yada/quux?param1=%E2%98%A0',
49     'URI for undef action with query params in unicode'
50 );
51
52 $request->mock( 'base',  sub { URI->new('http://localhost:3000/') } );
53 $request->mock( 'match', sub { 'orderentry/contract' } );
54 is(
55     Catalyst::uri_for( $context, '/Orderentry/saveContract' )->as_string,
56     'http://localhost:3000/Orderentry/saveContract',
57     'URI for absolute path'
58 );
59
60 {
61     $request->mock( 'base', sub { URI->new('http://127.0.0.1/') } );
62
63     my $context = Test::MockObject->new;
64     $context->mock( 'request',   sub { $request } );
65     $context->mock( 'namespace', sub { '' } );
66
67     is( Catalyst::uri_for( $context, '/bar/baz' )->as_string,
68         'http://127.0.0.1/bar/baz', 'URI with no base or match' );
69 }
70