use inlined module hiding in tests
[catagits/Catalyst-Runtime.git] / t / aggregate / unit_core_uri_with.t
CommitLineData
3c9e6294 1use strict;
2use warnings;
3
7c1c4dc6 4use Test::More;
3c9e6294 5use URI;
d527814d 6use URI::QueryParam;
7c1c4dc6 7use Catalyst::Log;
3c9e6294 8
9use_ok('Catalyst::Request');
10
1e8c91ac 11sub cmp_uri {
12 my ($got, $exp_txt, $comment) = @_;
13 $comment ||= '';
14 my $exp = URI->new($exp_txt);
15 foreach my $thing (qw/ scheme host path /) {
16 is $exp->$thing, $got->$thing, "$comment: $thing";
17 }
d527814d 18 is_deeply $got->query_form_hash, $exp->query_form_hash, "$comment: query";
1e8c91ac 19}
20
3c9e6294 21my $request = Catalyst::Request->new( {
7c1c4dc6 22 _log => Catalyst::Log->new,
3c9e6294 23 uri => URI->new('http://127.0.0.1/foo/bar/baz')
24 } );
25
1e8c91ac 26cmp_uri(
3c9e6294 27 $request->uri_with({}),
28 'http://127.0.0.1/foo/bar/baz',
29 'URI for absolute path'
30);
31
1e8c91ac 32cmp_uri(
3c9e6294 33 $request->uri_with({ foo => 'bar' }),
34 'http://127.0.0.1/foo/bar/baz?foo=bar',
35 'URI adds param'
36);
37
38my $request2 = Catalyst::Request->new( {
7c1c4dc6 39 _log => Catalyst::Log->new,
3c9e6294 40 uri => URI->new('http://127.0.0.1/foo/bar/baz?bar=gorch')
41 } );
1e8c91ac 42
43cmp_uri(
3c9e6294 44 $request2->uri_with({}),
45 'http://127.0.0.1/foo/bar/baz?bar=gorch',
46 'URI retains param'
47);
48
1e8c91ac 49cmp_uri(
3c9e6294 50 $request2->uri_with({ me => 'awesome' }),
51 'http://127.0.0.1/foo/bar/baz?bar=gorch&me=awesome',
52 'URI retains param and adds new'
53);
54
1e8c91ac 55cmp_uri(
3c9e6294 56 $request2->uri_with({ bar => undef }),
57 'http://127.0.0.1/foo/bar/baz',
58 'URI loses param when explicitly undef'
59);
60
1e8c91ac 61cmp_uri(
3c9e6294 62 $request2->uri_with({ bar => 'snort' }),
63 'http://127.0.0.1/foo/bar/baz?bar=snort',
64 'URI changes param'
65);
a375a206 66
1e8c91ac 67cmp_uri(
a375a206 68 $request2->uri_with({ bar => [ 'snort', 'ewok' ] }),
69 'http://127.0.0.1/foo/bar/baz?bar=snort&bar=ewok',
70 'overwrite mode URI appends arrayref param'
71);
72
1e8c91ac 73cmp_uri(
a375a206 74 $request2->uri_with({ bar => 'snort' }, { mode => 'append' }),
75 'http://127.0.0.1/foo/bar/baz?bar=gorch&bar=snort',
76 'append mode URI appends param'
77);
78
1e8c91ac 79cmp_uri(
a375a206 80 $request2->uri_with({ bar => [ 'snort', 'ewok' ] }, { mode => 'append' }),
81 'http://127.0.0.1/foo/bar/baz?bar=gorch&bar=snort&bar=ewok',
82 'append mode URI appends arrayref param'
83);
84
7c1c4dc6 85done_testing;
86