handle newline and html break conversions in mediawiki publishing
[scpubgit/System-Introspector-Report.git] / t / publish_mediawiki.t
CommitLineData
21e7cc98 1use strictures 1;
2use Test::More;
3use IO::All;
4use FindBin;
5
6use aliased 'System::Introspector::Report::Publish::MediaWiki';
7
8my %result;
9
10do {
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
31my $conn = TestConnection->new;
32my $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
44ok $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 },
a57e8790 80 { bar => 989, baz => "foo\nbar" },
21e7cc98 81 ],
82 },
83]), 'publish ok';
84
85my $_despace = sub {
86 my $string = shift;
87 $string =~ s{[\s\n]+}{}g;
88 return $string;
89};
90
91## uncomment to regenerate result file
92# do { no warnings; $result{foo} > io("$FindBin::Bin/data/result/foo.txt") };
93
94is $result{foo}->$_despace,
95 scalar(io("$FindBin::Bin/data/result/foo.txt")->slurp)->$_despace,
96 'resulting page looks correct';
97
98done_testing;