mediawiki merging, row identification, tests
[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   connection => $conn,
34   page => {
35     foo => {
36       report => ['foo:*'],
37     },
38   },
39 );
40
41 ok $wiki->publish([
42   { id => [qw( foo a )],
43     title => "Foo A",
44     rowid => ['bar'],
45     columns => [
46       { key => 'bar', label => 'Bar' },
47       { key => 'baz', label => 'Baz' },
48     ],
49     rows => [
50       { bar => 231, baz => 421 },
51       { bar => 232, baz => 884 },
52       { bar => 332, baz => 784 },
53     ],
54   },
55   { id => [qw( foo b )],
56     title => "Foo B",
57     rowid => ['bar'],
58     columns => [
59       { key => 'bar', label => 'Bar' },
60       { key => 'baz', label => 'Baz' },
61     ],
62     rows => [
63       { bar => 231, baz => 421 },
64       { bar => 332, baz => 784 },
65     ],
66   },
67   { id => [qw( foo c )],
68     title => "Foo C",
69     rowid => ['bar'],
70     columns => [
71       { key => 'bar', label => 'New Bar' },
72       { key => 'baz', label => 'New Baz' },
73     ],
74     rows => [
75       { bar => 232, baz => 884 },
76       { bar => 332, baz => 784 },
77     ],
78   },
79 ]), 'publish ok';
80
81 my $_despace = sub {
82   my $string = shift;
83   $string =~ s{[\s\n]+}{}g;
84   return $string;
85 };
86
87 ## uncomment to regenerate result file
88 # do { no warnings; $result{foo} > io("$FindBin::Bin/data/result/foo.txt") };
89
90 is $result{foo}->$_despace,
91    scalar(io("$FindBin::Bin/data/result/foo.txt")->slurp)->$_despace,
92    'resulting page looks correct';
93
94 done_testing;