Add tests for existing podcast behavior.
[ikiwiki.git] / t / podcast.t
1 #!/usr/bin/perl
2 use warnings;
3 use strict;
4
5 BEGIN {
6         eval q{use XML::Feed};
7         if ($@) {
8                 eval q{use Test::More skip_all => "XML::Feed not available"};
9         }
10         else {
11                 eval q{use Test::More tests => 36};
12         }
13 }
14
15 sub simple_podcast {
16         my $baseurl = 'http://example.com';
17         ok(! system("mkdir t/tmp"));
18         ok(! system("./ikiwiki.out -plugin inline -url=$baseurl -rss -atom -underlaydir=underlays/basewiki -set underlaydirbase=underlays -templatedir=templates t/tinypodcast t/tmp/out"));
19
20         my %media_types = (
21                 'piano.mp3'     => 'audio/mpeg',
22                 'scroll.3gp'    => 'video/3gpp',
23                 'walter.ogg'    => 'video/x-theora+ogg',
24         );
25
26         for my $format (qw(atom rss)) {
27                 my $feed = XML::Feed->parse("t/tmp/out/index.$format");
28
29                 is($feed->title, 'wiki', qq{$format feed title});
30                 is($feed->link, "$baseurl/", qq{$format feed link});
31                 is($feed->description, $feed->title, qq{$format feed description});
32                 if ('atom' eq $format) {
33                         is($feed->author, $feed->title, qq{$format feed author});
34                         is($feed->id, "$baseurl/", qq{$format feed id});
35                         is($feed->generator, "ikiwiki", qq{$format feed generator});
36                 }
37
38                 for my $entry ($feed->entries) {
39                         my $title = $entry->title;
40                         my $url = $entry->id;
41                         my $enclosure = $entry->enclosure;
42
43                         is($url, "$baseurl/$title", qq{$format $title id});
44                         is($entry->link, $url, qq{$format $title link});
45                         is($enclosure->url, $url, qq{$format $title enclosure url});
46                         is($enclosure->type, $media_types{$title}, qq{$format $title enclosure type});
47                         # is($enclosure->length, '12345', qq{$format $title enclosure length});
48                         # creation date
49                         # modification date
50                 }
51         }
52
53         ok(! system("rm -rf t/tmp t/tinypodcast/.ikiwiki"));
54 }
55
56 simple_podcast();