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 59 60 61
|
use strict;
use warnings;
use Test::RequiresInternet 'test.wikipedia.org' => 80;
use Test::More 0.96;
use MediaWiki::Bot;
my $t = __FILE__;
plan eval q{ use Imager; use Imager::File::JPEG; 1 }
? (tests => 3)
: (skip_all => q{Imager & Imager::File::JPEG required});
my $bot = MediaWiki::Bot->new({
agent => "MediaWiki::Bot tests (https://metacpan.org/MediaWiki::Bot; $t)",
host => 'test.wikipedia.org',
});
my $image_name = 'File:Albert_Einstein_Head.jpg';
subtest 'no width, no height' => sub {
plan tests => 4;
my $data = $bot->get_image($image_name);
ok $data, 'nonscaled image retrieved';
my $img = Imager->new;
my $did_read = $img->read(data => $data);
ok $did_read, 'retrieved nonscaled data is an image'
or diag $img->errstr;
is $img->getwidth(), 3250, 'nonscaled img has w 3,250';
is $img->getheight(), 4333, 'nonscaled img has h 4,333';
};
subtest 'supply a width' => sub {
plan tests => 3;
my $data = $bot->get_image($image_name, {width => 12});
ok $data, 'wscaled image retrieved';
my $img = Imager->new;
my $did_read = $img->read(data => $data);
ok $did_read, 'retrieved wscaled data is an image.'
or diag $img->errstr;
is $img->getwidth(), 12, 'wscaled img has w 12';
};
#supply a width & a not-to-scale height. These
# should both be considered maximum dimensions,
# and scale should be proportional.
subtest 'supply a width and a not-to-scale height' => sub {
plan tests => 4;
my $data = $bot->get_image($image_name, {width => 200, height => 200});
ok $data, 'whscaled image retrieved';
my $img = Imager->new;
my $did_read = $img->read(data => $data);
ok $did_read, 'retrieved whscaled data is an image.'
or diag $img->errstr;
cmp_ok $img->getwidth(), '<=', 200, '200 height is max';
cmp_ok $img->getheight(), '<=', 200, '200 width is max';
};
|