Debian lenny version packages
[pkg-perl] / deb-src / libwww-mechanize-perl / libwww-mechanize-perl-1.34 / t / link.t
1 #!perl -Tw
2
3 use warnings;
4 use strict;
5
6 use Test::More tests=>23;
7
8 BEGIN {
9     use_ok( 'WWW::Mechanize::Link' );
10 }
11
12 OLD_API: {
13     my $link =
14         WWW::Mechanize::Link->new(
15             'url.html', 'text', 'name', 'frame', 'http://base.example.com/', { alt => 'alt text' } );
16
17     isa_ok( $link, 'WWW::Mechanize::Link' );
18     is( scalar @$link, 6, 'Should have five elements' );
19
20     # Test the new-style accessors
21     is( $link->url, 'url.html', 'url() works' );
22     is( $link->text, 'text', 'text() works' );
23     is( $link->name, 'name', 'name() works' );
24     is( $link->tag, 'frame', 'tag() works' );
25     is( $link->base, 'http://base.example.com/', 'base() works' );
26     is( $link->attrs->{alt}, 'alt text', 'attrs() works' );
27
28     # Order of the parms in the blessed array is important for backwards compatibility.
29     is( $link->[0], 'url.html', 'parm 0 is url' );
30     is( $link->[1], 'text', 'parm 1 is text' );
31     is( $link->[2], 'name', 'parm 2 is name' );
32     is( $link->[3], 'frame', 'parm 3 is tag' );
33     is( $link->[4], 'http://base.example.com/', 'parm 4 is base' );
34
35     my $URI = $link->URI;
36     isa_ok( $URI, 'URI::URL', 'URI is proper type' );
37     is( $URI->rel, 'url.html', 'Short form of the url' );
38     is( $link->url_abs, 'http://base.example.com/url.html', 'url_abs works' );
39 }
40
41 NEW_API: {
42     # test new style API
43     my $link = WWW::Mechanize::Link->new( {
44         url  => 'url.html',
45         text => 'text',
46         name => 'name',
47         tag  => 'frame',
48         base => 'http://base.example.com/',
49         attrs => { alt =>  'alt text' },
50     } );
51
52     is( $link->url, 'url.html', 'url() works' );
53     is( $link->text, 'text', 'text() works' );
54     is( $link->name, 'name', 'name() works' );
55     is( $link->tag, 'frame', 'tag() works' );
56     is( $link->base, 'http://base.example.com/', 'base() works' );
57     is( $link->attrs->{alt}, 'alt text', 'attrs() works' );
58 }