File: image-new.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 (46 lines) | stat: -rw-r--r-- 1,272 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
#!perl -T

use warnings;
use strict;

use Test::More tests => 15;

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

# test new style API
my $img = WWW::Mechanize::Image->new( {
    url  => 'url.html',
    base => 'http://base.example.com/',
    name => 'name',
    alt  => 'alt',
    tag  => 'a',
    height => 2112,
    width => 5150,
    attrs  => { id => 'id', class => 'foo bar' },
} );

is( $img->url, 'url.html', 'url() works' );
is( $img->base, 'http://base.example.com/', 'base() works' );
is( $img->name, 'name', 'name() works' );
is( $img->alt, 'alt', 'alt() works' );
is( $img->tag, 'a', 'tag() works' );
is( $img->height, 2112, 'height works' );
is( $img->width, 5150, 'width works' );
is( $img->attrs->{id}, 'id', 'attrs/id works' );
is( $img->attrs->{class}, 'foo bar', 'attrs/class works' );
is( $img->url_abs, 'http://base.example.com/url.html', 'url_abs works' );
isa_ok( $img->URI, 'URI::URL', 'Returns an object' );

my $img_no_src = WWW::Mechanize::Image->new( {
    url  => undef,
    base => 'http://base.example.com/',
    tag  => 'img',
    height => 123,
    width => 321,
} );

isa_ok($img_no_src, 'WWW::Mechanize::Image');
is( $img_no_src->url, undef, 'url() without url is undef');
isa_ok( $img_no_src->URI, 'URI::URL', 'Returns an object' );