File: 06-get_history.t

package info (click to toggle)
libmediawiki-bot-perl 5.007000-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 656 kB
  • sloc: perl: 1,992; makefile: 5
file content (59 lines) | stat: -rw-r--r-- 2,011 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
47
48
49
50
51
52
53
54
55
56
57
58
59
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 $title = 'User:Mike.lifeguard/06-get_history.t';
my $result = [
  {
    'timestamp_time' => '00:17:05',
    'revid' => 132956,
    'comment' => qq{Protected "[[User:Mike.lifeguard/06-get history.t]]": history must be static (\x{200e}[edit=sysop] (indefinite) \x{200e}[move=sysop] (indefinite))},
    'timestamp_date' => '2012-05-09',
    'minor' => 1,
    'user' => 'Mike.lifeguard'
  },
  {
    'timestamp_time' => '00:16:54',
    'revid' => 132955,
    'comment' => 'Created page with "."',
    'timestamp_date' => '2012-05-09',
    'minor' => '',
    'user' => 'Mike.lifeguard'
  }
];

# old style
my @history;
warning_is(
    sub { @history = $bot->get_history($title, undef, 132955); },
    'Please pass a hashref; this method of calling get_history is deprecated and will be removed in a future release',
    'deprecated usage of get_history'
);
warning_is(
    sub { @history = $bot->get_history($title, 2); },
    'Please pass a hashref; this method of calling get_history is deprecated and will be removed in a future release',
    'deprecated usage of get_history'
);
is_deeply(\@history, $result, 'Loaded page history (old format) OK') or diag explain \@history;

#new style
@history = $bot->get_history($title, {'rvlimit' => 2});

is_deeply(\@history, $result, 'Loaded page history OK') or diag explain \@history;

my $time = $history[0]->{'timestamp_time'};
my $date = $history[0]->{'timestamp_date'};
my ($timestamp, $user) = $bot->recent_edit_to_page($title);

like($timestamp, qr/^\d{4}-\d{1,2}-\d{1,2}T\d\d:\d\d:\d\dZ$/, 'Timestamp formed properly');
is($timestamp, "${date}T${time}Z", 'Timestamp found OK');
is($user, 'Mike.lifeguard', 'User returned!'); # Unreported bug