Change Catalsyt _parse_attrs so that when sub attr handlers:
[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;
7c1c4dc6 6use Catalyst::Log;
3c9e6294 7
8use_ok('Catalyst::Request');
9
10my $request = Catalyst::Request->new( {
7c1c4dc6 11 _log => Catalyst::Log->new,
3c9e6294 12 uri => URI->new('http://127.0.0.1/foo/bar/baz')
13 } );
14
15is(
16 $request->uri_with({}),
17 'http://127.0.0.1/foo/bar/baz',
18 'URI for absolute path'
19);
20
21is(
22 $request->uri_with({ foo => 'bar' }),
23 'http://127.0.0.1/foo/bar/baz?foo=bar',
24 'URI adds param'
25);
26
27my $request2 = Catalyst::Request->new( {
7c1c4dc6 28 _log => Catalyst::Log->new,
3c9e6294 29 uri => URI->new('http://127.0.0.1/foo/bar/baz?bar=gorch')
30 } );
31is(
32 $request2->uri_with({}),
33 'http://127.0.0.1/foo/bar/baz?bar=gorch',
34 'URI retains param'
35);
36
37is(
38 $request2->uri_with({ me => 'awesome' }),
39 'http://127.0.0.1/foo/bar/baz?bar=gorch&me=awesome',
40 'URI retains param and adds new'
41);
42
43is(
44 $request2->uri_with({ bar => undef }),
45 'http://127.0.0.1/foo/bar/baz',
46 'URI loses param when explicitly undef'
47);
48
49is(
50 $request2->uri_with({ bar => 'snort' }),
51 'http://127.0.0.1/foo/bar/baz?bar=snort',
52 'URI changes param'
53);
a375a206 54
55is(
56 $request2->uri_with({ bar => [ 'snort', 'ewok' ] }),
57 'http://127.0.0.1/foo/bar/baz?bar=snort&bar=ewok',
58 'overwrite mode URI appends arrayref param'
59);
60
61is(
62 $request2->uri_with({ bar => 'snort' }, { mode => 'append' }),
63 'http://127.0.0.1/foo/bar/baz?bar=gorch&bar=snort',
64 'append mode URI appends param'
65);
66
67is(
68 $request2->uri_with({ bar => [ 'snort', 'ewok' ] }, { mode => 'append' }),
69 'http://127.0.0.1/foo/bar/baz?bar=gorch&bar=snort&bar=ewok',
70 'append mode URI appends arrayref param'
71);
72
7c1c4dc6 73done_testing;
74