Change Catalsyt _parse_attrs so that when sub attr handlers:
[catagits/Catalyst-Runtime.git] / t / aggregate / unit_core_uri_with.t
1 use strict;
2 use warnings;
3
4 use Test::More;
5 use URI;
6 use Catalyst::Log;
7
8 use_ok('Catalyst::Request');
9
10 my $request = Catalyst::Request->new( {
11                 _log => Catalyst::Log->new,
12                 uri => URI->new('http://127.0.0.1/foo/bar/baz')
13               } );
14
15 is(
16     $request->uri_with({}),
17     'http://127.0.0.1/foo/bar/baz',
18     'URI for absolute path'
19 );
20
21 is(
22     $request->uri_with({ foo => 'bar' }),
23     'http://127.0.0.1/foo/bar/baz?foo=bar',
24     'URI adds param'
25 );
26
27 my $request2 = Catalyst::Request->new( {
28                 _log => Catalyst::Log->new,
29                 uri => URI->new('http://127.0.0.1/foo/bar/baz?bar=gorch')
30               } );
31 is(
32     $request2->uri_with({}),
33     'http://127.0.0.1/foo/bar/baz?bar=gorch',
34     'URI retains param'
35 );
36
37 is(
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
43 is(
44     $request2->uri_with({ bar => undef }),
45     'http://127.0.0.1/foo/bar/baz',
46     'URI loses param when explicitly undef'
47 );
48
49 is(
50     $request2->uri_with({ bar => 'snort' }),
51     'http://127.0.0.1/foo/bar/baz?bar=snort',
52     'URI changes param'
53 );
54
55 is(
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
61 is(
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
67 is(
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
73 done_testing;
74