File: 29_http-lwp-withcache.t

package info (click to toggle)
libxml-treepp-perl 0.43-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 680 kB
  • sloc: perl: 810; xml: 58; sh: 41; makefile: 2
file content (41 lines) | stat: -rwxr-xr-x 1,536 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
38
39
40
41
# ----------------------------------------------------------------
    use strict;
    use Test::More;
# ----------------------------------------------------------------
SKIP: {
    local $@;
    eval { require LWP::UserAgent::WithCache; } unless defined $LWP::UserAgent::WithCache::VERSION;
    if ( ! defined $LWP::UserAgent::WithCache::VERSION ) {
        plan skip_all => 'LWP::UserAgent::WithCache is not loaded.';
    }
    if ( ! defined $ENV{MORE_TESTS} ) {
        plan skip_all => 'define $MORE_TESTS to test this.';
    }
    plan tests => 6;
    use_ok('XML::TreePP');

    my $http = LWP::UserAgent::WithCache->new();
    ok( ref $http, 'LWP::UserAgent::WithCache' );
    my $name = ( $0 =~ m#([^/:\\]+)$# )[0];
    $http->agent( "$name " );

    my $tpp = XML::TreePP->new();
    $tpp->set( lwp_useragent => $http );

    &test_http_post( $tpp, $name );     # use LWP::UserAgent::WithCache
}
# ----------------------------------------------------------------
sub test_http_post {
    my $tpp = shift;
    my $name = shift;
    my $url = "http://www.kawa.net/works/perl/treepp/example/envxml.cgi";
    my( $tree, $xml ) = $tpp->parsehttp( POST => $url, '' );
    ok( ref $tree, $url );
    my $agent = $tree->{env}->{HTTP_USER_AGENT};
    ok( $agent, "User-Agent: $agent" );
    like( $agent, qr/libwww-perl/, "Test: libwww-perl" );
    like( $agent, qr/\Q$name\E/, "Test: $name" );
}
# ----------------------------------------------------------------
;1;
# ----------------------------------------------------------------