File: unit_core_uri_with.t

package info (click to toggle)
libcatalyst-perl 5.90132-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,016 kB
  • sloc: perl: 11,061; makefile: 7
file content (86 lines) | stat: -rw-r--r-- 2,091 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
use strict;
use warnings;

use Test::More;
use URI;
use URI::QueryParam;
use Catalyst::Log;

use_ok('Catalyst::Request');

sub cmp_uri {
    my ($got, $exp_txt, $comment) = @_;
    $comment ||= '';
    my $exp = URI->new($exp_txt);
    foreach my $thing (qw/ scheme host path /) {
        is $exp->$thing, $got->$thing, "$comment: $thing";
    }
    is_deeply $got->query_form_hash, $exp->query_form_hash, "$comment: query";
}

my $request = Catalyst::Request->new( {
                _log => Catalyst::Log->new,
                uri => URI->new('http://127.0.0.1/foo/bar/baz')
              } );

cmp_uri(
    $request->uri_with({}),
    'http://127.0.0.1/foo/bar/baz',
    'URI for absolute path'
);

cmp_uri(
    $request->uri_with({ foo => 'bar' }),
    'http://127.0.0.1/foo/bar/baz?foo=bar',
    'URI adds param'
);

my $request2 = Catalyst::Request->new( {
                _log => Catalyst::Log->new,
                uri => URI->new('http://127.0.0.1/foo/bar/baz?bar=gorch')
              } );

cmp_uri(
    $request2->uri_with({}),
    'http://127.0.0.1/foo/bar/baz?bar=gorch',
    'URI retains param'
);

cmp_uri(
    $request2->uri_with({ me => 'awesome' }),
    'http://127.0.0.1/foo/bar/baz?bar=gorch&me=awesome',
    'URI retains param and adds new'
);

cmp_uri(
    $request2->uri_with({ bar => undef }),
    'http://127.0.0.1/foo/bar/baz',
    'URI loses param when explicitly undef'
);

cmp_uri(
    $request2->uri_with({ bar => 'snort' }),
    'http://127.0.0.1/foo/bar/baz?bar=snort',
    'URI changes param'
);

cmp_uri(
    $request2->uri_with({ bar => [ 'snort', 'ewok' ] }),
    'http://127.0.0.1/foo/bar/baz?bar=snort&bar=ewok',
    'overwrite mode URI appends arrayref param'
);

cmp_uri(
    $request2->uri_with({ bar => 'snort' }, { mode => 'append' }),
    'http://127.0.0.1/foo/bar/baz?bar=gorch&bar=snort',
    'append mode URI appends param'
);

cmp_uri(
    $request2->uri_with({ bar => [ 'snort', 'ewok' ] }, { mode => 'append' }),
    'http://127.0.0.1/foo/bar/baz?bar=gorch&bar=snort&bar=ewok',
    'append mode URI appends arrayref param'
);

done_testing;