1use warnings; 2use strict; 3use Test::More; 4 5use lib 't/local'; 6use LocalServer; 7 8 9BEGIN { 10 delete @ENV{ qw( IFS CDPATH ENV BASH_ENV ) }; 11} 12 13my $NONEXISTENT = 'blahblahblah.xx-only-testing.foo.'; 14my @results = gethostbyname( $NONEXISTENT ); 15if ( @results ) { 16 my ($name,$aliases,$addrtype,$length,@addrs) = @results; 17 my $ip = join( '.', unpack('C4',$addrs[0]) ); 18 plan skip_all => "Your ISP is overly helpful and returns $ip for non-existent domain $NONEXISTENT. This test cannot be run."; 19} 20my $bad_url = "http://$NONEXISTENT/"; 21 22plan tests => 15; 23require_ok( 'WWW::Mechanize' ); 24my $server = LocalServer->spawn; 25isa_ok( $server, 'LocalServer' ); 26 27my $mech = WWW::Mechanize->new( autocheck => 0 ); 28isa_ok( $mech, 'WWW::Mechanize', 'Created object' ); 29 30GOOD_PAGE: { 31 my $response = $mech->get($server->url); 32 isa_ok( $response, 'HTTP::Response' ); 33 ok( $response->is_success, 'Success' ); 34 ok( $mech->success, 'Get webpage' ); 35 ok( $mech->is_html, 'It\'s HTML' ); 36 is( $mech->title, 'WWW::Mechanize test page', 'Correct title' ); 37 38 my @links = $mech->links; 39 is( scalar @links, 10, '10 links, please' ); 40 my @forms = $mech->forms; 41 is( scalar @forms, 2, 'Two form' ); 42} 43 44BAD_PAGE: { 45 my $bad_url = "http://$NONEXISTENT/"; 46 $mech->get( $bad_url ); 47 48 ok( !$mech->success, 'Failed the fetch' ); 49 ok( !$mech->is_html, "Isn't HTML" ); 50 ok( !defined $mech->title, "No title" ); 51 52 my @links = $mech->links; 53 is( scalar @links, 0, "No links" ); 54 55 my @forms = $mech->forms; 56 is( scalar @forms, 0, "No forms" ); 57} 58