Debian lenny version packages
[pkg-perl] / deb-src / libwww-mechanize-perl / libwww-mechanize-perl-1.34 / t / local / failure.t
1 #!perl
2
3 use warnings;
4 use strict;
5 use Test::More;
6
7 use lib 't/local';
8 use LocalServer;
9
10 BEGIN {
11     if (gethostbyname('blahblahblah.xx-only-testing.')) {
12         plan skip_all => 'Found an A record for the non-existent domain';
13     }
14     plan tests => 16;
15 }
16
17 BEGIN {
18     delete @ENV{ grep { lc eq 'http_proxy' } keys %ENV };
19     delete @ENV{ qw( IFS CDPATH ENV BASH_ENV ) };
20     use_ok( 'WWW::Mechanize' );
21 }
22
23 my $server = LocalServer->spawn;
24 isa_ok( $server, 'LocalServer' );
25
26
27 my $mech = WWW::Mechanize->new;
28 isa_ok( $mech, 'WWW::Mechanize', 'Created object' );
29
30 GOOD_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::Shell 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, 1, 'One form' );
42     isa_ok( $forms[0], 'HTML::Form' );
43 }
44
45 BAD_PAGE: {
46     my $badurl = "http://blahblahblah.xx-only-testing.";
47     $mech->get( $badurl );
48
49     ok( !$mech->success, 'Failed the fetch' );
50     ok( !$mech->is_html, "Isn't HTML" );
51     ok( !defined $mech->title, "No title" );
52
53     my @links = $mech->links;
54     is( scalar @links, 0, "No links" );
55
56     my @forms = $mech->forms;
57     is( scalar @forms, 0, "No forms" );
58 }