File: 39-image_usage.t

package info (click to toggle)
libmediawiki-bot-perl 5.006003-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, stretch
  • size: 600 kB
  • ctags: 77
  • sloc: perl: 1,928; makefile: 5
file content (37 lines) | stat: -rw-r--r-- 1,384 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
use strict;
use warnings;
use Test::RequiresInternet 'test.wikipedia.org' => 80;
use Test::More tests => 7;
use Test::Warn;

use MediaWiki::Bot;
my $t = __FILE__;

my $bot = MediaWiki::Bot->new({
    agent   => "MediaWiki::Bot tests (https://metacpan.org/MediaWiki::Bot; $t)",
    host    => 'test.wikipedia.org',
});

my $file = 'File:Wiki.png';

my @pages = $bot->image_usage($file, undef, undef, { max => 1 });
my @pages_bc;
warning_like(
    sub { @pages_bc = $bot->links_to_image($file, undef, undef, { max => 1 }); },
    qr/links_to_image is an alias of image_usage; please use the new name/,
    'links_to_image is deprecated'
);

ok(     @pages,                                             'No error');
cmp_ok( scalar @pages,                  '>', 1,             'More than one result');
ok(     defined($pages[0]),                                 'Something was returned');
like(   $pages[0],                      qr/\w+/,            'The title looks valid');
is_deeply(\@pages, \@pages_bc,                              'The BC method returned the same as the current method');

$bot->image_usage($file, undef, 'nonredirects', { hook => \&mysub, max => 5 });
my $is_redir = 1;
sub mysub {
    my $res = shift;
    $is_redir = exists $res->[0]->{redirect};
}
isnt(     $is_redir,                                        'We got a normal link when we asked for no redirects');