File: link.t

package info (click to toggle)
libwww-mechanize-perl 2.03-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 988 kB
  • sloc: perl: 4,088; makefile: 6
file content (58 lines) | stat: -rw-r--r-- 1,905 bytes parent folder | download
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 -T

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 params in the blessed array is important for backwards compatibility.
    is( $link->[0], 'url.html', 'param 0 is url' );
    is( $link->[1], 'text', 'param 1 is text' );
    is( $link->[2], 'name', 'param 2 is name' );
    is( $link->[3], 'frame', 'param 3 is tag' );
    is( $link->[4], 'http://base.example.com/', 'param 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' );
}