|
1 | 1 | use strict;
|
2 | 2 | use warnings;
|
3 |
| -use Test::More 0.88; |
| 3 | +use Test::More 0.96; |
4 | 4 |
|
5 | 5 | use MediaWiki::Bot;
|
6 | 6 | my $t = __FILE__;
|
7 | 7 |
|
8 |
| -unless (eval q{use Imager; 1 }) { |
9 |
| - plan skip_all => q{Imager required}; |
10 |
| - exit; |
| 8 | +plan eval q{use Imager; 1 } |
| 9 | + ? (tests => 3) |
| 10 | + : (skip_all => q{Imager required}); |
| 11 | + |
| 12 | +my $username = $ENV{'PWPUsername'}; |
| 13 | +my $password = $ENV{'PWPPassword'}; |
| 14 | +my $login_data; |
| 15 | +if (defined($username) and defined($password)) { |
| 16 | + $login_data = { username => $username, password => $password }; |
11 | 17 | }
|
12 | 18 |
|
13 |
| -#my $username = $ENV{'PWPUsername'}; |
14 |
| -#my $password = $ENV{'PWPPassword'}; |
15 | 19 | my $bot = MediaWiki::Bot->new({
|
16 | 20 | agent => "MediaWiki::Bot tests ($t)",
|
17 | 21 | host => 'test.wikipedia.org',
|
18 |
| - # login_data => { username => $username, password => $password }, |
| 22 | + login_data => $login_data, |
19 | 23 | });
|
20 | 24 | if(defined($ENV{'PWPMakeTestSetWikiHost'})) {
|
21 | 25 | $bot->set_wiki($ENV{'PWPMakeTestSetWikiHost'}, $ENV{'PWPMakeTestSetWikiDir'});
|
22 | 26 | }
|
23 | 27 |
|
24 |
| -{ #no width, no height |
25 |
| - my $data = $bot->get_image('File:Test-favicon.png'); |
26 |
| - ok($data, 'nonscaled image retrieved'); |
| 28 | +my $image_name = 'File:Albert_Einstein_Head.jpg'; |
| 29 | +subtest 'no width, no height' => sub { |
| 30 | + plan tests => 4; |
| 31 | + my $data = $bot->get_image($image_name); |
| 32 | + ok $data, 'nonscaled image retrieved'; |
27 | 33 |
|
28 |
| - my $img = Imager->new; |
29 |
| - my $did_read = $img->read(data=>$data); |
30 |
| - diag $img->errstr unless $did_read; |
31 |
| - ok($did_read, 'retrieved nonscaled data is an image.'); |
| 34 | + my $img = Imager->new; |
| 35 | + my $did_read = $img->read(data => $data); |
| 36 | + ok $did_read, 'retrieved nonscaled data is an image' |
| 37 | + or diag $img->errstr; |
32 | 38 |
|
33 |
| - is($img->getwidth(),16, 'nonscaled img has w 16'); |
34 |
| - is($img->getheight(),16, 'nonscaled img has h 16'); |
35 |
| -} |
36 |
| -{ #supply a width |
37 |
| - my $data = $bot->get_image('File:Test-favicon.png',{width=>12}); |
38 |
| - ok($data, 'wscaled image retrieved'); |
| 39 | + is $img->getwidth(), 924, 'nonscaled img has w 924'; |
| 40 | + is $img->getheight(), 1203, 'nonscaled img has h 1203'; |
| 41 | +}; |
39 | 42 |
|
40 |
| - my $img = Imager->new; |
41 |
| - my $did_read = $img->read(data=>$data); |
42 |
| - diag $img->errstr unless $did_read; |
43 |
| - ok($did_read, 'retrieved wscaled data is an image.'); |
| 43 | +subtest 'supply a width' => sub { |
| 44 | + plan tests => 3; |
| 45 | + my $data = $bot->get_image($image_name, {width => 12}); |
| 46 | + ok $data, 'wscaled image retrieved'; |
44 | 47 |
|
45 |
| - is($img->getwidth(),12, 'wscaled img has w 12'); |
46 |
| - is($img->getheight(),12, 'wscaled img has h 12'); |
47 |
| -} |
48 |
| -{ #supply a width & a not-to-scale height. These |
49 |
| - # should both be considered maximum dimensions, |
50 |
| - # and scale should be proportional. |
51 |
| - my $data = $bot->get_image('File:Test-favicon.png',{width=>4,height=>8}); |
52 |
| - ok($data, 'whscaled image retrieved'); |
53 |
| - |
54 |
| - my $img = Imager->new; |
55 |
| - my $did_read = $img->read(data=>$data); |
56 |
| - diag $img->errstr unless $did_read; |
57 |
| - ok($did_read, 'retrieved whscaled data is an image.'); |
58 |
| - |
59 |
| - is($img->getwidth(),4, 'whscaled img has w 4'); |
60 |
| - is($img->getheight(),4, 'whscaled img has h 4'); |
61 |
| -} |
| 48 | + my $img = Imager->new; |
| 49 | + my $did_read = $img->read(data => $data); |
| 50 | + ok $did_read, 'retrieved wscaled data is an image.' |
| 51 | + or diag $img->errstr; |
| 52 | + |
| 53 | + is $img->getwidth(), 12, 'wscaled img has w 12'; |
| 54 | +}; |
| 55 | + |
| 56 | +#supply a width & a not-to-scale height. These |
| 57 | +# should both be considered maximum dimensions, |
| 58 | +# and scale should be proportional. |
| 59 | +subtest 'supply a width and a not-to-scale height' => sub { |
| 60 | + plan tests => 4; |
| 61 | + my $data = $bot->get_image($image_name, {width => 200, height => 200}); |
| 62 | + ok $data, 'whscaled image retrieved'; |
| 63 | + |
| 64 | + my $img = Imager->new; |
| 65 | + my $did_read = $img->read(data => $data); |
| 66 | + ok $did_read, 'retrieved whscaled data is an image.' |
| 67 | + or diag $img->errstr; |
62 | 68 |
|
63 |
| -done_testing; |
| 69 | + cmp_ok $img->getwidth(), '<=', 200, '200 height is max'; |
| 70 | + cmp_ok $img->getheight(), '<=', 200, '200 width is max'; |
| 71 | +}; |
0 commit comments