Test case using Exception::Class
[catagits/Catalyst-Runtime.git] / t / unit_core_uri_with.t
CommitLineData
3c9e6294 1use strict;
2use warnings;
3
a375a206 4use Test::More tests => 10;
3c9e6294 5use URI;
6
7use_ok('Catalyst::Request');
8
9my $request = Catalyst::Request->new( {
10 uri => URI->new('http://127.0.0.1/foo/bar/baz')
11 } );
12
13is(
14 $request->uri_with({}),
15 'http://127.0.0.1/foo/bar/baz',
16 'URI for absolute path'
17);
18
19is(
20 $request->uri_with({ foo => 'bar' }),
21 'http://127.0.0.1/foo/bar/baz?foo=bar',
22 'URI adds param'
23);
24
25my $request2 = Catalyst::Request->new( {
26 uri => URI->new('http://127.0.0.1/foo/bar/baz?bar=gorch')
27 } );
28is(
29 $request2->uri_with({}),
30 'http://127.0.0.1/foo/bar/baz?bar=gorch',
31 'URI retains param'
32);
33
34is(
35 $request2->uri_with({ me => 'awesome' }),
36 'http://127.0.0.1/foo/bar/baz?bar=gorch&me=awesome',
37 'URI retains param and adds new'
38);
39
40is(
41 $request2->uri_with({ bar => undef }),
42 'http://127.0.0.1/foo/bar/baz',
43 'URI loses param when explicitly undef'
44);
45
46is(
47 $request2->uri_with({ bar => 'snort' }),
48 'http://127.0.0.1/foo/bar/baz?bar=snort',
49 'URI changes param'
50);
a375a206 51
52is(
53 $request2->uri_with({ bar => [ 'snort', 'ewok' ] }),
54 'http://127.0.0.1/foo/bar/baz?bar=snort&bar=ewok',
55 'overwrite mode URI appends arrayref param'
56);
57
58is(
59 $request2->uri_with({ bar => 'snort' }, { mode => 'append' }),
60 'http://127.0.0.1/foo/bar/baz?bar=gorch&bar=snort',
61 'append mode URI appends param'
62);
63
64is(
65 $request2->uri_with({ bar => [ 'snort', 'ewok' ] }, { mode => 'append' }),
66 'http://127.0.0.1/foo/bar/baz?bar=gorch&bar=snort&bar=ewok',
67 'append mode URI appends arrayref param'
68);
69