PageRenderTime 21ms CodeModel.GetById 1ms app.highlight 16ms RepoModel.GetById 1ms app.codeStats 0ms

/XML-TreePP/t/27_http-lite-force.t

http://xml-treepp.googlecode.com/
Unknown | 65 lines | 57 code | 8 blank | 0 comment | 0 complexity | 264cb7e72d8173209858c9a66bc96a9a MD5 | raw file
 1# ----------------------------------------------------------------
 2    use strict;
 3    use Test::More;
 4# ----------------------------------------------------------------
 5SKIP: {
 6    local $@;
 7    eval { require HTTP::Lite; } unless defined $HTTP::Lite::VERSION;
 8    if ( ! defined $HTTP::Lite::VERSION ) {
 9        plan skip_all => 'HTTP::Lite is not loaded.';
10    }
11    eval { require LWP::UserAgent; } unless defined $LWP::UserAgent::VERSION;
12    if ( ! defined $LWP::UserAgent::VERSION ) {
13        # ok
14    }
15    if ( ! defined $ENV{MORE_TESTS} ) {
16        plan skip_all => 'define $MORE_TESTS to test this.';
17    }
18    plan tests => 14;
19    use_ok('XML::TreePP');
20
21    my $name = 'HTTP::Lite';
22    my $url = "http://www.kawa.net/works/perl/treepp/example/envxml.cgi";
23    my $query = time();
24
25    {
26        my $tpp = XML::TreePP->new();
27        my $http = HTTP::Lite->new();
28        ok( ref $http, 'HTTP::Lite->new()' );
29        $tpp->set( http_lite => $http );
30        $tpp->set( user_agent => '' );
31        &test_http_req( $tpp, $name, POST => $url, $query );   # use HTTP::Lite
32    }
33
34    {
35        my $tpp = XML::TreePP->new();
36        my $http = HTTP::Lite->new();
37        ok( ref $http, 'HTTP::Lite->new()' );
38        $tpp->set( http_lite => $http );
39        $tpp->set( user_agent => '' );
40        my $ret = &test_http_req( $tpp, $name, GET => "$url?$query" );
41        is( $ret, $query, "QUERY_STRING: $query" );
42    }
43}
44# ----------------------------------------------------------------
45sub test_http_req {
46    my $tpp = shift;
47    my $name = shift;
48
49    my( $tree, $xml, $code ) = $tpp->parsehttp( @_ );
50    ok( ref $tree, "parsehttp: $_[1]" );
51
52    my $decl = ( $xml =~ /(<\?xml[^>]+>)/ )[0];
53    like( $xml, qr/(<\?xml[^>]+>)/, "XML Decl: $decl" );
54
55    is( $code, 200, "HTTP Status: $code" );
56
57    my $agent = $tree->{env}->{HTTP_USER_AGENT};
58    ok( $agent, "User-Agent: $agent" );
59    like( $agent, qr/\Q$name\E/, "Match: $name" );
60
61    $tree->{env}->{QUERY_STRING};
62}
63# ----------------------------------------------------------------
64;1;
65# ----------------------------------------------------------------