6 eval q{use XML::Feed; use HTML::Parser};
8 eval q{use Test::More skip_all =>
9 "XML::Feed and/or HTML::Parser not available"};
12 eval q{use Test::More tests => 77};
17 my $statedir = 't/tinypodcast/.ikiwiki';
20 my $baseurl = 'http://example.com';
21 my @command = (qw(./ikiwiki.out -plugin inline -rss -atom));
22 push @command, qw(-underlaydir=underlays/basewiki);
23 push @command, qw(-set underlaydirbase=underlays -templatedir=templates);
24 push @command, "-url=$baseurl", qw(t/tinypodcast), "$tmp/out";
26 ok(! system("mkdir $tmp"));
27 ok(! system(@command));
31 'piano.mp3' => 'audio/mpeg',
32 'scroll.3gp' => 'video/3gpp',
33 'walter.ogg' => 'video/x-theora+ogg',
36 for my $format (qw(atom rss)) {
37 my $feed = XML::Feed->parse("$tmp/out/index.$format");
39 is($feed->title, 'wiki',
40 qq{$format feed title});
41 is($feed->link, "$baseurl/",
42 qq{$format feed link});
43 is($feed->description, $feed->title,
44 qq{$format feed description});
45 if ('atom' eq $format) {
46 is($feed->author, $feed->title,
47 qq{$format feed author});
48 is($feed->id, "$baseurl/",
50 is($feed->generator, "ikiwiki",
51 qq{$format feed generator});
54 for my $entry ($feed->entries) {
55 my $title = $entry->title;
57 my $body = $entry->content->body;
58 my $enclosure = $entry->enclosure;
60 is($entry->link, $url, qq{$format $title link});
61 isnt($entry->issued, undef,
62 qq{$format $title issued date});
63 isnt($entry->modified, undef,
64 qq{$format $title modified date});
66 if (defined $media_types{$title}) {
67 is($url, "$baseurl/$title",
68 qq{$format $title id});
70 qq{$format $title no body text});
71 is($enclosure->url, $url,
72 qq{$format $title enclosure url});
73 is($enclosure->type, $media_types{$title},
74 qq{$format $title enclosure type});
75 cmp_ok($enclosure->length, '>', 0,
76 qq{$format $title enclosure length});
79 is($url, "$baseurl/$title/",
80 qq{$format $title id});
82 qq{$format $title body text});
84 qq{$format $title no enclosure});
89 ok(! system("rm -rf $tmp $statedir"));
92 sub single_page_html {
93 my @command = (qw(./ikiwiki.out));
94 push @command, qw(-underlaydir=underlays/basewiki);
95 push @command, qw(-set underlaydirbase=underlays -templatedir=templates);
96 push @command, qw(t/tinypodcast), "$tmp/out";
98 ok(! system("mkdir $tmp"));
99 ok(! system(@command));
100 my $html = "$tmp/out/podcast/index.html";
102 my $body = _extract_html_content($html, 'content');
103 like($body, qr/article has content and/m, q{html body text});
105 my $enclosure = _extract_html_content($html, 'enclosure');
106 like($enclosure, qr/Download this episode/m, q{html enclosure});
108 # XXX die if specified enclosure doesn't exist
109 # XXX die if more than one enclosure is specified
111 ok(! system("rm -rf $tmp $statedir"));
114 sub _extract_html_content {
115 my ($file, $desired_id, $desired_tag) = @_;
116 $desired_tag = 'div' unless defined $desired_tag;
118 my $p = HTML::Parser->new(api_version => 3);
121 $p->handler(start => sub {
122 my ($tag, $self, $attr) = @_;
123 return if $tag ne $desired_tag;
124 return unless exists $attr->{id} && $attr->{id} eq $desired_id;
126 $self->handler(text => sub {
131 $self->handler(end => sub {
132 my ($tag, $self) = @_;
133 $self->eof if $tag eq $desired_tag;
135 }, "tagname,self,attr");
137 $p->parse_file($file) || die $!;