#!/usr/bin/perl -w
use strict;
use XML::Generator::RSS10;
use Test::More;
BEGIN
{
eval { require XML::SAX::Writer };
if ($@)
{
plan skip_all => 'Cannot run tests without XML::SAX::Writer.';
}
else
{
plan tests => 8;
}
}
{
my $out;
my $writer = XML::SAX::Writer->new( Output => \$out );
my $gen = XML::Generator::RSS10->new( Handler => $writer,
pretty => 1,
modules => [ qw( content ) ],
);
$gen->item( title => 'Item 1 title',
link => 'http://example.com/foo1',
content => { encoded => 'bar' },
);
$gen->channel( title => 'Channel title',
link => 'http://example.com/',
description => 'a description',
);
my $p = XML::Generator::RSS10::content->Prefix;
my $uri = XML::Generator::RSS10::content->NamespaceURI;
like( $out, qr{xmlns:\Q$p\E=.\Q$uri\E.}s,
"expect to find $p namespace declaration" );
like( $out, qr{- ]+>.*.+.*
}s,
'expect to find content:encoded tag inside item tag' );
like( $out, qr{- ]+>.*bar\]\]>.*
}s,
'expect to find CDATA content inside item tag' );
}
{
my $out;
my $writer = XML::SAX::Writer->new( Output => \$out );
my $gen = XML::Generator::RSS10->new( Handler => $writer,
pretty => 1,
modules => [ qw( content ) ],
);
$gen->item( title => 'Item 1 title',
link => 'http://example.com/foo1',
);
$gen->channel( title => 'Channel title',
link => 'http://example.com/',
description => 'a description',
content =>
{ items =>
[ { format => 'http://www.w3.org/1999/xhtml',
content => 'Axis Love',
},
{ format => 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional',
about => 'http://example.com/content-elsewhere',
},
{ format => 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional',
encoding => 'http://www.w3.org/TR/REC-xml#dt-wellformed',
content => 'italics',
},
],
},
);
like( $out, qr{]+>.*\s*\s*.+\s*\s*.*}s,
'expect to find content:items -> rdf:Bag -> rdf:li tags nested inside channel tag' );
like( $out, qr{.+}s,
'expect to find content:format inside rdf:li tag' );
like( $out, qr{.+Axis Love\]\]>.+}s,
'expect to find CDATA inside content:item tag' );
like( $out, qr{.+}s,
'expect to find CDATA inside content:item tag' );
like( $out, qr{.+}s,
'expect to find CDATA inside content:item tag' );
}