Add the original source packages to maemo, source lenny
[dh-make-perl] / dev / i386 / libwww-mechanize-perl / libwww-mechanize-perl-1.34 / t / local / get.t
1 #!perl
2
3 use warnings;
4 use strict;
5 use Test::More tests => 32;
6
7 use lib 't/local';
8 use LocalServer;
9
10
11 BEGIN {
12     delete @ENV{ grep { lc eq 'http_proxy' } keys %ENV };
13     delete @ENV{ qw( IFS CDPATH ENV BASH_ENV ) };
14     use_ok( 'WWW::Mechanize' );
15 }
16
17 eval "use Test::Memory::Cycle";
18 my $canTMC = !$@;
19
20 my $server = LocalServer->spawn;
21 isa_ok( $server, 'LocalServer' );
22
23 my $agent = WWW::Mechanize->new;
24 isa_ok( $agent, 'WWW::Mechanize', 'Created object' );
25
26 my $response = $agent->get($server->url);
27 isa_ok( $response, 'HTTP::Response' );
28 isa_ok( $agent->response, 'HTTP::Response' );
29 ok( $response->is_success, 'Page read OK' );
30 ok( $agent->success, "Get webpage" );
31 is( $agent->ct, "text/html", "Got the content-type..." );
32 ok( $agent->is_html, "... and the is_html wrapper" );
33 is( $agent->title, 'WWW::Mechanize::Shell test page', 'Titles match' );
34
35 $agent->get( '/foo/' );
36 ok( $agent->success, 'Got the /foo' );
37 is( $agent->uri, sprintf('%sfoo/',$server->url), 'Got relative OK' );
38 ok( $agent->is_html,'Got HTML back' );
39 is( $agent->title, 'WWW::Mechanize::Shell test page', 'Got the right page' );
40
41 $agent->get( '../bar/' );
42 ok( $agent->success, 'Got the /bar page' );
43 is( $agent->uri, sprintf('%sbar/',$server->url), 'Got relative OK' );
44 ok( $agent->is_html, 'is HTML' );
45 is( $agent->title, 'WWW::Mechanize::Shell test page', 'Got the right page' );
46
47 $agent->get( 'basics.html' );
48 ok( $agent->success, 'Got the basics page' );
49 is( $agent->uri, sprintf('%sbar/basics.html',$server->url), 'Got relative OK' );
50 ok( $agent->is_html, 'is HTML' );
51 is( $agent->title, 'WWW::Mechanize::Shell test page', 'Title matches' );
52 like( $agent->content, qr/WWW::Mechanize::Shell test page/, 'Got the right page' );
53
54 $agent->get( './refinesearch.html' );
55 ok( $agent->success, 'Got the "refine search" page' );
56 is( $agent->uri, sprintf('%sbar/refinesearch.html',$server->url), 'Got relative OK' );
57 ok( $agent->is_html, 'is HTML' );
58 is( $agent->title, 'WWW::Mechanize::Shell test page', 'Title matches' );
59 like( $agent->content, qr/WWW::Mechanize::Shell test page/, 'Got the right page' );
60 my $rslength = length $agent->content;
61
62 my $tempfile = './temp';
63 unlink $tempfile;
64 ok( !-e $tempfile, 'tempfile not there right now' );
65 $agent->get( './refinesearch.html', ':content_file'=>$tempfile );
66 ok( -e $tempfile, 'File exists' );
67 is( -s $tempfile, $rslength, 'Did all the bytes get saved?' );
68 unlink $tempfile;
69
70 SKIP: {
71     skip 'Test::Memory::Cycle not installed', 1 unless $canTMC;
72
73     memory_cycle_ok( $agent, 'Mech: no cycles' );
74 }