1731bdfa2ba914d413b769fa1b3b8588329c0a3c
[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 use File::Temp;
6 use lib "$FindBin::Bin/lib";
7 use aliased 'System::Introspector::Report::Publish::MediaWiki';
8
9 $ENV{TEST_SI_REPORT_OUT} = my $out_dir = File::Temp->newdir;
10 $ENV{TEST_SI_REPORT_IN}  = "$FindBin::Bin/data";
11
12 my %result;
13
14 my $wiki = MediaWiki->new(
15   api_uri => 'http://example.com:9999/',
16   connection_class => 'TestConnection',
17   username => 'foo',
18   password => 'bar',
19   page => {
20     foo => {
21       report => ['foo:*'],
22     },
23   },
24 );
25
26 ok $wiki->publish([
27   { id => [qw( foo a )],
28     title => "Foo A",
29     rowid => ['bar'],
30     columns => [
31       { key => 'bar', label => 'Bar' },
32       { key => 'baz', label => 'Baz' },
33     ],
34     rows => [
35       { bar => 231, baz => 421 },
36       { bar => 232, baz => 884 },
37       { bar => 332, baz => 784 },
38     ],
39   },
40   { id => [qw( foo b )],
41     title => "Foo B",
42     rowid => ['bar'],
43     columns => [
44       { key => 'bar', label => 'Bar' },
45       { key => 'baz', label => 'Baz' },
46     ],
47     rows => [
48       { bar => 231, baz => 421 },
49       { bar => 332, baz => 784 },
50     ],
51   },
52   { id => [qw( foo c )],
53     title => "Foo C",
54     rowid => ['bar'],
55     columns => [
56       { key => 'bar', label => 'New Bar' },
57       { key => 'baz', label => 'New Baz' },
58     ],
59     rows => [
60       { bar => 232, baz => 884 },
61       { bar => 332, baz => 784 },
62       { bar => 989, baz => "foo\nbar" },
63     ],
64   },
65 ]), 'publish ok';
66
67 my $_despace = sub {
68   my $string = shift;
69   $string =~ s{[\s\n]+}{}g;
70   return $string;
71 };
72
73 ## uncomment to regenerate result file
74 # do { no warnings; io("$out_dir/foo") > io("$FindBin::Bin/data/result/foo.txt"); fail "regenerated" };
75
76 is scalar(io("$out_dir/foo")->slurp)->$_despace,
77    scalar(io("$FindBin::Bin/data/result/foo.txt")->slurp)->$_despace,
78    'resulting page looks correct';
79
80 done_testing;