Switched to Module::Install
[catagits/Catalyst-Runtime.git] / t / unit_core_uri_for.t
1 use strict;
2 use warnings;
3
4 use Test::More tests => 6;
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( Catalyst::uri_for( $context, '../quux' )->as_string,
30     'http://127.0.0.1/foo/quux', 'URI for relative dot path' );
31
32 $request->mock( 'base',  sub { URI->new('http://localhost:3000/') } );
33 $request->mock( 'match', sub { 'orderentry/contract' } );
34 is(
35     Catalyst::uri_for( $context, '/Orderentry/saveContract' )->as_string,
36     'http://localhost:3000/Orderentry/saveContract',
37     'URI for absolute path'
38 );
39
40 {
41     $request->mock( 'base', sub { URI->new('http://127.0.0.1/') } );
42
43     my $context = Test::MockObject->new;
44     $context->mock( 'request',   sub { $request } );
45     $context->mock( 'namespace', sub { '' } );
46
47     is( Catalyst::uri_for( $context, '/bar/baz' )->as_string,
48         'http://127.0.0.1/bar/baz', 'URI with no base or match' );
49 }