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 62 63 64 65 66 67 68 69 70 71 72 73 74
|
use strict;
use warnings;
use Test::Is qw(extended);
use Test::RequiresInternet 'test.wikipedia.org' => 80;
use Test::More;
use MediaWiki::Bot qw(:constants);
my $t = __FILE__;
plan tests => ($ENV{PWPUsername} && $ENV{PWPPassword} ? 3 : 2);
my $agent = "MediaWiki::Bot tests (https://metacpan.org/MediaWiki::Bot; $t)";
my $bot = MediaWiki::Bot->new({
agent => $agent,
host => 'test.wikipedia.org',
protocol => 'https',
( $ENV{PWPUsername} && $ENV{PWPPassword}
? ( login_data => { username => $ENV{PWPUsername}, password => $ENV{PWPPassword} } )
: ()
),
});
my $rand = rand();
my $rand2 = rand();
my $title = 'User:Mike.lifeguard/04-edit.t';
my $status = $bot->edit({
page => $title,
text => $rand,
summary => $agent . ' (should be a minor edit)',
minor => 1,
});
SKIP: {
skip 'Cannot use editing tests: ' . $bot->{error}->{details}, 2
if defined $bot->{error}->{code}
and ($bot->{error}->{code} == ERR_API or $bot->{error}->{code} == ERR_CAPTCHA);
is $bot->get_text($title, $status->{newrevid}) => $rand, 'Did whole-page editing successfully';
$status = $bot->edit({
page => $title,
text => $rand2,
section => 'new',
summary => $agent,
});
skip 'Cannot use editing tests: ' . $bot->{error}->{details}, 1
if defined $bot->{error}->{code}
and ($bot->{error}->{code} == ERR_API or $bot->{error}->{code} == ERR_CAPTCHA);
diag explain $bot->{error} unless $status;
like $bot->get_text($title, $status->{edit}->{newrevid}) => qr{== \Q$agent\E ==\n\n\Q$rand2\E},
'Did section editing successfully'
or diag explain { status => $status, error => $bot->{error} };
}
subtest 'check history' => sub {
my $do_history_test = $ENV{PWPUsername} && $ENV{PWPPassword} &&
!($bot->{error}->{code} == ERR_API or $bot->{error}->{code} == ERR_CAPTCHA);
plan ($do_history_test ? (tests => 2) : (skip_all => "previous test didn't run"));
my @hist = $bot->get_history($title, 2);
ok $hist[1]->{minor}, 'Minor edit' or diag explain \@hist;
$status = $bot->edit({
page => $title,
text => $rand2.$rand,
summary => $agent . ' (major)',
minor => 0,
});
@hist = $bot->get_history($title, 1);
ok !$hist[0]->{minor}, 'Not a minor edit'
or diag explain { hist => \@hist, status => $status };
}
|