File: 10-api.t

package info (click to toggle)
libmediawiki-api-perl 0.52-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 204 kB
  • sloc: perl: 422; makefile: 4
file content (102 lines) | stat: -rw-r--r-- 2,189 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
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!perl -T

use strict;
use warnings;

use Test::More;
use LWP::UserAgent;

plan skip_all => "Unset NO_NETWORK to enable this test" if $ENV{NO_NETWORK};

sub get_url {
  my $url = shift;
  my $ua = LWP::UserAgent->new;
  $ua->timeout(10);
  $ua->env_proxy;
  my $response = $ua->get($url);
  return $response;
}

my $api_url = 'https://testwiki.exotica.org.uk/w/api.php';

my $response = get_url($api_url);

if ($response->is_success) {
  plan tests => 11;
} else {
  plan skip_all => "Can't access $api_url to run tests";
}

use_ok( 'MediaWiki::API' );
my $mw = MediaWiki::API->new( { api_url => $api_url }  );
isa_ok( $mw, 'MediaWiki::API' );
$mw->{config}->{upload_url} = 'https://testwiki.exotica.org.uk/wiki/Special:Upload';

my $ref;
ok ( $ref = $mw->api( {
  action => 'query',
  meta => 'siteinfo'
  } ),
  '->api siteinfo call'
  );

is ( $ref->{query}->{general}->{server}, 'https://testwiki.exotica.org.uk', '->api siteinfo server' );

ok ( $mw->api( {
  action => 'query',
  list => 'allcategories'
  } ),
  '->list allcategories'
  );

my $time = time;
my $title = 'apitest/' . $time;
my $content = "* Version: $MediaWiki::API::VERSION\n\nthe quick brown fox jumps over the lazy dog";
ok ( $mw->edit( {
  action => 'edit',
  title => $title,
  text => $content,
  summary => 'MediaWiki::API Test suite - edit page',
  bot => 1
  } ),
  '->edit ' . $title
  );

ok ( $ref = $mw->get_page( { title => $title } ), "->get_page $title call" );

is ( $ref->{'*'}, $content, "->get_page $title content" );

ok ( $mw->edit( {
  action => 'move',
  from => $title,
  to  => $title . '-moved',
  summary => 'MediaWiki::API Test suite - move page',
  bot => 1
  } ),
  '->edit action=move ' . $title 
  );

$title = $title . '-moved';
ok ( $mw->edit( {
  action => 'delete',
  title => $title,
  summary => 'MediaWiki::API Test suite - delete page',
  bot => 1
  } ),
  '->edit action=delete ' . $title
  );

$title = "apitest - $time.png";
ok ( $mw->edit( {
  action => 'upload',
  filename => $title,
  comment => 'MediaWiki::API Test suite - upload image',
  file => [ 't/testimage.png'],
  ignorewarnings => 1,
  bot => 1
  } ),
  "->edit action=upload $title"
  );

done_testing();