File: follow_link_ok.t

package info (click to toggle)
libtest-www-mechanize-perl 1.48-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 336 kB
  • ctags: 70
  • sloc: perl: 2,145; makefile: 4
file content (40 lines) | stat: -rw-r--r-- 1,098 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!perl -T

use strict;
use warnings;

use Test::More tests => 6;
use Test::Builder::Tester;
use URI::file ();

use Test::WWW::Mechanize ();

FOLLOW_GOOD_LINK: {
    my $mech = Test::WWW::Mechanize->new( autocheck => 0 );
    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 - Go after first link' );
    $mech->follow_link_ok( {n=>1}, 'Go after first link' );
    test_test( 'Handles good links' );
}

FOLLOW_BAD_LINK: {
    my $mech = Test::WWW::Mechanize->new( autocheck => 0 );
    isa_ok( $mech, 'Test::WWW::Mechanize' );

    my $uri = URI::file->new_abs( 't/badlinks.html' );
    my $path = $uri->file;
    $path =~ s{\Qbadlinks.html}{bad1.html};

    $mech->get_ok( $uri->as_string );
    test_out('not ok 1 - Go after bad link');
    test_fail(+3);
    test_diag( 404 ); # XXX Who is printing this 404, and should it be?
    test_diag( qq{File `$path' does not exist} );
    $mech->follow_link_ok( {n=>2}, 'Go after bad link' );
    test_test('Handles bad links');
}

done_testing();