stop using Moo as a test package
[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 URI::QueryParam;
7 use Catalyst::Log;
8
9 use_ok('Catalyst::Request');
10
11 sub 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     }
18     is_deeply $got->query_form_hash, $exp->query_form_hash, "$comment: query";
19 }
20
21 my $request = Catalyst::Request->new( {
22                 _log => Catalyst::Log->new,
23                 uri => URI->new('http://127.0.0.1/foo/bar/baz')
24               } );
25
26 cmp_uri(
27     $request->uri_with({}),
28     'http://127.0.0.1/foo/bar/baz',
29     'URI for absolute path'
30 );
31
32 cmp_uri(
33     $request->uri_with({ foo => 'bar' }),
34     'http://127.0.0.1/foo/bar/baz?foo=bar',
35     'URI adds param'
36 );
37
38 my $request2 = Catalyst::Request->new( {
39                 _log => Catalyst::Log->new,
40                 uri => URI->new('http://127.0.0.1/foo/bar/baz?bar=gorch')
41               } );
42
43 cmp_uri(
44     $request2->uri_with({}),
45     'http://127.0.0.1/foo/bar/baz?bar=gorch',
46     'URI retains param'
47 );
48
49 cmp_uri(
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
55 cmp_uri(
56     $request2->uri_with({ bar => undef }),
57     'http://127.0.0.1/foo/bar/baz',
58     'URI loses param when explicitly undef'
59 );
60
61 cmp_uri(
62     $request2->uri_with({ bar => 'snort' }),
63     'http://127.0.0.1/foo/bar/baz?bar=snort',
64     'URI changes param'
65 );
66
67 cmp_uri(
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
73 cmp_uri(
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
79 cmp_uri(
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
85 done_testing;
86