handle newline and html break conversions in mediawiki publishing
[scpubgit/System-Introspector-Report.git] / t / publish_mediawiki.t
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(
33   api_uri => 'http://example.com:9999/',
34   username => 'foo',
35   password => 'bar',
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       { bar => 989, baz => "foo\nbar" },
81     ],
82   },
83 ]), 'publish ok';
84
85 my $_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
94 is $result{foo}->$_despace,
95    scalar(io("$FindBin::Bin/data/result/foo.txt")->slurp)->$_despace,
96    'resulting page looks correct';
97
98 done_testing;