3 use Test::More skip_all => "Mysteriously stopped passing, and I don't know why.";
8 use Test::More tests => 11;
16 This tests for various ways, advertised in L<WWW::Mechanize>, to
17 create a subclass of the mech to alter it's behavior in a useful
18 manner. (Of course free-style overloading is discouraged, as it breaks
19 encapsulation big time.)
21 This test first feeds some bad HTML to Mech to make sure that it throws
22 an error. Then, it overloads update_html() to fix the HTML before
23 processing it, and then we should not have an error.
25 =head2 Overloading update_html()
27 This is the recommended way to tidy up the received HTML in a generic
28 way, and/or to install supplemental "surface tests" on the HTML
34 delete @ENV{ grep { lc eq 'http_proxy' } keys %ENV };
35 delete @ENV{ qw( IFS CDPATH ENV BASH_ENV ) };
36 use_ok( 'WWW::Mechanize' );
39 my $server = LocalServer->spawn(html => <<'BROKEN_HTML');
41 <head><title>Broken document</head>
44 <tr><select name="foo">
45 <option value="bar">Bar</option></td></tr>
49 isa_ok( $server, 'LocalServer' );
53 use base 'WWW::Mechanize';
59 $html =~ s[Broken][Fixed]isg or die "Couldn't fix the HTML for the test (#1)";
60 $html =~ s[</option>.{0,3}</td>][</option></select></td>]isg or die "Couldn't fix the HTML for the test (#2)";
62 $self->WWW::Mechanize::update_html( $html );
68 no warnings 'redefine';
69 local *Carp::carp = sub {$carpmsg = shift};
71 my $mech = WWW::Mechanize->new();
72 isa_ok( $mech, 'WWW::Mechanize' );
74 $mech->get( $server->url );
75 like($carpmsg, qr/bad.*select/i, 'Standard mech chokes on bogus HTML');
77 # If at first you don't succeed, try with a shorter bungee...
79 $mech = MyMech->new();
80 isa_ok( $mech, 'WWW::Mechanize', 'Derived object' );
82 my $response = $mech->get( $server->url );
83 isa_ok( $response, 'HTTP::Response', 'Response I got back' );
84 ok( $response->is_success, 'Got URL' ) or die 'Can\'t even fetch local url';
85 ok( $mech->is_html, 'Local page is HTML' );
86 ok( !$carpmsg, 'No warnings this time' );
88 my @forms = $mech->forms;
89 is( scalar @forms, 1, 'One form' );
91 like($mech->content(), qr[/select], 'alteration visible in ->content() too');