File: request.t

package info (click to toggle)
libsru-perl 1.01-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 240 kB
  • sloc: perl: 836; makefile: 2
file content (37 lines) | stat: -rw-r--r-- 1,179 bytes parent folder | download | duplicates (4)
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
use strict;
use warnings;

use Test::More;
use SRU::Request;

my @queries = (
'operation=scan&version=1.1&scanClause=%2fdc.title%3d%22cat%22&responsePosition=3&maximumTerms=50&stylesheet=http://myserver.com/myStyle',
'operation=explain&version=1.0&recordPacking=xml&stylesheet=http://www.example.com/style.xsl&extraRequestData=123',
'operation=searchRetrieve&version=1.1&query=dc.identifier+%3d%220-8212-1623-6%22&recordSchema=dc&recordPacking=XML&stylesheet=http://myserver.com/myStyle',
);

sub normalize_url {
    my $url = URI->new(shift);
    my %query = $url->query_form;
    my @sorted = map { $_ => $query{$_} } sort keys %query;
    $url->query_form( \@sorted, '&' );
    return $url;
}

sub is_same_url {
    is normalize_url($_[0]), normalize_url($_[1]), $_[2];
}

foreach my $query (@queries) {
    my $request = SRU::Request->new( { QUERY_STRING => $query } );

    my $uri = URI->new( "http://myserver.com/myurl?$query" );
    my $base = "http://myserver.com/myurl";
    is_same_url( $request->asURI($base), $uri, 'asURI with base');

    $uri->host('localhost');
    $uri->path('/');
    is_same_url( $request->asURI, $uri, 'asURI without base');
}

done_testing;