Commit | Line | Data |
21e7cc98 |
1 | use strictures 1; |
2 | use Test::More; |
3 | use IO::All; |
4 | use FindBin; |
5 | |
6 | use aliased 'System::Introspector::Report::Publish::MediaWiki'; |
7 | |
8 | my %result; |
9 | |
10 | do { |
11 | package TestConnection; |
12 | use Moo; |
13 | use IO::All; |
14 | use aliased 'System::Introspector::Report::Publish::MediaWiki::Page'; |
15 | |
16 | sub get { |
17 | my ($self, $name) = @_; |
18 | return Page->new( |
19 | name => $name, |
20 | timestamp => 23, |
21 | content => scalar(io("$FindBin::Bin/data/$name.txt")->slurp), |
22 | ); |
23 | } |
24 | |
25 | sub put { |
26 | my ($self, $page) = @_; |
27 | $result{$page->name} = $page->content; |
28 | } |
29 | }; |
30 | |
31 | my $conn = TestConnection->new; |
32 | my $wiki = MediaWiki->new( |
f15f1fe1 |
33 | api_uri => 'http://example.com:9999/', |
34 | username => 'foo', |
35 | password => 'bar', |
21e7cc98 |
36 | connection => $conn, |
37 | page => { |
38 | foo => { |
39 | report => ['foo:*'], |
40 | }, |
41 | }, |
42 | ); |
43 | |
44 | ok $wiki->publish([ |
45 | { id => [qw( foo a )], |
46 | title => "Foo A", |
47 | rowid => ['bar'], |
48 | columns => [ |
49 | { key => 'bar', label => 'Bar' }, |
50 | { key => 'baz', label => 'Baz' }, |
51 | ], |
52 | rows => [ |
53 | { bar => 231, baz => 421 }, |
54 | { bar => 232, baz => 884 }, |
55 | { bar => 332, baz => 784 }, |
56 | ], |
57 | }, |
58 | { id => [qw( foo b )], |
59 | title => "Foo B", |
60 | rowid => ['bar'], |
61 | columns => [ |
62 | { key => 'bar', label => 'Bar' }, |
63 | { key => 'baz', label => 'Baz' }, |
64 | ], |
65 | rows => [ |
66 | { bar => 231, baz => 421 }, |
67 | { bar => 332, baz => 784 }, |
68 | ], |
69 | }, |
70 | { id => [qw( foo c )], |
71 | title => "Foo C", |
72 | rowid => ['bar'], |
73 | columns => [ |
74 | { key => 'bar', label => 'New Bar' }, |
75 | { key => 'baz', label => 'New Baz' }, |
76 | ], |
77 | rows => [ |
78 | { bar => 232, baz => 884 }, |
79 | { bar => 332, baz => 784 }, |
80 | ], |
81 | }, |
82 | ]), 'publish ok'; |
83 | |
84 | my $_despace = sub { |
85 | my $string = shift; |
86 | $string =~ s{[\s\n]+}{}g; |
87 | return $string; |
88 | }; |
89 | |
90 | ## uncomment to regenerate result file |
91 | # do { no warnings; $result{foo} > io("$FindBin::Bin/data/result/foo.txt") }; |
92 | |
93 | is $result{foo}->$_despace, |
94 | scalar(io("$FindBin::Bin/data/result/foo.txt")->slurp)->$_despace, |
95 | 'resulting page looks correct'; |
96 | |
97 | done_testing; |