File: link.t

package info (click to toggle)
libwww-mechanize-perl 1.18-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 488 kB
  • ctags: 109
  • sloc: perl: 2,315; makefile: 39
file content (58 lines) | stat: -rw-r--r-- 1,900 bytes parent folder | download | duplicates (2)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!perl -Tw

use warnings;
use strict;

use Test::More tests=>23;

BEGIN {
    use_ok( 'WWW::Mechanize::Link' );
}

OLD_API: {
    my $link =
        WWW::Mechanize::Link->new(
            "url.html", "text", "name", "frame", "http://base.example.com/", { alt => 'alt text' } );

    isa_ok( $link, 'WWW::Mechanize::Link' );
    is( scalar @$link, 6, "Should have five elements" );

    # Test the new-style accessors
    is( $link->url, "url.html", "url() works" );
    is( $link->text, "text", "text() works" );
    is( $link->name, "name", "name() works" );
    is( $link->tag, "frame", "tag() works" );
    is( $link->base, "http://base.example.com/", "base() works" );
    is( $link->attrs->{alt}, "alt text", "attrs() works" );

    # Order of the parms in the blessed array is important for backwards compatibility.
    is( $link->[0], 'url.html', 'parm 0 is url' );
    is( $link->[1], 'text', 'parm 1 is text' );
    is( $link->[2], 'name', 'parm 2 is name' );
    is( $link->[3], 'frame', 'parm 3 is tag' );
    is( $link->[4], 'http://base.example.com/', 'parm 4 is base' );

    my $URI = $link->URI;
    isa_ok( $URI, "URI::URL", "URI is proper type" );
    is( $URI->rel, "url.html", "Short form of the url" );
    is( $link->url_abs, "http://base.example.com/url.html", "url_abs works" );
}

NEW_API: {
    # test new style API
    my $link = WWW::Mechanize::Link->new( {
        url  => 'url.html',
        text => "text",
        name => "name",
        tag  => "frame",
        base => "http://base.example.com/",
        attrs => { alt =>  "alt text" },
    } );

    is( $link->url, "url.html", "url() works" );
    is( $link->text, "text", "text() works" );
    is( $link->name, "name", "name() works" );
    is( $link->tag, "frame", "tag() works" );
    is( $link->base, "http://base.example.com/", "base() works" );
    is( $link->attrs->{alt}, "alt text", "attrs() works" );
}