Test 1Test 2Test 3
Test-WWW-Mechanize-1.60/t/manylinks.html 0000644 0001750 0001750 00000001011 14343263442 016546 0 ustar andy andy
Test Page
Test Page of many link types
Test 1Blah blahSecureMail your complaintsGet your distroTest 2Test 3
Test-WWW-Mechanize-1.60/t/click_ok.t 0000644 0001750 0001750 00000001727 14343270541 015632 0 ustar andy andy #!perl -T
use strict;
use warnings;
use Test::More tests => 6;
use Test::Builder::Tester;
use Test::WWW::Mechanize ();
use lib 't';
use TestServer;
my $server = TestServer->new;
my $pid = $server->background;
my $server_root = $server->root;
SUBMIT_GOOD_FORM: {
local @ENV{qw( http_proxy HTTP_PROXY )};
my $mech = Test::WWW::Mechanize->new();
isa_ok( $mech,'Test::WWW::Mechanize' );
$mech->get_ok( "$server_root/form.html" );
$mech->click_ok( 'big_button', 'Submit First Form' );
# XXX We need to check that the request is correct.
}
SUBMIT_GOOD_FORM_WITH_COORDINATES: {
local @ENV{qw( http_proxy HTTP_PROXY )};
my $mech = Test::WWW::Mechanize->new();
isa_ok( $mech,'Test::WWW::Mechanize' );
$mech->get_ok( "$server_root/form.html" );
$mech->click_ok( ['big_button',360,80], 'Submit First Form with coordinates' );
# XXX We need to check that the request is correct.
}
$server->stop;
done_testing();
exit 0;
Test-WWW-Mechanize-1.60/t/text_contains.t 0000644 0001750 0001750 00000002206 14343263442 016731 0 ustar andy andy #!perl -T
use strict;
use warnings;
use Test::More tests => 5;
use Test::Builder::Tester;
use URI::file;
use Test::WWW::Mechanize ();
my $mech = Test::WWW::Mechanize->new();
isa_ok( $mech,'Test::WWW::Mechanize' );
my $uri = URI::file->new_abs( 't/goodlinks.html' )->as_string;
$mech->get_ok( $uri );
# test regex
test_out( 'ok 1 - Does it say test page?' );
$mech->text_contains( 'Test Page', 'Does it say test page?' );
test_test( 'Finds the contains' );
# default desc
test_out( 'ok 1 - Text contains "Test Page"' );
$mech->text_contains( 'Test Page');
test_test( 'Finds the contains - default desc' );
# Handles not finding something. Also, what we are searching for IS
# found in content_contains() but NOT in text_contains().
test_out( 'not ok 1 - Trying to find goodlinks' );
test_fail(+5);
test_diag( q{ searched: "Test PageTest PageTest 1 Test 2 Test 3"} );
test_diag( q{ can't find: "goodlinks.html"} );
test_diag( q{ LCSS: "s"} );
test_diag( q{LCSS context: "Test PageTest PageTest 1 Test 2 Test 3"} );
$mech->text_contains( 'goodlinks.html', 'Trying to find goodlinks' );
test_test( 'Handles not finding it' );
done_testing();
Test-WWW-Mechanize-1.60/t/page_links_ok.t 0000644 0001750 0001750 00000001726 14343263442 016662 0 ustar andy andy #!perl -T
use strict;
use warnings;
use Test::More tests => 6;
use Test::Builder::Tester;
use URI::file;
use Test::WWW::Mechanize ();
my $mech = Test::WWW::Mechanize->new();
isa_ok($mech,'Test::WWW::Mechanize');
my $uri = URI::file->new_abs( 't/goodlinks.html' )->as_string;
$mech->get_ok( $uri );
# Good links.
test_out('ok 1 - Checking all page links successful');
$mech->page_links_ok('Checking all page links successful');
test_test('Handles All page links successful');
# Good links - default desc
test_out('ok 1 - All links ok');
$mech->page_links_ok();
test_test('Handles All page links successful - default desc');
# Bad links
$uri = URI::file->new_abs( 't/badlinks.html' )->as_string;
$mech->get_ok( $uri );
test_out('not ok 1 - Checking some page link failures');
test_fail(+4);
test_diag('bad1.html');
test_diag('bad2.html');
test_diag('bad3.html');
$mech->page_links_ok('Checking some page link failures');
test_test('Handles link not found');
done_testing();
Test-WWW-Mechanize-1.60/t/id_exists.html 0000644 0001750 0001750 00000000431 14343263442 016541 0 ustar andy andy
Test-WWW-Mechanize-1.60/t/pod-coverage.t 0000644 0001750 0001750 00000000354 14343263442 016424 0 ustar andy andy #!perl -T
use strict;
use warnings;
use Test::More;
if ( not eval 'use Test::Pod::Coverage 0.08;' ) {
plan skip_all => 'Test::Pod::Coverage 0.08 required for testing POD coverage' if $@;
}
all_pod_coverage_ok();
done_testing();
Test-WWW-Mechanize-1.60/t/00-load.t 0000644 0001750 0001750 00000001450 14343270541 015201 0 ustar andy andy #!perl -T
use warnings;
use strict;
use Test::More tests => 1;
use LWP;
use WWW::Mechanize;
use Test::Builder::Tester;
use Test::WWW::Mechanize;
pass( 'Modules loaded' );
diag( "Testing Test::WWW::Mechanize $Test::WWW::Mechanize::VERSION on Perl $], $^X" );
diag( "LWP $LWP::VERSION" );
diag( "WWW::Mechanize $WWW::Mechanize::VERSION" );
diag( "Test::More $Test::More::VERSION" );
diag( "Test::Builder::Tester $Test::Builder::Tester::VERSION" );
for my $module ( qw( HTML::Lint HTML::Tidy5 ) ) {
my $rc = eval "use $module; 1;";
if ( $rc ) {
no strict 'refs';
my $version = ${"${module}::VERSION"};
diag( "Found optional $module $version" );
}
else {
diag( "Optional $module not found. Install it to use additional features." );
}
}
done_testing();
Test-WWW-Mechanize-1.60/t/fluffy.html 0000644 0001750 0001750 00000000517 14343263442 016046 0 ustar andy andy
Test Page
This page has valid structure, but contains errors that HTML::Lint
categorizes as fluff.
goodTest
Test-WWW-Mechanize-1.60/t/bad.html 0000644 0001750 0001750 00000000343 14343263442 015276 0 ustar andy andy
Test Page
Test Page Back to badgoodTest
Test-WWW-Mechanize-1.60/t/scrape_text_by_id.t 0000644 0001750 0001750 00000015245 14343263442 017545 0 ustar andy andy #!/usr/bin/perl -T
use strict;
use warnings;
use Test::Builder::Tester;
use Test::More tests => 3;
use URI::file ();
use Test::WWW::Mechanize ();
subtest scrape_text_by_id => sub {
plan tests => 8;
my $mech = Test::WWW::Mechanize->new( autolint => 0 );
isa_ok( $mech, 'Test::WWW::Mechanize' );
my $uri = URI::file->new_abs( 't/goodlinks.html' )->as_string;
$mech->get_ok( $uri, 'Get a dummy page just to have one' );
subtest 'nothing to find' => sub {
plan tests => 2;
$mech->update_html( '' );
is_deeply( [$mech->scrape_text_by_id( 'asdf' )], [], 'empty list returned in list context' );
is( $mech->scrape_text_by_id( 'asdf' ), undef, 'undef returned in scalar context' );
};
subtest 'find one' => sub {
plan tests => 2;
$mech->update_html( '
' );
is_deeply( [$mech->scrape_text_by_id( 'asdf' )], ['contents', 'further'], 'empty list returned in list context' );
is( $mech->scrape_text_by_id( 'asdf' ), 'contents', 'first string returned in scalar context' );
};
subtest 'present but empty' => sub {
plan tests => 2;
$mech->update_html( '' );
is_deeply( [$mech->scrape_text_by_id( 'asdf' )], [''], 'list context' );
is( $mech->scrape_text_by_id( 'asdf' ), '', 'scalar context' );
};
subtest 'present but emptier' => sub {
plan tests => 2;
$mech->update_html( '' );
is_deeply( [$mech->scrape_text_by_id( 'asdf' )], [''], 'list context' );
is( $mech->scrape_text_by_id( 'asdf' ), '', 'scalar context' );
};
subtest 'nested tag' => sub {
plan tests => 2;
$mech->update_html( '
Bob and Bongo!
' );
is_deeply( [$mech->scrape_text_by_id( 'asdf' )], ['Bob and Bongo!'], 'list context' );
is( $mech->scrape_text_by_id( 'asdf' ), 'Bob and Bongo!', 'scalar context' );
};
};
subtest 'scraped_id_is and scraped_id_like' => sub {
plan tests => 5;
my $mech = Test::WWW::Mechanize->new( autolint => 0 );
isa_ok( $mech, 'Test::WWW::Mechanize' );
my $uri = URI::file->new_abs( 't/goodlinks.html' )->as_string;
$mech->get_ok( $uri, 'Get a dummy page just to have one' );
subtest 'find one' => sub {
plan tests => 2;
$mech->update_html( '
contents
' );
$mech->scraped_id_is( 'asdf', 'contents', 'Works in scalar context' );
$mech->scraped_id_like( 'asdf', qr/con.+s/, 'Works on regexes' );
};
subtest 'nested tag' => sub {
plan tests => 2;
$mech->update_html( '
Bob and Bongo!
' );
$mech->scraped_id_is( 'asdf', 'Bob and Bongo!' );
$mech->scraped_id_like( 'asdf', qr/Bob.+Bongo/ );
};
subtest 'failures' => sub {
plan tests => 6;
$mech->update_html( '
Bob and Bongo!
' );
# Test standard successes.
$mech->scraped_id_is( 'asdf', 'Bob and Bongo!' );
$mech->scraped_id_like( 'asdf', qr/Bob.+Bongo/ );
# Test failures.
test_out( 'not ok 1 - Trying to match nonexistent ID to a string' );
test_fail( +2 );
test_diag( q{Can't find ID "nonexistent" to compare to "foo"} );
$mech->scraped_id_is( 'nonexistent', 'foo', 'Trying to match nonexistent ID to a string' );
test_test( 'Fails when trying to find nonexistent ID' );
my $regex = qr/Dave/ism;
test_out( 'not ok 1 - Trying to match nonexistent ID to a regex' );
test_fail( +2 );
test_diag( qq{Can't find ID "nonexistent" to match against $regex} );
$mech->scraped_id_like( 'nonexistent', $regex, 'Trying to match nonexistent ID to a regex' );
test_test( 'Fails when mismatched against existing ID' );
# Make sure that empty tags don't get seen as non-existent.
$mech->scraped_id_is( 'empty', '' );
$mech->scraped_id_like( 'empty', qr/^$/ );
};
};
# Previous versions would miss a search for id="foo" if it was not
# exactly id="foo". Here we test for variants.
subtest 'scrape_text_by_id optimization' => sub {
plan tests => 6;
_find_the_chips( <<'HTML', 'Double-quoted ID' );
Bongo
not chips
chips
also not chips
HTML
_find_the_chips( <<'HTML', 'Single-quoted ID' );
Bongo
not chips
chips
also not chips
HTML
_find_the_chips( <<'HTML', 'Unquoted ID' );
Bongo
not chips
chips
also not chips
HTML
_find_the_chips( <<'HTML', 'Abnormal spacing' );
Bongo
not chips
chips
also not chips
HTML
_find_the_chips( <<'HTML', 'Unquoted broken across lines' );
Bongo
not chips
chips
also not chips
HTML
_find_the_chips( <<'HTML', 'Quoted broken across lines' );
Bongo
not chips
chips
also not chips
HTML
};
sub _find_the_chips {
local $Test::Builder::Level = $Test::Builder::Level + 1;
my $html = shift;
my $msg = shift or die;
return subtest "_find_the_chips( $msg )" => sub {
plan tests => 2;
my $mech = Test::WWW::Mechanize->new( autolint => 0 );
isa_ok( $mech, 'Test::WWW::Mechanize' );
$mech->update_html( $html );
$mech->scraped_id_is( 'fish', 'chips' );
};
}
done_testing();
exit 0;
Test-WWW-Mechanize-1.60/t/page_links_content.t 0000644 0001750 0001750 00000004067 14343263442 017724 0 ustar andy andy #!perl -T
use strict;
use warnings;
use Test::More tests => 9;
use Test::Builder::Tester;
use URI::file;
use Test::WWW::Mechanize ();
use lib 't';
my $mech = Test::WWW::Mechanize->new();
isa_ok( $mech,'Test::WWW::Mechanize' );
my $uri = URI::file->new_abs( 't/goodlinks.html' )->as_string;
$mech->get_ok( $uri );
# test regex
test_out('not ok 1 - page_links_content_like');
test_fail(+2);
test_diag(q{ "blah" doesn't look much like a regex to me.});
$mech->page_links_content_like('blah','Testing the regex');
test_test('Handles bad regexs');
# like
test_out('ok 1 - Checking all page links contain: Test');
$mech->page_links_content_like(qr/Test/,'Checking all page links contain: Test');
test_test('Handles All page links contents successful');
# like - default desc
my $re_string = ($] < 5.014) ? '(?-xism:Test)' : '(?^:Test)';
test_out(qq{ok 1 - All links are like "$re_string"});
$mech->page_links_content_like(qr/Test/);
test_test('Handles All page links contents successful');
test_out('not ok 1 - Checking all page link content failures');
test_fail(+4);
test_diag('goodlinks.html');
test_diag('badlinks.html');
test_diag('goodlinks.html');
$mech->page_links_content_like(qr/BadTest/,'Checking all page link content failures');
test_test('Handles link content not found');
# unlike
# test regex
test_out('not ok 1 - page_links_content_unlike');
test_fail(+2);
test_diag(q{ "blah" doesn't look much like a regex to me.});
$mech->page_links_content_unlike('blah','Testing the regex');
test_test('Handles bad regexs');
test_out('ok 1 - Checking all page links do not contain: BadTest');
$mech->page_links_content_unlike(qr/BadTest/,'Checking all page links do not contain: BadTest');
test_test('Handles All page links unlike contents successful');
test_out('not ok 1 - Checking all page link unlike content failures');
test_fail(+4);
test_diag('goodlinks.html');
test_diag('badlinks.html');
test_diag('goodlinks.html');
$mech->page_links_content_unlike(qr/Test/,'Checking all page link unlike content failures');
test_test('Handles link unlike content found');
done_testing();
Test-WWW-Mechanize-1.60/t/pod.t 0000644 0001750 0001750 00000000273 14343263442 014633 0 ustar andy andy #!perl -Tw
use strict;
use warnings;
use Test::More;
if ( not eval 'use Test::Pod 1.00;' ) {
plan skip_all => 'Test::Pod 1.00 required for testing POD' if $@;
}
all_pod_files_ok();
Test-WWW-Mechanize-1.60/t/autotidy.t 0000644 0001750 0001750 00000011466 14343263442 015721 0 ustar andy andy #!/usr/bin/env perl -T
use strict;
use warnings;
use Test::Builder::Tester;
use Test::More;
use URI::file;
use Test::WWW::Mechanize;
BEGIN {
my $module = 'HTML::Tidy5 1.00';
# Load HTML::Lint here for the imports
if ( not eval "use $module; 1;" ) {
plan skip_all => "Optional $module is not installed, cannot test autotidy.";
}
plan tests => 5;
}
subtest 'Accessor and mutator' => sub {
plan tests => 17;
my $tidy = HTML::Tidy5->new;
isa_ok( $tidy, 'HTML::Tidy5' );
ACCESSOR: {
my $mech = Test::WWW::Mechanize->new();
ok( !$mech->autotidy(), 'no autotidy to new yields autotidy off' );
$mech = Test::WWW::Mechanize->new( autotidy => undef );
ok( !$mech->autotidy(), 'undef to new yields autotidy off' );
$mech = Test::WWW::Mechanize->new( autotidy => 0 );
ok( !$mech->autotidy(), '0 to new yields autotidy off' );
$mech = Test::WWW::Mechanize->new( autotidy => 1 );
ok( $mech->autotidy(), '1 to new yields autotidy on' );
$mech = Test::WWW::Mechanize->new( autotidy => [] );
ok( $mech->autotidy(), 'non-false, non-object to new yields autotidy on' );
$mech = Test::WWW::Mechanize->new( autotidy => $tidy );
ok( $mech->autotidy(), 'HTML::Tidy5 object to new yields autotidy on' );
}
MUTATOR: {
my $mech = Test::WWW::Mechanize->new();
ok( !$mech->autotidy(0), '0 returns autotidy off' );
ok( !$mech->autotidy(), '0 autotidy really off' );
ok( !$mech->autotidy(''), '"" returns autotidy off' );
ok( !$mech->autotidy(), '"" autotidy really off' );
ok( !$mech->autotidy(1), '1 returns autotidy off (prior state)' );
ok( $mech->autotidy(), '1 autotidy really on' );
ok( $mech->autotidy($tidy), 'HTML::Tidy5 object returns autotidy on (prior state)' );
ok( $mech->autotidy(), 'HTML::Tidy5 object autotidy really on' );
my $ret = $mech->autotidy( 0 );
isa_ok( $ret, 'HTML::Tidy5' );
ok( !$mech->autotidy(), 'autotidy off after nuking HTML::Tidy5 object' );
}
};
subtest 'Fluffy page has errors' => sub {
plan tests => 2;
my $mech = Test::WWW::Mechanize->new( autotidy => 1 );
isa_ok( $mech, 'Test::WWW::Mechanize' );
my $uri = URI::file->new_abs( 't/fluffy.html' )->as_string;
test_out( "not ok 1 - GET $uri" );
test_fail( +5 );
test_err( "# HTML::Tidy5 messages for $uri" );
test_err( '# (1:1) Warning: missing declaration' );
test_err( '# (10:9) Warning: lacks "alt" attribute' );
test_err( '# 2 messages on the page' );
$mech->get_ok( $uri );
test_test( 'Fluffy page should have fluffy errors' );
};
subtest 'Custom tidy ignores fluffy errors' => sub {
plan tests => 4;
my $tidy = HTML::Tidy5->new( { show_warnings => 0 } );
isa_ok( $tidy, 'HTML::Tidy5' );
my $mech = Test::WWW::Mechanize->new( autotidy => $tidy );
isa_ok( $mech, 'Test::WWW::Mechanize' );
my $uri = URI::file->new_abs( 't/fluffy.html' )->as_string;
$mech->get_ok( $uri, 'Fluffy page should not have errors' );
# And if we go to another page, the autolint object has been reset.
$mech->get_ok( $uri, 'Second pass at the fluffy page should not have errors, either' );
};
subtest 'Get good HTML' => sub {
plan tests => 3;
my $mech = Test::WWW::Mechanize->new( autotidy => 1 );
isa_ok( $mech, 'Test::WWW::Mechanize' );
my $uri = URI::file->new_abs( 't/good.html' )->as_string;
$mech->get_ok( $uri );
test_out( "ok 1 - GET $uri" );
$mech->get_ok( $uri, "GET $uri" );
test_test( 'Good GET, good HTML' );
};
subtest 'Get bad HTML' => sub {
plan tests => 3;
my $mech = Test::WWW::Mechanize->new( autotidy => 1 );
isa_ok( $mech, 'Test::WWW::Mechanize' );
my $uri = URI::file->new_abs( 't/bad.html' )->as_string;
# Test via get_ok
test_out( "not ok 1 - GET $uri" );
test_fail( +6 );
test_err( "# HTML::Tidy5 messages for $uri" );
test_err( '# (1:1) Warning: missing declaration' );
test_err( '# (8:33) Warning: discarding unexpected ' );
test_err( '# (8:9) Warning: missing ' );
test_err( '# 3 messages on the page' );
$mech->get_ok( $uri, "GET $uri" );
test_test( 'get_ok complains about bad HTML' );
# Test via follow_link_ok
test_out( 'not ok 1 - Following link back to bad.html' );
test_fail( +6 );
test_err( "# HTML::Tidy5 messages for $uri" );
test_err( '# (1:1) Warning: missing declaration' );
test_err( '# (8:33) Warning: discarding unexpected ' );
test_err( '# (8:9) Warning: missing ' );
test_err( '# 3 messages on the page' );
$mech->follow_link_ok( { text => 'Back to bad' }, 'Following link back to bad.html' );
test_test( 'follow_link_ok complains about bad HTML' );
};
done_testing();
exit 0;
Test-WWW-Mechanize-1.60/t/has_tag.t 0000644 0001750 0001750 00000004602 14343263442 015457 0 ustar andy andy #!perl -T
use strict;
use warnings;
use Test::More tests => 15;
use Test::Builder::Tester;
use URI::file;
use Test::WWW::Mechanize ();
my $mech = Test::WWW::Mechanize->new();
isa_ok($mech,'Test::WWW::Mechanize');
my $uri = URI::file->new_abs( 't/goodlinks.html' )->as_string;
$mech->get_ok( $uri );
test_out( 'ok 1 - looking for "Test" link' );
$mech->has_tag( h1 => 'Test Page', 'looking for "Test" link' );
test_test( 'Handles finding tag by content' );
# default desc
test_out( 'ok 1 - Page has h1 tag with "Test Page"' );
$mech->has_tag( h1 => 'Test Page' );
test_test( 'Handles finding tag by content - default desc' );
test_out( 'not ok 1 - looking for "Quiz" link' );
test_fail( +1 );
$mech->has_tag( h1 => 'Quiz', 'looking for "Quiz" link' );
test_test( 'Handles unfindable tag by content' );
test_out( 'ok 1 - Should have qr/Test 3/i link' );
$mech->has_tag_like( a => qr/Test 3/, 'Should have qr/Test 3/i link' );
test_test( 'Handles finding tag by content regexp' );
test_out( 'not ok 1 - Should be missing qr/goof/i link' );
test_fail( +1 );
$mech->has_tag_like( a => qr/goof/i, 'Should be missing qr/goof/i link' );
test_test( 'Handles unfindable tag by content regexp' );
## nested table tag
my $table_uri = URI::file->new_abs( 't/table.html' )->as_string;
$mech->get_ok( $table_uri );
test_out( 'ok 1 - Page has td tag with "Foobar"' );
$mech->has_tag('td' => 'Foobar' );
test_test( 'Handles finding text in table data tag' );
test_out( 'ok 1 - User company' );
$mech->has_tag('td', 'company', 'User company');
test_test( 'Handles finding text in nested table data tag' );
test_out( 'ok 1 - Page has td tag with "company,email,employee,website"' );
$mech->has_tag('td', 'company,email,employee,website');
test_test( 'Handles finding text in nested table data second tag' );
test_out( 'ok 1 - Page has th tag with "Groups"' );
$mech->has_tag('th', 'Groups');
test_test( 'Handles finding text in nested table header' );
test_out( 'ok 1 - Page has h3 tag with "Show all users and groups"' );
$mech->has_tag('h3', 'Show all users and groups');
test_test( 'Handles finding text in h3 in table' );
test_out( 'ok 1 - Page has p tag with "Its been said:"' );
$mech->has_tag('p', 'Its been said:');
test_test( 'Checks finding text in sub inline element in p' );
test_out( 'ok 1 - Page has p tag with "Hi"');
$mech->has_tag( 'p', 'Hi' );
test_test( 'Finding text in sub inline element in p' );
done_testing();
Test-WWW-Mechanize-1.60/t/headers.t 0000644 0001750 0001750 00000010132 14343270541 015455 0 ustar andy andy #!perl -T
use strict;
use warnings;
use Test::More tests => 26;
use Test::Builder::Tester;
use lib 't';
use TestServer;
my $server = TestServer->new;
my $pid = $server->background;
my $server_root = $server->root;
use Test::WWW::Mechanize ();
my $mech = do {
local @ENV{qw( http_proxy HTTP_PROXY )};
Test::WWW::Mechanize->new( autocheck => 0 );
};
isa_ok($mech,'Test::WWW::Mechanize');
$mech->get_ok( "$server_root/form.html" );
GOOD_EXISTS: {
test_out( 'ok 1 - Has Content-Type' );
my $ok = $mech->header_exists_ok('Content-Type', 'Has Content-Type');
test_test( 'Gets existing header and reports success' );
is( ref($ok), '', 'get_ok() should only return a scalar' );
ok( $ok, 'And the result should be true' );
# default desc
test_out( 'ok 1 - Response has Content-Type header' );
$mech->header_exists_ok('Content-Type');
test_test( 'Gets existing header and reports success - default desc' );
}
BAD_EXISTS: {
test_out( 'not ok 1 - Try to get a bad header' );
test_fail( +1 );
my $ok = $mech->header_exists_ok('Server', 'Try to get a bad header');
test_test( 'Fails to get nonexistent header and reports failure' );
is( ref($ok), '', 'get_ok() should only return a scalar' );
ok( !$ok, 'And the result should be false' );
}
GOOD_LACKS: {
test_out( 'ok 1 - Lacks Bongotronic-X' );
my $ok = $mech->lacks_header_ok( 'Bongotronic-X', 'Lacks Bongotronic-X' );
test_test( 'Gets existing header and reports success' );
is( ref($ok), '', 'get_ok() should only return a scalar' );
ok( $ok, 'And the result should be true' );
test_out( 'ok 1 - Response lacks Bongotronic-X header' );
$mech->lacks_header_ok( 'Bongotronic-X' );
test_test( 'Gives reasonable default to lacks_header_ok' );
}
BAD_LACKS: {
test_out( 'not ok 1 - Hoping Content-Type is missing' );
test_fail( +1 );
my $ok = $mech->lacks_header_ok( 'Content-Type', 'Hoping Content-Type is missing' );
test_test( 'The header we expected to lack is indeed there.' );
is( ref($ok), '', 'get_ok() should only return a scalar' );
ok( !$ok, 'And the result should be false' );
}
GOOD_IS: {
test_out( 'ok 1 - Content-Type is "text/html"' );
my $ok = $mech->header_is('Content-Type', 'text/html', 'Content-Type is "text/html"');
test_test( 'Matches existing header and reports success' );
is( ref($ok), '', 'get_ok() should only return a scalar' );
ok( $ok, 'And the result should be true' );
# default desc
test_out( 'ok 1 - Response has Content-Type header with value "text/html"' );
$mech->header_is('Content-Type', 'text/html');
test_test( 'Matches existing header and reports success - default desc' );
}
BAD_IS: {
test_out( 'not ok 1 - Try to match a nonexistent header' );
test_fail( +2 );
test_diag( 'Header Bongotronic-X does not exist' );
my $ok = $mech->header_is('Bongotronic-X', 'GitHub.com', 'Try to match a nonexistent header');
test_test( 'Fails to match nonexistent header and reports failure' );
is( ref($ok), '', 'get_ok() should only return a scalar' );
ok( !$ok, 'And the result should be false' );
test_out( 'not ok 1 - Content-Type is "text/plain"' );
test_fail( +3 );
test_diag(q( got: 'text/html'));
test_diag(q( expected: 'text/plain'));
$mech->header_is('Content-Type', 'text/plain', 'Content-Type is "text/plain"');
test_test( 'Fails to match header and reports failure' );
}
GOOD_LIKE: {
test_out( 'ok 1 - Content-Type matches /^text\\/html$/' );
$mech->header_like('Content-Type', qr/^text\/html$/, 'Content-Type matches /^text\\/html$/');
test_test( 'Matches existing header and reports success - regex' );
}
BAD_LIKE: {
my $pattern = qr{^text/plain$};
test_out( 'not ok 1 - Content-Type matches /^text\\/plain$/' );
test_fail( +3 );
test_diag( q( 'text/html'));
test_diag(qq( doesn't match '$pattern'));
$mech->header_like('Content-Type', $pattern, 'Content-Type matches /^text\\/plain$/');
test_test( 'Fails to match header and reports failure - regex' );
}
$server->stop;
done_testing();
Test-WWW-Mechanize-1.60/t/post_ok.t 0000644 0001750 0001750 00000000730 14343270541 015523 0 ustar andy andy #!perl -T
use strict;
use warnings;
use Test::More tests => 2;
use Test::Builder::Tester;
use Test::WWW::Mechanize ();
my $mech = Test::WWW::Mechanize->new( autocheck => 0 );
isa_ok($mech,'Test::WWW::Mechanize');
UNDEF_URL: {
test_out( 'not ok 1 - Passing undef for a URL' );
test_fail( +2 );
test_diag( 'URL cannot be undef.' );
my $ok = $mech->post_ok( undef, 'Passing undef for a URL' );
test_test( 'Undef URLs' );
}
done_testing();
exit 0;
Test-WWW-Mechanize-1.60/t/lacks_uncapped_inputs.t 0000644 0001750 0001750 00000002237 14343263442 020431 0 ustar andy andy #!perl -T
use strict;
use warnings;
use Test::More tests => 5;
use Test::Builder::Tester;
use URI::file;
use Test::WWW::Mechanize ();
my $mech = Test::WWW::Mechanize->new();
isa_ok( $mech,'Test::WWW::Mechanize' );
GOOD: {
my $uri = URI::file->new_abs( 't/lacks_uncapped_inputs-good.html' )->as_string;
$mech->get_ok( $uri ) or die;
test_out( 'ok 1 - This should have no failures' );
$mech->lacks_uncapped_inputs( 'This should have no failures' );
test_test( 'Finds the lacks' );
}
BAD: {
my $uri = URI::file->new_abs( 't/lacks_uncapped_inputs-bad.html' )->as_string;
$mech->get_ok( $uri ) or die;
test_out( 'not ok 1 - This should have three errors found' );
test_fail( +6 );
test_diag( q{foo has no maxlength attribute} );
test_diag( q{quux has an invalid maxlength attribute of "dogs"} );
test_diag( q{crunchy has an invalid maxlength attribute of "-1"} );
test_diag( q{bingo has an invalid maxlength attribute of ""} );
test_diag( q{bongo has an invalid maxlength attribute of " "} );
$mech->lacks_uncapped_inputs( 'This should have three errors found' );
test_test( 'Detect uncapped' );
}
done_testing();
Test-WWW-Mechanize-1.60/t/id_exists.t 0000644 0001750 0001750 00000002621 14343263442 016043 0 ustar andy andy #!perl -T
use strict;
use warnings;
use Test::More tests => 23;
use Test::Builder::Tester;
use Test::WWW::Mechanize ();
use URI::file ();
my @valid_ids = ( 'user-block', 'name', 'address' );
my @invalid_ids = ( 'bingo', 'bongo' );
my $mech = Test::WWW::Mechanize->new();
isa_ok( $mech,'Test::WWW::Mechanize' );
my $uri = URI::file->new_abs( 't/id_exists.html' )->as_string;
$mech->get_ok( $uri );
for my $id ( @valid_ids ) {
ok( $mech->id_exists( $id ), "$id found" );
$mech->id_exists_ok( $id );
$mech->ids_exist_ok( [$id] );
}
for my $id ( @invalid_ids ) {
ok( !$mech->id_exists( $id ), "$id not found" );
$mech->lacks_id_ok( $id );
$mech->lacks_ids_ok( [$id] );
}
$mech->ids_exist_ok( [@valid_ids], 'Valid IDs found' );
$mech->lacks_ids_ok( [@invalid_ids], 'Valid IDs found' );
# Now test output specifics.
# id_exists_ok
test_out( 'not ok 1 - ID "bongo" should exist' );
test_fail( +1 );
$mech->id_exists_ok( 'bongo' );
test_test( 'Proper id_exists_ok results for nonexistent ID' );
# lacks_id_ok
test_out( 'not ok 1 - ID "name" should not exist' );
test_fail( +1 );
$mech->lacks_id_ok( 'name' );
test_test( 'Proper lacks_id_ok results for ID that is there' );
# Now go get a new page and do tests again.
$mech->update_html( '
Very boring page
id_exists_ok( 'boring' );
$mech->lacks_ids_ok( [@valid_ids, @invalid_ids] );
exit 0
Test-WWW-Mechanize-1.60/t/lacks_uncapped_inputs-good.html 0000644 0001750 0001750 00000000534 14343263442 022056 0 ustar andy andy
Title
Test-WWW-Mechanize-1.60/t/stuff_inputs.html 0000644 0001750 0001750 00000000127 14343263442 017301 0 ustar andy andy
Title
Test-WWW-Mechanize-1.60/t/autolint.t 0000644 0001750 0001750 00000011146 14343263442 015711 0 ustar andy andy #!/usr/bin/env perl -T
use strict;
use warnings;
use Test::Builder::Tester;
use Test::More;
use URI::file;
use Test::WWW::Mechanize;
BEGIN {
my $module = 'HTML::Lint 2.20';
# Load HTML::Lint here for the imports
if ( not eval "use $module; 1;" ) {
plan skip_all => "$module is not installed, cannot test autolint";
}
plan tests => 27;
}
ACCESSOR_MUTATOR: {
my $lint = HTML::Lint->new( only_types => HTML::Lint::Error::STRUCTURE );
ACCESSOR: {
my $mech = Test::WWW::Mechanize->new();
ok( !$mech->autolint(), 'no autolint to new yields autolint off' );
$mech = Test::WWW::Mechanize->new( autolint => undef );
ok( !$mech->autolint(), 'undef to new yields autolint off' );
$mech = Test::WWW::Mechanize->new( autolint => 0 );
ok( !$mech->autolint(), '0 to new yields autolint off' );
$mech = Test::WWW::Mechanize->new( autolint => 1 );
ok( $mech->autolint(), '1 to new yields autolint on' );
$mech = Test::WWW::Mechanize->new( autolint => [] );
ok( $mech->autolint(), 'non-false, non-object to new yields autolint on' );
$mech = Test::WWW::Mechanize->new( autolint => $lint );
ok( $mech->autolint(), 'HTML::Lint object to new yields autolint on' );
}
MUTATOR: {
my $mech = Test::WWW::Mechanize->new();
ok( !$mech->autolint(0), '0 returns autolint off' );
ok( !$mech->autolint(), '0 autolint really off' );
ok( !$mech->autolint(''), '"" returns autolint off' );
ok( !$mech->autolint(), '"" autolint really off' );
ok( !$mech->autolint(1), '1 returns autolint off (prior state)' );
ok( $mech->autolint(), '1 autolint really on' );
ok( $mech->autolint($lint), 'HTML::Lint object returns autolint on (prior state)' );
ok( $mech->autolint(), 'HTML::Lint object autolint really on' );
my $ret = $mech->autolint( 0 );
isa_ok( $ret, 'HTML::Lint' );
ok( !$mech->autolint(), 'autolint off after nuking HTML::Lint object' );
}
}
FLUFFY_PAGE_HAS_ERRORS: {
my $mech = Test::WWW::Mechanize->new( autolint => 1 );
isa_ok( $mech, 'Test::WWW::Mechanize' );
my $uri = URI::file->new_abs( 't/fluffy.html' )->as_string;
test_out( "not ok 1 - GET $uri" );
test_fail( +5 );
test_err( "# HTML::Lint errors for $uri" );
test_err( '# (10:9) tag has no HEIGHT and WIDTH attributes' );
test_err( '# (10:9) does not have ALT text defined' );
test_err( '# 2 errors on the page' );
$mech->get_ok( $uri );
test_test( 'Fluffy page should have fluffy errors' );
}
CUSTOM_LINTER_IGNORES_FLUFFY_ERRORS: {
my $lint = HTML::Lint->new( only_types => HTML::Lint::Error::STRUCTURE );
my $mech = Test::WWW::Mechanize->new( autolint => $lint );
isa_ok( $mech, 'Test::WWW::Mechanize' );
my $uri = URI::file->new_abs( 't/fluffy.html' )->as_string;
$mech->get_ok( $uri, 'Fluffy page should not have errors' );
# And if we go to another page, the autolint object has been reset.
$mech->get_ok( $uri, 'Second pass at the fluffy page should not have errors, either' );
}
GOOD_GET_GOOD_HTML: {
my $mech = Test::WWW::Mechanize->new( autolint => 1 );
isa_ok( $mech, 'Test::WWW::Mechanize' );
my $uri = URI::file->new_abs( 't/good.html' )->as_string;
$mech->get_ok( $uri );
test_out( "ok 1 - GET $uri" );
$mech->get_ok( $uri, "GET $uri" );
test_test( 'Good GET, good HTML' );
}
GOOD_GET_BAD_HTML: {
my $mech = Test::WWW::Mechanize->new( autolint => 1 );
isa_ok( $mech, 'Test::WWW::Mechanize' );
my $uri = URI::file->new_abs( 't/bad.html' )->as_string;
# Test via get_ok
test_out( "not ok 1 - GET $uri" );
test_fail( +6 );
test_err( "# HTML::Lint errors for $uri" );
test_err( '# (7:9) Unknown attribute "hrex" for tag ' );
test_err( '# (8:33) with no opening ' );
test_err( '# (9:5) at (8:9) is never closed' );
test_err( '# 3 errors on the page' );
$mech->get_ok( $uri, "GET $uri" );
test_test( 'get_ok complains about bad HTML' );
# Test via follow_link_ok
test_out( 'not ok 1 - Following link back to bad.html' );
test_fail( +6 );
test_err( "# HTML::Lint errors for $uri" );
test_err( '# (7:9) Unknown attribute "hrex" for tag ' );
test_err( '# (8:33) with no opening ' );
test_err( '# (9:5) at (8:9) is never closed' );
test_err( '# 3 errors on the page' );
$mech->follow_link_ok( { text => 'Back to bad' }, 'Following link back to bad.html' );
test_test( 'follow_link_ok complains about bad HTML' );
}
done_testing();
Test-WWW-Mechanize-1.60/t/good.html 0000644 0001750 0001750 00000000320 14343263442 015473 0 ustar andy andy
Test Page
Test Page
goodTest
Test-WWW-Mechanize-1.60/t/stuff_inputs.t 0000644 0001750 0001750 00000011164 14343263442 016603 0 ustar andy andy #!perl -T
use strict;
use warnings;
use Test::More tests => 43;
use URI::file;
use Test::WWW::Mechanize ();
MAIN: {
my $mech = Test::WWW::Mechanize->new();
my $uri = URI::file->new_abs( 't/stuff_inputs.html' )->as_string;
EMPTY_FIELDS: {
$mech->get_ok( $uri ) or die;
add_test_fields( $mech );
$mech->stuff_inputs();
field_checks(
$mech, {
text0 => '',
text1 => '@',
text10 => '@' x 10,
text70k => '@' x 70_000,
textunlimited => '@' x 66_000,
textarea => '@' x 66_000,
},
'filling empty fields'
);
}
MULTICHAR_FILL: {
$mech->get_ok( $uri ) or die;
add_test_fields( $mech );
$mech->stuff_inputs( { fill => '123' } );
field_checks(
$mech, {
text0 => '',
text1 => '1',
text10 => '1231231231',
text70k => ('123' x 23_333) . '1',
textunlimited => '123' x 22_000,
textarea => '123' x 22_000,
},
'multichar_fill'
);
}
OVERWRITE: {
$mech->get_ok( $uri ) or die;
add_test_fields( $mech );
$mech->stuff_inputs();
is( $mech->value('text10'), '@' x 10, 'overwriting fields: initial fill as expected' );
$mech->stuff_inputs( { fill => 'X' } );
field_checks(
$mech, {
text0 => '',
text1 => 'X',
text10 => 'X' x 10,
text70k => 'X' x 70_000,
textunlimited => 'X' x 66_000,
textarea => 'X' x 66_000,
},
'overwriting fields'
);
}
CUSTOM_FILL: {
$mech->get_ok( $uri ) or die;
add_test_fields( $mech );
$mech->stuff_inputs( {
fill => 'z',
specs => {
text10 => { fill=>'#' },
textarea => { fill=>'*' },
}
} );
field_checks(
$mech, {
text0 => '',
text1 => 'z',
text10 => '#' x 10,
text70k => 'z' x 70_000,
textunlimited => 'z' x 66_000,
textarea => '*' x 66_000,
},
'custom fill'
);
}
MAXLENGTH: {
$mech->get_ok( $uri ) or die;
add_test_fields( $mech );
$mech->stuff_inputs( {
specs => {
text10 => { maxlength=>7 },
textarea => { fill=>'*', maxlength=>9 },
}
}
);
field_checks(
$mech, {
text0 => '',
text1 => '@',
text10 => '@' x 7,
text70k => '@' x 70_000,
textunlimited => '@' x 66_000,
textarea => '*' x 9,
},
'maxlength'
);
}
IGNORE: {
$mech->get_ok( $uri ) or die;
add_test_fields( $mech );
$mech->stuff_inputs( { ignore => [ 'text10' ] } );
field_checks(
$mech, {
text0 => '',
text1 => '@',
text10 => undef,
text70k => '@' x 70_000,
textunlimited => '@' x 66_000,
textarea => '@' x 66_000,
},
'ignore'
);
}
}
done_testing();
sub add_test_fields {
my $mech = shift;
HTML::Form::Input->new( type=>'text', name=>'text0', maxlength=>0 )->add_to_form( $mech->current_form() );
HTML::Form::Input->new( type=>'text', name=>'text1', maxlength=>1 )->add_to_form( $mech->current_form() );
HTML::Form::Input->new( type=>'text', name=>'text10', maxlength=>10 )->add_to_form( $mech->current_form() );
HTML::Form::Input->new( type=>'text', name=>'text70k', maxlength=>70_000 )->add_to_form( $mech->current_form() );
HTML::Form::Input->new( type=>'text', name=>'textunlimited' )->add_to_form( $mech->current_form() );
HTML::Form::Input->new( type=>'textarea', name=>'textarea' )->add_to_form( $mech->current_form() );
return;
}
sub field_checks {
my $mech = shift;
my $expected = shift;
my $desc = shift;
foreach my $key ( qw( text0 text1 text10 text70k textunlimited textarea ) ) {
is( $mech->value($key), $expected->{$key}, "$desc: field $key" );
}
return;
}
Test-WWW-Mechanize-1.60/t/table.html 0000644 0001750 0001750 00000001316 14343263442 015640 0 ustar andy andy
nested table for mech
Show all users and groups
User
Groups
company
company,email,employee,website
Foobar
Its been said: so it was
Hi bye Hi
Test-WWW-Mechanize-1.60/t/put_ok.t 0000644 0001750 0001750 00000002550 14343270541 015350 0 ustar andy andy #!perl -T
use strict;
use warnings;
use Test::More tests => 8;
use Test::Builder::Tester;
use Test::WWW::Mechanize ();
use lib 't';
use TestServer;
my $server = TestServer->new;
my $pid = $server->background;
my $server_root = $server->root;
my $text = 'This is what we are putting';
GOOD_PUT: {
local @ENV{qw( http_proxy HTTP_PROXY )};
my $mech = Test::WWW::Mechanize->new( autocheck => 0 );
isa_ok($mech,'Test::WWW::Mechanize');
my $scratch = "$server_root/scratch.html";
$mech->put_ok($scratch, {content => $text});
ok($mech->success, 'sanity check: we can load scratch.html');
test_out('ok 1 - Try to PUT scratch.html');
my $ok = $mech->put_ok($scratch, 'Try to PUT scratch.html');
test_test('PUTs existing URI and reports success');
is( ref($ok), '', 'put_ok() should only return a scalar' );
ok( $ok, 'And the result should be true' );
# default desc
test_out("ok 1 - PUT $scratch");
$mech->put_ok($scratch);
test_test('PUTs existing URI and reports success - default desc');
}
UNDEF_URL: {
my $mech = Test::WWW::Mechanize->new();
test_out( 'not ok 1 - Passing undef for a URL' );
test_fail( +2 );
test_diag( 'URL cannot be undef.' );
my $ok = $mech->put_ok( undef, 'Passing undef for a URL' );
test_test( 'Undef URLs' );
}
$server->stop;
done_testing();
exit 0;
Test-WWW-Mechanize-1.60/t/content_lacks.t 0000644 0001750 0001750 00000002420 14343263442 016674 0 ustar andy andy #!perl -T
use strict;
use warnings;
use Test::More tests => 5;
use Test::Builder::Tester;
use URI::file;
use Test::WWW::Mechanize ();
my $mech=Test::WWW::Mechanize->new();
isa_ok($mech,'Test::WWW::Mechanize');
my $uri = URI::file->new_abs( 't/goodlinks.html' )->as_string;
$mech->get_ok( $uri );
# test regex
test_out( 'ok 1 - Does it say Mungo eats cheese?' );
$mech->content_lacks( 'Mungo eats cheese', 'Does it say Mungo eats cheese?' );
test_test( 'Finds the lacks' );
# default desc
test_out( 'ok 1 - Content lacks "Mungo eats cheese"' );
$mech->content_lacks( 'Mungo eats cheese');
test_test( 'Finds the lacks - default desc' );
test_out( q{not ok 1 - Shouldn't say it's a test page} );
test_fail(+11);
if ( $^O eq 'MSWin32' ) {
test_diag(q( searched: "\x{0d}\x{0a} \x{0d}\x{0a} Test Page\x{0a} \x{0a} Test Page"...) );
test_diag(q( and found: "Test Page") );
test_diag(q( at position: 33 (line 3 column 16)) );
}
$mech->content_lacks( 'Test Page', q{Shouldn't say it's a test page} );
test_test( 'Handles not finding it' );
done_testing();
Test-WWW-Mechanize-1.60/t/goodlinks.html 0000644 0001750 0001750 00000000375 14343263442 016546 0 ustar andy andy
Test Page
Test Page
Test 1Test 2Test 3
Test-WWW-Mechanize-1.60/t/followable_links.t 0000644 0001750 0001750 00000001271 14343263442 017376 0 ustar andy andy #!perl -T
use strict;
use warnings;
use Test::More tests => 3;
use URI::file;
use Test::WWW::Mechanize ();
my $mech = Test::WWW::Mechanize->new();
isa_ok($mech,'Test::WWW::Mechanize');
my $uri = URI::file->new_abs( 't/manylinks.html' )->as_string;
$mech->get_ok( $uri );
# Good links.
my @links = $mech->followable_links();
@links = map { $_->url_abs } @links;
my @expected = (
URI::file->new_abs( 't/goodlinks.html' )->as_string,
'http://bongo.com/wang.html',
'https://secure.bongo.com/',
URI::file->new_abs( 't/badlinks.html' )->as_string,
URI::file->new_abs( 't/goodlinks.html' )->as_string,
);
is_deeply( \@links, \@expected, 'Got the right links' );
done_testing();
Test-WWW-Mechanize-1.60/t/get_ok.t 0000644 0001750 0001750 00000003242 14343270541 015316 0 ustar andy andy #!perl -T
use strict;
use warnings;
use Test::More tests => 11;
use Test::Builder::Tester;
use URI::file ();
use Test::WWW::Mechanize ();
my $mech = Test::WWW::Mechanize->new( autocheck => 0 );
isa_ok($mech,'Test::WWW::Mechanize');
GOOD_GET: {
my $goodlinks = URI::file->new_abs( 't/goodlinks.html' )->as_string;
$mech->get_ok($goodlinks);
test_out('ok 1 - Try to get goodlinks.html');
my $ok = $mech->get_ok($goodlinks, 'Try to get goodlinks.html');
test_test('Gets existing URI and reports success');
is( ref($ok), '', 'get_ok() should only return a scalar' );
ok( $ok, 'And the result should be true' );
# default desc
test_out("ok 1 - GET $goodlinks");
$mech->get_ok($goodlinks);
test_test('Gets existing URI and reports success - default desc');
}
BAD_GET: {
my $badurl = URI::file->new_abs('t/no-such-file');
my $abs_path = $badurl->file;
$mech->get( $badurl->as_string );
ok(!$mech->success, qq{sanity check: we can't load $badurl});
test_out( 'not ok 1 - Try to get bad URL' );
test_fail( +4 );
test_diag( $badurl );
test_diag( '404' );
test_diag( qq{File `$abs_path' does not exist} );
my $ok = $mech->get_ok( $badurl->as_string, 'Try to get bad URL' );
test_test( 'Fails to get nonexistent URI and reports failure' );
is( ref($ok), '', 'get_ok() should only return a scalar' );
ok( !$ok, 'And the result should be false' );
}
UNDEF_URL: {
test_out( 'not ok 1 - Passing undef for a URL' );
test_fail( +2 );
test_diag( 'URL cannot be undef.' );
my $ok = $mech->get_ok( undef, 'Passing undef for a URL' );
test_test( 'Undef URLs' );
}
done_testing();
exit 0;
Test-WWW-Mechanize-1.60/t/new.t 0000644 0001750 0001750 00000001516 14343263442 014643 0 ustar andy andy #!perl -T
use warnings;
use strict;
use Test::More tests => 2;
use Test::WWW::Mechanize ();
subtest 'basic new' => sub {
my $mech = Test::WWW::Mechanize->new;
isa_ok( $mech, 'Test::WWW::Mechanize' );
};
# Stolen from WWW::Mechanize's t/new.t.
# If this works, then subclassing works OK.
subtest 'constructor parms' => sub {
my $alias = 'Windows IE 6';
my $mech = Test::WWW::Mechanize->new( agent => $alias );
isa_ok( $mech, 'Test::WWW::Mechanize' );
can_ok( $mech, 'request' );
is( $mech->agent, $alias, q{Aliases don't get translated in the constructor} );
$mech->agent_alias( $alias );
like( $mech->agent, qr/^Mozilla.+compatible.+Windows/, 'Alias sets the agent' );
$mech->agent( 'ratso/bongo v.43' );
is( $mech->agent, 'ratso/bongo v.43', 'Can still set the agent' );
};
done_testing();
Test-WWW-Mechanize-1.60/t/link_content.t 0000644 0001750 0001750 00000004671 14343263442 016546 0 ustar andy andy #!perl -T
use strict;
use warnings;
use Test::More tests => 11;
use Test::Builder::Tester;
use URI::file;
use Test::WWW::Mechanize;
my $mech=Test::WWW::Mechanize->new();
isa_ok($mech,'Test::WWW::Mechanize');
my $uri = URI::file->new_abs( 't/goodlinks.html' )->as_string;
$mech->get_ok( $uri );
my @urls = $mech->links();
is( scalar @urls, 3, 'Got links from the HTTP server');
# test regex
test_out('not ok 1 - link_content_like');
test_fail(+2);
test_diag(q{ "blah" doesn't look much like a regex to me.});
$mech->link_content_like(\@urls,'blah','Testing the regex');
test_test('Handles bad regexs');
# like
test_out('ok 1 - Checking all page links contain: Test');
$mech->link_content_like(\@urls,qr/Test/,'Checking all page links contain: Test');
test_test('Handles All page links contents successful');
# like - default desc
my $re_string = ($] < 5.014) ? '(?-xism:Test)' : '(?^:Test)';
test_out('ok 1 - ' . scalar(@urls) . qq{ links are like "$re_string"} );
$mech->link_content_like(\@urls,qr/Test/);
test_test('Handles All page links contents successful - default desc');
test_out('not ok 1 - Checking all page link content failures');
test_fail(+4);
test_diag('goodlinks.html');
test_diag('badlinks.html');
test_diag('goodlinks.html');
$mech->link_content_like(\@urls,qr/BadTest/,'Checking all page link content failures');
test_test('Handles link content not found');
# unlike
# test regex
test_out('not ok 1 - link_content_unlike');
test_fail(+2);
test_diag(q{ "blah" doesn't look much like a regex to me.});
$mech->link_content_unlike(\@urls,'blah','Testing the regex');
test_test('Handles bad regexs');
test_out('ok 1 - Checking all page links do not contain: BadTest');
$mech->link_content_unlike(\@urls,qr/BadTest/,'Checking all page links do not contain: BadTest');
test_test('Handles All page links unlike contents successful');
# unlike - default desc
$re_string = ($] < 5.014) ? '(?-xism:BadTest)' : '(?^:BadTest)';
test_out('ok 1 - ' . scalar(@urls) . qq{ links are not like "$re_string"});
$mech->link_content_unlike(\@urls,qr/BadTest/);
test_test('Handles All page links unlike contents successful - default desc');
test_out('not ok 1 - Checking all page link unlike content failures');
test_fail(+4);
test_diag('goodlinks.html');
test_diag('badlinks.html');
test_diag('goodlinks.html');
$mech->link_content_unlike(\@urls,qr/Test/,'Checking all page link unlike content failures');
test_test('Handles link unlike content found');
done_testing();
Test-WWW-Mechanize-1.60/Changes 0000644 0001750 0001750 00000035333 14343270541 014717 0 ustar andy andy Revision history for Test-WWW-Mechanize
WWW::Mechanize and Test::WWW::Mechanize do not use rt.cpan.org for
bug tracking. They are now being tracked via GitHub at
https://github.com/petdance/test-www-mechanize/issues
1.60 Sun Dec 4 10:18:28 PM CST 2022
------------------------------------
[ENHANCMENTS]
Added default test messages for button_exists_ok and lacks_button_ok
methods. Thanks, Daniel Böhmer (GH#70)
get_ok(), post_ok(), head_ok(), put_ok() and delete_ok() now all fail
if an undef URL is passed, rather than passing the undef URL into the
underlying LWP functions. Thanks, Jess Robinson. (GH #40)
[FIXES]
Disable proxies in some of the tests that look at a local test server.
(GH#55, GH#74)
[DOCUMENTATION]
Clarified some wording. Thanks, Daniel Böhmer (GH#70)
1.58 Fri Apr 29 11:23:39 CDT 2022
------------------------------------
[ENHANCEMENTS]
Failed get_ok, post_ok, head_ok, put_ok, delete_ok calls now show the URL
as a diagnostic if there's a problem accessing the URL. This apply to
functions like submit_form_ok() and follow_link_ok() that are wrappers
around these methods.
1.56 Tue Apr 26 22:14:12 CDT 2022
------------------------------------
This version of Test::WWW::Mechanize requires Perl 5.10.
[ENHANCEMENTS]
Add check_all_images_ok(). (GH #17) Thanks, Julien Fiegehenn.
This is the first version of this function, and its functionality may
change in the near future.
[DOCUMENTATION]
Fixed some incorrect docs. Thanks, Daniel Böhmer.
[INTERNALS]
Require Perl 5.10.
Explicitly requires HTTP::Message 6.29 or higher.
1.54 Tue Dec 8 23:25:06 CST 2020
------------------------------------
[ENHANCEMENTS]
Use ok() instead of cmp_ok() inside of lacks_uncapped_inputs().
This output makes more sense.
lacks_uncapped_inputs() now has a a default message if one isn't supplied.
[FIXES]
Fixed the subtest name inside of C.
Fixed the minimum version of Carp::Assert::More in Makefile.PL.
1.52 Wed Dec 5 10:00:56 CST 2018
------------------------------------
[ENHANCEMENTS]
click_ok() method can now take a button with X/Y coordinates.
Thanks to GitHub user @marderh. (GH #45)
Added the ability to modify the HTML that the html_tidy_ok() validates.
See the content_for_validation() method. (GH #61)
Add a set of methods for existence of IDs: id_exists(), id_exists_ok(),
ids_exist_ok(), lacks_id_ok() and lacks_ids_ok(). (GH #48)
Add button_exists(), button_exists_ok() and lacks_button_ok()
methods. (GH #50)
[FIXES]
Clarified warnings to make it clear that certain modules are
optional. Thanks, Matthew Chae.
1.50 Mon Apr 16 15:16:59 CDT 2018
------------------------------------
[FIXES]
Added html_tidy_ok() methods, analogous to html_lint_ok().
Remove unnecessary dependency on HTML::TreeBuilder. Thanks, Kent Fredric.
1.49_01 Mon Mar 26 10:58:51 CDT 2018
------------------------------------
[ENHANCEMENTS]
Adding autotidy functionality. autotidy lets you validate every page that
Mech gets using the HTML::Tidy5 module, just like the autolint feature
does with the HTML::Lint module. HTML::Tidy5 is a much more complete
HTML checking tool, and validates HTML5 which HTML::Lint does not. You
must have HTML::Tidy5 1.00 installed to use autotidy.
1.48 Thu Dec 29 22:45:29 CST 2016
------------------------------------
[FIXES]
The linting method html_lint_ok() was not calling the HTML::Lint API
correctly, so may have missed some HTML errors at the end of a page.
This also applies to get, post, etc if you have the autolint argument on.
1.46
------------------------------------
[ENHANCEMENTS]
Added header_exists_ok(), lacks_header(), header_is() and header_like()
methods. Thanks to Eric A. Zarko for the original patches.
The scraped_id_is() method used to assign a description for the test if
one was not passed. Now it does not.
scraped_id_is() now gives proper diagnostics if an ID is not found in
the HTML.
Added a delete_ok() method. Thanks, moznion.
content_contains() now fails if it's called with a regex. content_like()
now fails if it's not called with a regex.
[FIXES]
The test server run during the test suite allowed URLs outside of the
document tree, which could potentially be a security problem. This has
been fixed. Thanks, Tynovsky.
https://github.com/petdance/test-www-mechanize/issues/33
Fixed an overly-restrictive optimization in scrape_text_by_id(), plus
scraped_id_is() and scraped_id_like() which wrap it.
The method checks to make sure that it doesn't bother looking for an ID
on the page if the ID doesn't exist. It did this by looking for the text
id="foo"
where foo is the ID being searched for. However, that would mean that
tags like
would be seen as not existing. This has been fixed by making
scrape_text_by_id() search for the string "foo" anywhere on the page.
1.44 Sat Jun 30 20:32:04 CDT 2012
------------------------------------
There is no new functionality in this release.
[FIXES]
Fixed test failures on Win32. Thanks, Jerry Gay.
1.42 Thu May 31 11:35:26 CDT 2012
------------------------------------
If you want to use the autolint functionality, you'll have to have
HTML::Lint 2.20.
[FIXES]
Custom lint objects don't get reset before they get used, making
autolint with a custom lint object practically useless.
https://github.com/petdance/test-www-mechanize/issues/25
1.40 Fri Apr 13 15:14:39 CDT 2012
------------------------------------
[ENHANCEMENTS]
Added a $mech->autolint() method so you can turn autolinting on and off
in mid-program. Thanks, Mike O'Regan.
New functions $mech->scrape_text_by_id() and $mech->scrape_text_by_attr()
let you extract text from your pages. Convenience function
$mech->scraped_id_is() makes it easy to scrape and compare in one
function.