#!/usr/bin/perl use strict; use warnings; use Test::More tests => 167; use XML::RSS; sub contains { local $Test::Builder::Level = $Test::Builder::Level + 1; my ($rss, $sub_string, $msg) = @_; my $rss_output = $rss->as_string(); my $ok = ok (index ($rss_output, $sub_string) >= 0, $msg ); if (! $ok) { diag("Could not find the substring [$sub_string] in:{{{{\n$rss_output\n}}}}\n"); } } sub not_contains { local $Test::Builder::Level = $Test::Builder::Level + 1; my ($rss, $sub_string, $msg) = @_; ok ((index ($rss->as_string(), $sub_string) < 0), $msg ); } sub create_rss_1 { my $args = shift; my $extra_rss_args = $args->{rss_args} || []; # my $rss = new XML::RSS (version => '0.9'); my $rss = new XML::RSS (version => $args->{version}, @$extra_rss_args); my $image_link = exists($args->{image_link}) ? $args->{image_link} : "http://freshmeat.net/"; my $extra_image_params = $args->{image_params} || []; $rss->channel( title => "freshmeat.net", link => "http://freshmeat.net", description => "the one-stop-shop for all your Linux software needs", ); $rss->image( title => "freshmeat.net", url => "0", link => $image_link, @{$extra_image_params}, ); $rss->add_item( title => "GTKeyboard 0.85", link => "http://freshmeat.net/news/1999/06/21/930003829.html" ); return $rss; } sub create_no_image_rss { my $args = shift; # my $rss = new XML::RSS (version => '0.9'); my $rss = new XML::RSS (version => $args->{version}); $rss->channel( title => "freshmeat.net", link => "http://freshmeat.net", description => "the one-stop-shop for all your Linux software needs", ); $rss->add_item( title => "GTKeyboard 0.85", link => "http://freshmeat.net/news/1999/06/21/930003829.html" ); return $rss; } sub create_item_with_0_rss { my $args = shift; # my $rss = new XML::RSS (version => '0.9'); my $rss = new XML::RSS (version => $args->{version}); my $image_link = exists($args->{image_link}) ? $args->{image_link} : "http://freshmeat.net/"; my $extra_image_params = $args->{image_params} || []; my $extra_item_params = $args->{item_params} || []; $rss->channel( title => "freshmeat.net", link => "http://freshmeat.net", description => "the one-stop-shop for all your Linux software needs", ); $rss->image( title => "freshmeat.net", url => "0", link => $image_link, @{$extra_image_params}, ); $rss->add_item( title => "0", link => "http://rss.mytld/", @{$extra_item_params}, ); return $rss; } sub create_textinput_with_0_rss { my $args = shift; # my $rss = new XML::RSS (version => '0.9'); my $rss = new XML::RSS (version => $args->{version}); my $image_link = exists($args->{image_link}) ? $args->{image_link} : "http://freshmeat.net/"; my $extra_image_params = $args->{image_params} || []; my $extra_item_params = $args->{item_params} || []; my $extra_textinput_params = $args->{textinput_params} || []; $rss->channel( title => "freshmeat.net", link => "http://freshmeat.net", description => "the one-stop-shop for all your Linux software needs", ); $rss->image( title => "freshmeat.net", url => "0", link => $image_link, @{$extra_image_params}, ); $rss->add_item( title => "0", link => "http://rss.mytld/", @{$extra_item_params}, ); $rss->textinput( (map { $_ => 0 } (qw(link title description name))), @{$extra_textinput_params}, ); return $rss; } sub create_channel_rss { my $args = shift; # my $rss = new XML::RSS (version => '0.9'); my $rss = new XML::RSS (version => $args->{version}); my $extra_channel_params = $args->{channel_params} || []; my @build_date = ($args->{version} eq "2.0" && !$args->{omit_date}) ? (lastBuildDate => "Sat, 07 Sep 2002 09:42:31 GMT",) : (); $rss->channel( title => "freshmeat.net", link => "http://freshmeat.net", description => "Linux software", @build_date, @{$extra_channel_params}, ); $rss->add_item( title => "GTKeyboard 0.85", link => "http://freshmeat.net/news/1999/06/21/930003829.html" ); return $rss; } sub create_skipHours_rss { my $args = shift; # my $rss = new XML::RSS (version => '0.9'); my $rss = new XML::RSS (version => $args->{version}); my $extra_channel_params = $args->{channel_params} || []; my $extra_skipHours_params = $args->{skipHours_params} || []; my @build_date = ($args->{version} eq "2.0" && !$args->{omit_date}) ? (lastBuildDate => "Sat, 07 Sep 2002 09:42:31 GMT",) : (); $rss->channel( title => "freshmeat.net", link => "http://freshmeat.net", description => "Linux software", @build_date, @{$extra_channel_params}, ); $rss->add_item( title => "GTKeyboard 0.85", link => "http://freshmeat.net/news/1999/06/21/930003829.html" ); $rss->skipHours(@{$extra_skipHours_params}); return $rss; } sub create_skipDays_rss { my $args = shift; # my $rss = new XML::RSS (version => '0.9'); my $rss = new XML::RSS (version => $args->{version}); my $extra_channel_params = $args->{channel_params} || []; my $extra_skipDays_params = $args->{skipDays_params} || []; my @build_date = ($args->{version} eq "2.0" && !$args->{omit_date}) ? (lastBuildDate => "Sat, 07 Sep 2002 09:42:31 GMT",) : (); $rss->channel( title => "freshmeat.net", link => "http://freshmeat.net", description => "Linux software", @build_date, @{$extra_channel_params}, ); $rss->add_item( title => "GTKeyboard 0.85", link => "http://freshmeat.net/news/1999/06/21/930003829.html" ); $rss->skipDays(@{$extra_skipDays_params}); return $rss; } sub create_rss_with_image_w_undef_link { my $args = shift; # my $rss = new XML::RSS (version => '0.9'); my $rss = new XML::RSS (version => $args->{version}); my $extra_image_params = $args->{image_params} || []; $rss->channel( title => "freshmeat.net", link => "http://freshmeat.net", description => "the one-stop-shop for all your Linux software needs", ); $rss->image( title => "freshmeat.net", url => "0", @{$extra_image_params}, ); $rss->add_item( title => "GTKeyboard 0.85", link => "http://freshmeat.net/news/1999/06/21/930003829.html" ); return $rss; } sub create_item_rss { my $args = shift; # my $rss = new XML::RSS (version => '0.9'); my $rss = new XML::RSS (version => $args->{version}); my $extra_item_params = $args->{item_params} || []; $rss->channel( title => "freshmeat.net", link => "http://freshmeat.net", description => "the one-stop-shop for all your Linux software needs", ); $rss->add_item( title => "Freecell Solver", link => "http://fc-solve.berlios.de/", @$extra_item_params, ); return $rss; } sub create_rss_without_item { my $args = shift; # my $rss = new XML::RSS (version => '0.9'); my $rss = new XML::RSS (version => $args->{version}); $rss->channel( title => "freshmeat.net", link => "http://freshmeat.net", description => "the one-stop-shop for all your Linux software needs", ); return $rss; } { my $rss = create_no_image_rss({version => "0.9"}); # TEST not_contains($rss, "", "0.9 - if an image was not specified it isn't there." ); } { my $rss = create_no_image_rss({version => "0.91"}); # TEST not_contains($rss, "", "0.91 - if an image was not specified it isn't there." ); } { my $rss = create_no_image_rss({version => "1.0"}); # TEST not_contains($rss, " "2.0"}); # TEST not_contains($rss, "", "1.0 - if an image was not specified it isn't there." ); } { my $rss = create_rss_1({version => "0.9"}); # TEST ok ($rss->as_string =~ m{.*?freshmeat.net.*?0.*?http://freshmeat.net/.*?}s, "Checking for image in RSS 0.9"); } { my $rss = create_rss_1({version => "0.91"}); # TEST ok ($rss->as_string =~ m{.*?freshmeat.net.*?0.*?http://freshmeat.net/.*?}s, "Checking for image in RSS 0.9.1"); } { my $rss = create_rss_1({version => "1.0"}); # TEST ok ($rss->as_string =~ m{.*?freshmeat.net.*?0.*?http://freshmeat.net/.*?}s, "Checking for image in RSS 1.0"); # TEST contains ($rss, "\n\n", "1.0 - contains image rdf:resource." ); } { my $rss = create_rss_1({version => "2.0"}); # TEST ok ($rss->as_string =~ m{.*?freshmeat.net.*?0.*?http://freshmeat.net/.*?}s, "Checking for image in RSS 2.0"); } { my $rss = create_rss_1({version => "0.9", image_link => "0",}); # TEST ok (index($rss->as_string(), "\nfreshmeat.net\n0\n0\n\n") >= 0, "Testing for link == 0 appearance in RSS 0.9" ); } { my $version = "0.91"; my $rss = create_rss_1({version => $version, image_link => "0",}); # TEST ok (index($rss->as_string(), "\nfreshmeat.net\n0\n0\n\n") >= 0, "Testing for link == 0 appearance in RSS $version" ); } { my $version = "1.0"; my $rss = create_rss_1({version => $version, image_link => "0",}); # TEST ok (index($rss->as_string(), qq{\nfreshmeat.net\n0\n0\n\n}) >= 0, "Testing for link == 0 appearance in RSS $version" ); } { my $version = "2.0"; my $rss = create_rss_1({version => $version, image_link => "0",}); # TEST ok (index($rss->as_string(), qq{\nfreshmeat.net\n0\n0\n\n}) >= 0, "Testing for link == 0 appearance in RSS $version" ); } { my $version = "0.91"; my $rss = create_rss_1({ version => $version, image_params => [width => 0, height => 0, description => 0], } ); # TEST contains($rss, "\nfreshmeat.net\n0\n" . "http://freshmeat.net/\n" . "0\n0\n" . "0\n\n", "Testing for width, height, description == 0 appearance in RSS $version" ); } { my $rss = create_rss_1({ version => "2.0", image_params => [width => 0, height => 0, description => 0], } ); # TEST contains($rss, "\nfreshmeat.net\n0\n" . "http://freshmeat.net/\n" . "0\n0\n" . "0\n\n", "2.0 - all(width, height, description) == 0 appearance" ); } { my $rss = create_item_with_0_rss({version => "0.9"}); # TEST contains( $rss, "\n0\nhttp://rss.mytld/\n", "0.9 - item/title == 0", ); } { my $rss = create_item_with_0_rss({version => "0.91", item_params => [description => "Hello There"], }); # TEST contains( $rss, "\n0\nhttp://rss.mytld/\nHello There\n", "0.9.1 - item/title == 0", ); } { my $rss = create_item_with_0_rss({version => "0.91", item_params => [description => "0"], }); # TEST contains( $rss, "\n0\nhttp://rss.mytld/\n0\n", "0.9.1 - item/title == 0 && item/description == 0", ); } { my $rss = create_item_with_0_rss({version => "1.0", item_params => [description => "Hello There", about => "Yowza"], }); # TEST contains( $rss, "\n0\nhttp://rss.mytld/\nHello There\n", "1.0 - item/title == 0", ); } { my $rss = create_item_with_0_rss({version => "1.0", item_params => [description => "0", about => "Yowza"], }); # TEST contains( $rss, "\n0\nhttp://rss.mytld/\n0\n", "1.0 - item/title == 0 && item/description == 0", ); } # TODO : Test the dc: items. { my @subs = (qw(title link description author category comments pubDate)); my $rss = create_item_with_0_rss({version => "2.0", item_params => [ map { $_ => 0 } @subs ], } ); # TEST contains( $rss, ("\n" . join("", map { "<$_>0\n" } @subs) . ""), "2.0 - item/* == 0 - 1", ); } { my $rss = create_item_with_0_rss({version => "2.0", item_params => [ title => "Foo&Bar", link => "http://www.mytld/", permaLink => "0", ], } ); # TEST contains( $rss, ("\n" . "Foo&Bar\n" . "http://www.mytld/\n" . "0\n" . "" ), "2.0 - item/permaLink == 0", ); } { my $rss = create_item_with_0_rss({version => "2.0", item_params => [ title => "Foo&Bar", link => "http://www.mytld/", guid => "0", ], } ); # TEST contains( $rss, ("\n" . "Foo&Bar\n" . "http://www.mytld/\n" . "0\n" . "" ), "2.0 - item/guid == 0", ); } { # TEST:$num_iters=4; foreach my $s ( ["Hercules", "http://www.hercules.tld/",], ["0", "http://www.hercules.tld/",], ["Hercules", "0",], ["0", "0",], ) { my $rss = create_item_with_0_rss({version => "2.0", item_params => [ title => "Foo&Bar", link => "http://www.mytld/", source => $s->[0], sourceUrl => $s->[1], ], } ); # TEST*$num_iters contains( $rss, ("\n" . "Foo&Bar\n" . "http://www.mytld/\n" . "[1]\">$s->[0]\n" . "" ), "2.0 - item - source = $s->[0] sourceUrl = $s->[1]", ); } } { my $rss = create_no_image_rss({version => "0.9"}); # TEST not_contains($rss, "", "0.9 - if a textinput was not specified it isn't there." ); } { my $rss = create_textinput_with_0_rss({version => "0.9"}); # TEST contains( $rss, ("\n" . join("", map {"<$_>0\n"} (qw(title description name link))) . "\n"), "0.9 - textinput/link == 0", ); } { my $rss = create_no_image_rss({version => "0.91"}); # TEST not_contains($rss, "", "0.9.1 - if a textinput was not specified it isn't there." ); } { my $rss = create_textinput_with_0_rss({version => "0.91"}); # TEST contains( $rss, ("\n" . join("", map {"<$_>0\n"} (qw(title description name link))) . "\n"), "0.9.1 - textinput/link == 0", ); } { my $rss = create_no_image_rss({version => "1.0"}); # TEST not_contains($rss, " "1.0"}); # TEST contains( $rss, ("\n" . join("", map {"<$_>0\n"} (qw(title description name link))) . "\n"), "1.0 - textinput/link == 0", ); # TEST contains( $rss, "\n\n", "1.0 - textinput/link == 0 and textinput rdf:resource", ); } { my $rss = create_no_image_rss({version => "2.0"}); # TEST not_contains($rss, "", "2.0 - if a textinput was not specified it isn't there." ); } { my $rss = create_textinput_with_0_rss({version => "2.0"}); # TEST contains( $rss, ("\n" . join("", map {"<$_>0\n"} (qw(title description name link))) . "\n"), "2.0 - textinput/link == 0", ); } { my $rss = create_channel_rss({version => "0.91"}); # TEST contains($rss, "\n" . "freshmeat.net\n" . "http://freshmeat.net\n" . "Linux software\n" . "\n" . "\n", "0.9.1 - if a channel/dc/language was not specified it isn't there." ); } { my $rss = create_channel_rss({ version => "0.91", channel_params => [dc => { language => "0",},], }); # TEST contains($rss, "\n" . "freshmeat.net\n" . "http://freshmeat.net\n" . "Linux software\n" . "0\n" . "\n" . "\n", "0.9.1 - channel/dc/language == 0" ); } { my $rss = create_channel_rss({ version => "0.91", channel_params => [language => "0",], }); # TEST contains($rss, "\n" . "freshmeat.net\n" . "http://freshmeat.net\n" . "Linux software\n" . "0\n" . "\n" . "\n", "0.9.1 - channel/language == 0" ); } { my $rss = create_channel_rss({version => "1.0"}); # TEST contains($rss, "\n" . "freshmeat.net\n" . "http://freshmeat.net\n" . "Linux software\n" . "\n", "1.0 - if a channel/dc/language was not specified it isn't there." ); } { my $rss = create_channel_rss({ version => "1.0", channel_params => [dc => { language => "0",},], }); # TEST contains($rss, "\n" . "freshmeat.net\n" . "http://freshmeat.net\n" . "Linux software\n" . "0\n" . "\n", "1.0 - channel/dc/language == 0" ); } { my $rss = create_channel_rss({ version => "1.0", channel_params => [language => "0",], }); # TEST contains($rss, "\n" . "freshmeat.net\n" . "http://freshmeat.net\n" . "Linux software\n" . "0\n" . "\n", "1.0 - channel/language == 0" ); } { my $rss = create_channel_rss({version => "2.0"}); # TEST contains($rss, "\n" . "freshmeat.net\n" . "http://freshmeat.net\n" . "Linux software\n" . "Sat, 07 Sep 2002 09:42:31 GMT\n" . "\n" . "\n", "2.0 - if a channel/dc/language was not specified it isn't there." ); } { my $rss = create_channel_rss({ version => "2.0", channel_params => [dc => { language => "0",},], }); # TEST contains($rss, "\n" . "freshmeat.net\n" . "http://freshmeat.net\n" . "Linux software\n" . "0\n" . "Sat, 07 Sep 2002 09:42:31 GMT\n" . "\n" . "\n", "2.0 - channel/dc/language == 0" ); } { my $rss = create_channel_rss({ version => "2.0", channel_params => [language => "0",], }); # TEST contains($rss, "\n" . "freshmeat.net\n" . "http://freshmeat.net\n" . "Linux software\n" . "0\n" . "Sat, 07 Sep 2002 09:42:31 GMT\n" . "\n" . "\n", "2.0 - channel/language == 0" ); } { my $rss = create_channel_rss({ version => "0.91", channel_params => [rating => "0",], }); # TEST contains($rss, "\n" . "freshmeat.net\n" . "http://freshmeat.net\n" . "Linux software\n" . "0\n" . "\n" . "\n", "0.9.1 - channel/rating == 0" ); } { my $rss = create_channel_rss({ version => "0.91", channel_params => [rating => "Hello", dc => {rights => "0"},], }); # TEST contains($rss, "\n" . "freshmeat.net\n" . "http://freshmeat.net\n" . "Linux software\n" . "Hello\n" . "0\n" . "\n" . "\n", "0.9.1 - channel/dc/copyright == 0" ); } { my $rss = create_channel_rss({ version => "0.91", channel_params => [rating => "Hello", copyright => "0",], }); # TEST contains($rss, "\n" . "freshmeat.net\n" . "http://freshmeat.net\n" . "Linux software\n" . "Hello\n" . "0\n" . "\n" . "\n", "0.9.1 - channel/copyright == 0" ); } { my $rss = create_channel_rss({ version => "2.0", channel_params => [dc => {rights => "0"},], }); # TEST contains($rss, "\n" . "freshmeat.net\n" . "http://freshmeat.net\n" . "Linux software\n" . "0\n" . "Sat, 07 Sep 2002 09:42:31 GMT\n" . "\n" . "\n", "2.0 - channel/dc/rights == 0" ); } { my $rss = create_channel_rss({ version => "2.0", channel_params => [copyright=> "0",], }); # TEST contains($rss, "\n" . "freshmeat.net\n" . "http://freshmeat.net\n" . "Linux software\n" . "0\n" . "Sat, 07 Sep 2002 09:42:31 GMT\n" . "\n" . "\n", "2.0 - channel/copyright == 0" ); } { my $rss = create_channel_rss({ version => "0.91", channel_params => [rating => "Hello", copyright => "Martha",docs => "0",], }); # TEST contains($rss, "\n" . "freshmeat.net\n" . "http://freshmeat.net\n" . "Linux software\n" . "Hello\n" . "Martha\n" . "0\n" . "\n" . "\n", "0.9.1 - channel/docs == 0" ); } { my $rss = create_channel_rss({ version => "2.0", channel_params => [copyright => "Martha", docs => "0",], }); # TEST contains($rss, "\n" . "freshmeat.net\n" . "http://freshmeat.net\n" . "Linux software\n" . "Martha\n" . "Sat, 07 Sep 2002 09:42:31 GMT\n" . "0\n" . "\n" . "\n", "2.0 - channel/docs == 0" ); } { my $rss = create_channel_rss({ version => "0.91", channel_params => [rating => "Hello", copyright => "Martha", docs => "MyDr. docs",dc => {publisher => 0}], }); # TEST contains($rss, "\n" . "freshmeat.net\n" . "http://freshmeat.net\n" . "Linux software\n" . "Hello\n" . "Martha\n" . "MyDr. docs\n" . "0\n" . "\n" . "\n", "0.9.1 - channel/dc/publisher == 0" ); } { my $rss = create_channel_rss({ version => "0.91", channel_params => [rating => "Hello", copyright => "Martha", docs => "MyDr. docs",managingEditor => 0], }); # TEST contains($rss, "\n" . "freshmeat.net\n" . "http://freshmeat.net\n" . "Linux software\n" . "Hello\n" . "Martha\n" . "MyDr. docs\n" . "0\n" . "\n" . "\n", "0.9.1 - channel/managingEditor == 0" ); } { my $rss = create_channel_rss({ version => "2.0", channel_params => [copyright => "Martha", docs => "MyDr. docs",managingEditor => 0], }); # TEST contains($rss, "\n" . "freshmeat.net\n" . "http://freshmeat.net\n" . "Linux software\n" . "Martha\n" . "Sat, 07 Sep 2002 09:42:31 GMT\n" . "MyDr. docs\n" . "0\n" . "\n" . "\n", "2.0 - channel/managingEditor == 0" ); } { my $rss = create_channel_rss({ version => "2.0", channel_params => [copyright => "Martha", docs => "MyDr. docs", dc => {publisher => 0}], }); # TEST contains($rss, "\n" . "freshmeat.net\n" . "http://freshmeat.net\n" . "Linux software\n" . "Martha\n" . "Sat, 07 Sep 2002 09:42:31 GMT\n" . "MyDr. docs\n" . "0\n" . "\n" . "\n", "2.0 - channel/dc/publisher == 0" ); } { my $rss = create_channel_rss({ version => "1.0", channel_params => [copyright => "Martha", dc => {publisher => 0}], }); # TEST contains($rss, "\n" . "freshmeat.net\n" . "http://freshmeat.net\n" . "Linux software\n" . "Martha\n" . "0\n" . "\n", "1.0 - channel/dc/publisher == 0" ); } { # Here we create an RSS 2.0 object and render it as 1.0 to get the # "managingEditor" field acknowledged. my $rss = create_channel_rss({ version => "2.0", channel_params => [copyright => "Martha", managingEditor => 0,], omit_date => 1, }); $rss->{output} = "1.0"; # TEST contains($rss, "\n" . "freshmeat.net\n" . "http://freshmeat.net\n" . "Linux software\n" . "Martha\n" . "0\n" . "\n", "1.0 - channel/managingEditor == 0" ); } { my $rss = create_channel_rss({ version => "0.91", channel_params => [rating => "Hello", copyright => "Martha", docs => "MyDr. docs",dc => {creator => 0}], }); # TEST contains($rss, "\n" . "freshmeat.net\n" . "http://freshmeat.net\n" . "Linux software\n" . "Hello\n" . "Martha\n" . "MyDr. docs\n" . "0\n" . "\n" . "\n", "0.9.1 - channel/dc/publisher == 0" ); } { my $rss = create_channel_rss({ version => "0.91", channel_params => [rating => "Hello", copyright => "Martha", docs => "MyDr. docs",webMaster => 0], }); # TEST contains($rss, "\n" . "freshmeat.net\n" . "http://freshmeat.net\n" . "Linux software\n" . "Hello\n" . "Martha\n" . "MyDr. docs\n" . "0\n" . "\n" . "\n", "0.9.1 - channel/webMaster == 0" ); } { my $rss = create_channel_rss({ version => "1.0", channel_params => [copyright => "Martha", dc => {creator => 0}], }); # TEST contains($rss, "\n" . "freshmeat.net\n" . "http://freshmeat.net\n" . "Linux software\n" . "Martha\n" . "0\n" . "\n", "1.0 - channel/dc/creator == 0" ); } { # Here we create an RSS 2.0 object and render it as 1.0 to get the # "managingEditor" field acknowledged. my $rss = create_channel_rss({ version => "2.0", channel_params => [copyright => "Martha", webMaster => 0,], omit_date => 1, }); $rss->{output} = "1.0"; # TEST contains($rss, "\n" . "freshmeat.net\n" . "http://freshmeat.net\n" . "Linux software\n" . "Martha\n" . "0\n" . "\n", "1.0 - channel/managingEditor == 0" ); } { my $rss = create_channel_rss({ version => "2.0", channel_params => [copyright => "Martha", docs => "MyDr. docs",webMaster => 0], }); # TEST contains($rss, "\n" . "freshmeat.net\n" . "http://freshmeat.net\n" . "Linux software\n" . "Martha\n" . "Sat, 07 Sep 2002 09:42:31 GMT\n" . "MyDr. docs\n" . "0\n" . "\n" . "\n", "2.0 - channel/webMaster == 0" ); } { my $rss = create_channel_rss({ version => "2.0", channel_params => [copyright => "Martha", docs => "MyDr. docs", dc => {creator => 0}], }); # TEST contains($rss, "\n" . "freshmeat.net\n" . "http://freshmeat.net\n" . "Linux software\n" . "Martha\n" . "Sat, 07 Sep 2002 09:42:31 GMT\n" . "MyDr. docs\n" . "0\n" . "\n" . "\n", "2.0 - channel/dc/creator == 0" ); } { my $rss = create_no_image_rss({version => "0.91"}); # TEST not_contains($rss, "", "0.91 - if skipHours was not specified it isn't there." ); } { my $rss = create_skipHours_rss({ version => "0.91", skipHours_params => [ hour => "0" ], }); # TEST contains($rss, "\n0\n\n", "0.91 - skipHours/hours == 0" ); } { my $rss = create_no_image_rss({version => "2.0"}); # TEST not_contains($rss, "", "2.0 - if skipHours was not specified it isn't there." ); } { my $rss = create_skipHours_rss({ version => "2.0", skipHours_params => [ hour => "0" ], }); # TEST contains($rss, "\n0\n\n", "2.0 - skipHours/hour == 0" ); } { my $rss = create_no_image_rss({version => "0.91"}); # TEST not_contains($rss, "", "0.91 - if skipDays was not specified it isn't there." ); } { my $rss = create_skipDays_rss({ version => "0.91", skipDays_params => [ day => "0" ], }); # TEST contains($rss, "\n0\n\n", "0.91 - skipDays/days == 0" ); } { my $rss = create_no_image_rss({version => "2.0"}); # TEST not_contains($rss, "", "2.0 - if skipDays was not specified it isn't there." ); } { my $rss = create_skipDays_rss({ version => "2.0", skipDays_params => [ day => "0" ], }); # TEST contains($rss, "\n0\n\n", "2.0 - skipDays/day == 0" ); } { my $rss = create_channel_rss({ version => "1.0", }); # TEST contains($rss, "\n" . "freshmeat.net\n" . "http://freshmeat.net\n" . "Linux software\n" . "\n", "1.0 - channel/dc/creator == 0" ); } { my $rss = create_channel_rss({ version => "1.0", channel_params => [copyright => 0,], }); # TEST contains($rss, "\n" . "freshmeat.net\n" . "http://freshmeat.net\n" . "Linux software\n" . "0\n" . "\n", "1.0 - channel/copyright == 0" ); } { my $rss = create_channel_rss({ version => "1.0", channel_params => [dc => { rights => 0},], }); # TEST contains($rss, "\n" . "freshmeat.net\n" . "http://freshmeat.net\n" . "Linux software\n" . "0\n" . "\n", "1.0 - channel/dc/rights == 0" ); } { my $rss = create_channel_rss({ version => "1.0", channel_params => [dc => { title => 0},], }); # TEST contains($rss, "\n" . "freshmeat.net\n" . "http://freshmeat.net\n" . "Linux software\n" . "0\n" . "\n", "1.0 - channel/dc/title == 0" ); } { my $rss = create_channel_rss({ version => "1.0", channel_params => [syn => { updateBase=> 0},], }); # TEST contains($rss, "\n" . "freshmeat.net\n" . "http://freshmeat.net\n" . "Linux software\n" . "0\n" . "\n", "1.0 - channel/syn/updateBase == 0" ); } { my $rss = create_rss_1({version => "1.0", image_params => [ dc => { subject => 0, }] }); # TEST contains ($rss, (qq{\nfreshmeat.net\n} . qq{0\nhttp://freshmeat.net/\n} . qq{0\n}), "1.0 - Checking for image/dc/subject == 0"); } { my $rss = create_item_with_0_rss({version => "1.0", item_params => [ description => "Hello There", about => "Yowza", dc => { subject => 0,}, ], }); # TEST contains( $rss, "\n0\nhttp://rss.mytld/\nHello There\n0\n", "1.0 - item/dc/subject == 0", ); } { my $rss = create_textinput_with_0_rss({version => "1.0", textinput_params => [dc => { subject => 0,},], }); # TEST contains( $rss, ("\n" . join("", map {"<$_>0\n"} (qw(title description name link dc:subject))) . "\n"), "1.0 - textinput/dc/subject == 0", ); } { # TEST:$num_fields=3; foreach my $field (qw(category generator ttl)) { # TEST:$num_dc=2; foreach my $dc (1,0) { my $rss = create_channel_rss({ version => "2.0", channel_params => [$dc ? (dc => {$field => 0 }) : ($field => 0) ], }); # TEST*$num_fields*$num_dc contains($rss, "\n" . "freshmeat.net\n" . "http://freshmeat.net\n" . "Linux software\n" . "Sat, 07 Sep 2002 09:42:31 GMT\n" . "<$field>0\n" . "\n" . "\n", "2.0 - Testing for fields with an optional dc being 0. (dc=$dc,field=$field)" ); } } } { my $rss = create_channel_rss({ version => "0.91", channel_params => [pubDate => "There&Everywhere"], }); # TEST contains($rss, "\n" . "freshmeat.net\n" . "http://freshmeat.net\n" . "Linux software\n" . "</pubDate><hello>There&amp;Everywhere</hello>\n" . "\n" . "\n", "0.9.1 - channel/pubDate Markup Injection" ); } { my $rss = create_channel_rss({ version => "0.91", channel_params => [lastBuildDate => "There&Everywhere"], }); # TEST contains($rss, "\n" . "freshmeat.net\n" . "http://freshmeat.net\n" . "Linux software\n" . "</pubDate><hello>There&amp;Everywhere</hello>\n" . "\n" . "\n", "0.9.1 - channel/lastBuildDate Markup Injection" ); } { my $rss = create_channel_rss({ version => "1.0", channel_params => [ dc => { date => "There&Everywhere" }, ], }); # TEST contains($rss, "\n" . "freshmeat.net\n" . "http://freshmeat.net\n" . "Linux software\n" . "</pubDate><hello>There&amp;Everywhere</hello>\n" . "\n", "1.0 - dc/date Markup Injection" ); } { my $rss = create_channel_rss({version => "2.0", channel_params => [pubDate => "There&Everywhere"], omit_date => 1, }); # TEST contains($rss, "\n" . "freshmeat.net\n" . "http://freshmeat.net\n" . "Linux software\n" . "</pubDate><hello>There&amp;Everywhere</hello>\n" . "\n" . "\n", "2.0 - channel/pubDate Markup Injection" ); } { my $rss = create_channel_rss({version => "2.0", channel_params => [lastBuildDate => "There&Everywhere"], omit_date => 1, }); # TEST contains($rss, "\n" . "freshmeat.net\n" . "http://freshmeat.net\n" . "Linux software\n" . "</pubDate><hello>There&amp;Everywhere</hello>\n" . "\n" . "\n", "2.0 - channel/lastBuildDate Markup Injection" ); } { my $rss = create_rss_with_image_w_undef_link({version => "0.9"}); # TEST contains ($rss, qq{\nfreshmeat.net\n0\n\n}, "Image with undefined link does not render the Image - RSS version 0.9" ); } { my $rss = create_rss_with_image_w_undef_link({version => "1.0"}); # TEST contains ($rss, qq{\nfreshmeat.net\n} . qq{0\n\n}, "Image with undefined link does not render the Image - RSS version 1.0" ); } { my $rss = create_channel_rss({ version => "1.0", channel_params => [about => "http://xml-rss-hackers.tld/"], }); # TEST contains($rss, "\n" . "freshmeat.net\n" . "http://freshmeat.net\n" . "Linux software\n" . "\n", "1.0 - channel/about overrides the rdf:about attribute." ); } { my $rss = create_channel_rss({ version => "1.0", channel_params => [ taxo => ["Foo", "Bar", "QuGof", "Lambda&Delta"], ], }); # TEST contains($rss, "\n" . "freshmeat.net\n" . "http://freshmeat.net\n" . "Linux software\n" . qq{\n \n} . qq{ \n} . qq{ \n} . qq{ \n} . qq{ \n} . qq{ \n\n} . "\n", "1.0 - taxo topics" ); } { my $rss = create_channel_rss({ version => "1.0", channel_params => [ admin => { 'foobar' => "Quod", }, ], }); # TEST contains($rss, "\n" . "freshmeat.net\n" . "http://freshmeat.net\n" . "Linux software\n" . "Quod\n" . "\n", '1.0 - channel/[module] with unknown key' ); } { my $rss = create_channel_rss({ version => "1.0", channel_params => [ eloq => { 'grow' => "There", }, ], }); $rss->add_module(prefix => "eloq", uri => "http://eloq.tld2/Gorj/"); # TEST contains($rss, "\n" . "freshmeat.net\n" . "http://freshmeat.net\n" . "Linux software\n" . "There\n" . "\n", '1.0 - channel/[module] with new module' ); } { my $rss = create_rss_1({ version => "1.0", image_params => [ admin => { 'foobar' => "Quod", }, ], }); # TEST contains($rss, "\n" . "freshmeat.net\n" . "0\n" . "http://freshmeat.net/\n" . "Quod\n" . "", '1.0 - image/[module] with unknown key' ); } { my $rss = create_rss_1({ version => "1.0", image_params => [ eloq => { 'grow' => "There", }, ], }); $rss->add_module(prefix => "eloq", uri => "http://eloq.tld2/Gorj/"); # TEST contains($rss, "\n" . "freshmeat.net\n" . "0\n" . "http://freshmeat.net/\n" . "There\n" . "", '1.0 - image/[module] with new module' ); } { my $rss = create_rss_1({ version => "1.0", image_params => [ admin => { 'generatorAgent' => "Spozilla 5.5", }, ], }); # TEST contains($rss, "\n" . "freshmeat.net\n" . "0\n" . "http://freshmeat.net/\n" . "\n" . "", '1.0 - image/[module] with known module' ); } { my $rss = create_channel_rss({ version => "1.0", }); $rss->add_item( title => "In the Jungle", link => "http://jungle.tld/Enter/", taxo => ["Foo","Loom", "", "Yok&Dol"], ); # TEST contains($rss, "\n" . "In the Jungle\n" . "http://jungle.tld/Enter/\n" . qq{\n} . qq{ \n} . qq{ \n} . qq{ \n} . qq{ \n} . qq{ \n} . qq{ \n} . qq{\n} . "\n", "1.0 - item/taxo:topics (with escaping)" ); } ## Test the RSS 1.0 items' ad-hoc modules support. { my $rss = create_item_rss({ version => "1.0", item_params => [ admin => { 'foobar' => "Quod", }, ], }); # TEST contains($rss, "\n" . "Freecell Solver\n" . "http://fc-solve.berlios.de/\n" . "Quod\n" . "", '1.0 - item/[module] with unknown key' ); } { my $rss = create_item_rss({ version => "1.0", item_params => [ eloq => { 'grow' => "There", }, ], }); $rss->add_module(prefix => "eloq", uri => "http://eloq.tld2/Gorj/"); # TEST contains($rss, "\n" . "Freecell Solver\n" . "http://fc-solve.berlios.de/\n" . "There\n" . "", '1.0 - item/[module] with new module' ); } { my $rss = create_item_rss({ version => "1.0", item_params => [ admin => { 'generatorAgent' => "Spozilla 5.5", }, ], }); # TEST contains($rss, "\n" . "Freecell Solver\n" . "http://fc-solve.berlios.de/\n" . "\n" . "", '1.0 - item/[module] with known module' ); } { my $rss = create_textinput_with_0_rss({version => "1.0", textinput_params => [admin => { 'foobar' => "Quod", },], }); # TEST contains( $rss, ("\n" . join("", map {"<$_>0\n"} (qw(title description name link))) . "Quod\n" . "\n" ), "1.0 - textinput/[module]", ); } { my $rss = create_channel_rss({ version => "2.0", channel_params => [ admin => { 'generatorAgent' => "Spozilla 5.5", }, ], }); $rss->add_module(prefix => "admin", uri => "http://webns.net/mvcb/"); # TEST contains($rss, "\n" . "freshmeat.net\n" . "http://freshmeat.net\n" . "Linux software\n" . "Sat, 07 Sep 2002 09:42:31 GMT\n" . "\n" . "\n" . "\n", '2.0 - channel/[module] with known module and key' ); } { my $rss = create_channel_rss({ version => "2.0", channel_params => [ admin => { 'foobar' => "Quod", }, ], }); $rss->add_module(prefix => "admin", uri => "http://webns.net/mvcb/"); # TEST contains($rss, "\n" . "freshmeat.net\n" . "http://freshmeat.net\n" . "Linux software\n" . "Sat, 07 Sep 2002 09:42:31 GMT\n" . "Quod\n" . "\n" . "\n", '2.0 - channel/[module] with unknown key' ); } { my $rss = create_channel_rss({ version => "2.0", channel_params => [ eloq => { 'grow' => "There", }, ], }); $rss->add_module(prefix => "eloq", uri => "http://eloq.tld2/Gorj/"); # TEST contains($rss, "\n" . "freshmeat.net\n" . "http://freshmeat.net\n" . "Linux software\n" . "Sat, 07 Sep 2002 09:42:31 GMT\n" . "There\n" . "\n" . "\n", '2.0 - channel/[module] with new module' ); } ## Testing the RSS 2.0 Image Modules Support { my $rss = create_rss_1({ version => "2.0", image_params => [ admin => { 'foobar' => "Quod", }, ], }); $rss->add_module(prefix => "admin", uri => "http://webns.net/mvcb/"); # TEST contains($rss, "\n" . "freshmeat.net\n" . "0\n" . "http://freshmeat.net/\n" . "Quod\n" . "\n", '2.0 - image/[module] with unknown key' ); } { my $rss = create_rss_1({ version => "2.0", image_params => [ eloq => { 'grow' => "There", }, ], }); $rss->add_module(prefix => "eloq", uri => "http://eloq.tld2/Gorj/"); # TEST contains($rss, "\n" . "freshmeat.net\n" . "0\n" . "http://freshmeat.net/\n" . "There\n" . "", '2.0 - image/[module] with new module' ); } { my $rss = create_rss_1({ version => "2.0", image_params => [ admin => { 'generatorAgent' => "Spozilla 5.5", }, ], }); $rss->add_module(prefix => "admin", uri => "http://webns.net/mvcb/"); # TEST contains($rss, "\n" . "freshmeat.net\n" . "0\n" . "http://freshmeat.net/\n" . "\n" . "", '2.0 - image/[module] with known module' ); } ## Test the RSS 2.0 items' ad-hoc modules support. { my $rss = create_item_rss({ version => "2.0", item_params => [ admin => { 'foobar' => "Quod", }, ], }); $rss->add_module(prefix => "admin", uri => "http://webns.net/mvcb/"); # TEST contains($rss, "\n" . "Freecell Solver\n" . "http://fc-solve.berlios.de/\n" . "Quod\n" . "", '2.0 - item/[module] with unknown key' ); } { my $rss = create_item_rss({ version => "2.0", item_params => [ eloq => { 'grow' => "There", }, ], }); $rss->add_module(prefix => "eloq", uri => "http://eloq.tld2/Gorj/"); # TEST contains($rss, "\n" . "Freecell Solver\n" . "http://fc-solve.berlios.de/\n" . "There\n" . "", '2.0 - item/[module] with new module' ); } { my $rss = create_item_rss({ version => "2.0", item_params => [ admin => { 'generatorAgent' => "Spozilla 5.5", }, ], }); $rss->add_module(prefix => "admin", uri => "http://webns.net/mvcb/"); # TEST contains($rss, "\n" . "Freecell Solver\n" . "http://fc-solve.berlios.de/\n" . "\n" . "", '2.0 - item/[module] with known module' ); } ## Test the RSS 2.0 skipping-items condition. { my $rss = create_rss_without_item({ version => "2.0", }); $rss->add_item( link => "http://freshmeat.net/news/1999/06/21/930003829.html" ); # TEST not_contains($rss, "\n", '2.0 - Item without description or title is skipped' ); } ## Test the RSS 2.0 "2.0", item_params => [ title => "Foo&Bar", link => "http://www.mylongtldyeahbaby/", source => $s->[0], sourceUrl => $s->[1], ], } ); # TEST*$num_iters contains( $rss, ("\n" . "Foo&Bar\n" . "http://www.mylongtldyeahbaby/\n" . "" ), "2.0 - item - Source and/or Source URL are not defined", ); } } { # Here we create an RSS 2.0 object and render it as the output # version "3.5" in order to test that version 1.0 is the default # version for output. my $rss = create_channel_rss({ version => "2.0", channel_params => [copyright => "Martha", managingEditor => 0,], omit_date => 1, }); $rss->{output} = "3.5"; # TEST contains($rss, "\n" . "freshmeat.net\n" . "http://freshmeat.net\n" . "Linux software\n" . "Martha\n" . "0\n" . "\n", "Unknown version renders as 1.0" ); } { my $version = "0.91"; my $rss = create_rss_1({ version => $version, image_link => "Hello ", rss_args => ["encode_output" => 0], }); # TEST contains($rss, "\nfreshmeat.net\n0\nHello \n\n", "Testing encode_output is false", ); } { my $rss = create_channel_rss({ version => "0.91", image_link => undef, channel_params => [ title => undef ], }); my $output; eval { $output = $rss->as_string(); }; # TEST ok ($@ =~ m{\A\$text is undefined in XML::RSS::_encode}, "Undefined string throws an exception" ); } { my $rss = create_channel_rss({ version => "0.91", image_link => undef, channel_params => [ title => "Hello and ]]>"], }); # TEST contains($rss, "Hello and <![CDATA[Aloha<&>]]>", ); } ################ ### RSS Parsing Tests: ### We generate RSS and test that we get the same results. ################ sub parse_generated_rss { my $args = shift; my $gen_func = $args->{'func'}; my $rss_generator = $gen_func->($args); $rss_generator->{output} = $args->{version}; my $output = $rss_generator->as_string(); if ($args->{postproc}) { $args->{postproc}->(\$output); } my $parser = XML::RSS->new(version => $args->{version}); $parser->parse($output); return $parser; } { my $rss = parse_generated_rss({ func => \&create_textinput_with_0_rss, version => "0.9", textinput_params => [ description => "Welcome to the Jungle.", 'link' => "http://fooque.tld/", 'title' => "The Jungle of the City", 'name' => "There's more than one way to do it.", ], postproc => sub { for (${shift()}) { s{(]*(>)}{}; s{}{}; } }, }); # TEST is ($rss->{textinput}->{description}, "Welcome to the Jungle.", "0.9 parse - textinput/description", ); # TEST is ($rss->{textinput}->{link}, "http://fooque.tld/", "0.9 parse - textinput/link", ); # TEST is ($rss->{textinput}->{title}, "The Jungle of the City", "0.9 parse - textinput/title", ); # TEST is ($rss->{textinput}->{name}, "There's more than one way to do it.", "0.9 parse - textinput/name", ); } { my $rss_parser = parse_generated_rss( { func => \&create_textinput_with_0_rss, version => "0.9", textinput_params => [ description => "Welcome to the Jungle.", 'link' => "http://fooque.tld/", 'title' => "The Jungle of the City", 'name' => "There's more than one way to do it.", ], postproc => sub { for (${shift()}) { s{(]*(>)}{}; s{}{}; s{<(/?)textinput>}{<$1textInput>}g; } }, } ); # TEST is ($rss_parser->{textinput}->{description}, "Welcome to the Jungle.", "0.9 parse - textinput/description", ); # TEST is ($rss_parser->{textinput}->{link}, "http://fooque.tld/", "Parse textInput (with capital I) - textinput/link", ); # TEST is ($rss_parser->{textinput}->{title}, "The Jungle of the City", "Parse textInput (with capital I) - textinput/title", ); # TEST is ($rss_parser->{textinput}->{name}, "There's more than one way to do it.", "Parse textInput (with capital I) - textinput/name", ); } { my $rss_parser = parse_generated_rss( { func => \&create_textinput_with_0_rss, version => "0.9", textinput_params => [ description => "Welcome to the Jungle.", 'link' => "http://fooque.tld/", 'title' => "The Jungle of the City", 'name' => "There's more than one way to do it.", ], postproc => sub { for (${shift()}) { s{<(/?)textinput>}{<$1textInput>}g } }, } ); # TEST is ($rss_parser->{textinput}->{description}, "Welcome to the Jungle.", "0.9 parse - textinput/description", ); # TEST is ($rss_parser->{textinput}->{link}, "http://fooque.tld/", "Parse textInput (with capital I) - textinput/link", ); # TEST is ($rss_parser->{textinput}->{title}, "The Jungle of the City", "Parse textInput (with capital I) - textinput/title", ); # TEST is ($rss_parser->{textinput}->{name}, "There's more than one way to do it.", "Parse textInput (with capital I) - textinput/name", ) } { my $rss_parser = parse_generated_rss( { func => \&create_skipHours_rss, version => "0.91", skipHours_params => [ hour => "5" ], } ); # TEST is ($rss_parser->{skipHours}->{hour}, "5", "Parse 0.91 - skipHours/hour", ); } { my $rss_parser = parse_generated_rss( { func => \&create_skipHours_rss, version => "2.0", skipHours_params => [ hour => "5" ], } ); # TEST is ($rss_parser->{skipHours}->{hour}, "5", "Parse 2.0 - skipHours/hour", ); } ## Test the skipDays parsing. { my $rss_parser = parse_generated_rss( { func => \&create_skipDays_rss, version => "0.91", skipDays_params => [ day => "5" ], } ); # TEST is ($rss_parser->{skipDays}->{day}, "5", "Parse 0.91 - skipDays/day", ); } { my $rss_parser = parse_generated_rss( { func => \&create_skipDays_rss, version => "2.0", skipDays_params => [ day => "5" ], } ); # TEST is ($rss_parser->{skipDays}->{day}, "5", "Parse 2.0 - skipDays/day", ); } { my $rss_parser = XML::RSS->new(version => "2.0"); $rss_parser->parse(<<'EOF'); Test 2.0 Feed http://example.com/ en-us Copyright 2002 2007-01-19T14:21:43+0200 2007-01-19T14:21:43+0200 http://backend.userland.com/rss editor@example.com webmaster@example.com MyCategory XML::RSS Test 60 Test Image http://example.com/example.gif http://example.com/ 25 Test Image Hi there! This is an item http://example.com/2007/01/19 Yadda yadda yadda - R&D; joeuser@example.com MyCategory http://example.com/2007/01/19/comments.html http://example.com/2007/01/19 Fri 19 Jan 2007 02:21:43 PM IST GMT my brain EOF # TEST is ($rss_parser->{image}->{"http://foo.tld/foobar/"}->{hello}, "Hi there!", "Parsing 2.0 - element in a different namespace contained in image", ); } { my $rss_parser = XML::RSS->new(version => "1.0"); $rss_parser->parse(<<'EOF'); Test 1.0 Feed http://example.com/ To lead by example 2007-01-19T14:21:18+0200 Test Image http://example.com/example.gif http://example.com/ Aye Karamba This is an item http://example.com/2007/01/19 Yadda & yadda & yadda joeuser@example.com Search Search for an example q http://example.com/search.pl EOF # TEST is ($rss_parser->{image}->{""}->{foo}, "Aye Karamba", "Parsing 1.0 - element in a null namespace contained in image", ); } { my $rss_parser = XML::RSS->new(version => "2.0"); $rss_parser->parse(<<'EOF'); Test 2.0 Feed http://example.com/ en-us Copyright 2002 2007-01-19T14:21:43+0200 2007-01-19T14:21:43+0200 http://backend.userland.com/rss editor@example.com webmaster@example.com MyCategory XML::RSS Test 60 Test Image http://example.com/example.gif http://example.com/ 25 Test Image This is an item http://example.com/2007/01/19 Yadda yadda yadda - R&D; joeuser@example.com MyCategory http://example.com/2007/01/19/comments.html http://example.com/2007/01/19 Fri 19 Jan 2007 02:21:43 PM IST GMT my brain Hi there! EOF # TEST is ($rss_parser->{items}->[0]->{"http://foo.tld/foobar/"}->{hello}, "Hi there!", "Parsing 2.0 - element in a different namespace contained in an item", ); } { my $rss_parser = XML::RSS->new(version => "1.0"); $rss_parser->parse(<<'EOF'); Test 1.0 Feed http://example.com/ To lead by example 2007-01-19T14:21:18+0200 Test Image http://example.com/example.gif http://example.com/ This is an item http://example.com/2007/01/19 Yadda & yadda & yadda joeuser@example.com Aye Karamba Search Search for an example q http://example.com/search.pl EOF # TEST is ($rss_parser->{items}->[0]->{""}->{foo}, "Aye Karamba", "Parsing 1.0 - element in a null namespace contained in image", ); } { my $rss_parser = XML::RSS->new(version => "2.0"); $rss_parser->parse(<<'EOF'); Test 2.0 Feed http://example.com/ en-us Copyright 2002 2007-01-19T14:21:43+0200 2007-01-19T14:21:43+0200 http://backend.userland.com/rss editor@example.com webmaster@example.com MyCategory XML::RSS Test 60 Test Image http://example.com/example.gif http://example.com/ 25 Test Image This is an item http://example.com/2007/01/19 Yadda yadda yadda - R&D; joeuser@example.com MyCategory http://example.com/2007/01/19/comments.html http://example.com/2007/01/19 Fri 19 Jan 2007 02:21:43 PM IST GMT my brain Search Search for an example q http://example.com/search.pl Show Baloon EOF # TEST is ($rss_parser->{textinput}->{"http://foo.tld/foobar/"}->{hello}, "Show Baloon", "Parsing 2.0 - element in a different namespace contained in a textinput", ); } { my $rss_parser = XML::RSS->new(version => "1.0"); $rss_parser->parse(<<'EOF'); Test 1.0 Feed http://example.com/ To lead by example 2007-01-19T14:21:18+0200 Test Image http://example.com/example.gif http://example.com/ This is an item http://example.com/2007/01/19 Yadda & yadda & yadda joeuser@example.com Search Search for an example q http://example.com/search.pl Priceless EOF # TEST is ($rss_parser->{textinput}->{""}->{foo}, "Priceless", "Parsing 1.0 - element in a null namespace contained in a textinput", ); } { my $rss_parser = XML::RSS->new(version => "2.0"); $rss_parser->parse(<<'EOF'); Test 2.0 Feed http://example.com/ en-us Copyright 2002 2007-01-19T14:21:43+0200 2007-01-19T14:21:43+0200 http://backend.userland.com/rss editor@example.com webmaster@example.com MyCategory XML::RSS Test 60 The RSS Must Flow Test Image http://example.com/example.gif http://example.com/ 25 Test Image This is an item http://example.com/2007/01/19 Yadda yadda yadda - R&D; joeuser@example.com MyCategory http://example.com/2007/01/19/comments.html http://example.com/2007/01/19 Fri 19 Jan 2007 02:21:43 PM IST GMT my brain Search Search for an example q http://example.com/search.pl EOF # TEST is ($rss_parser->{channel}->{"http://foo.tld/foobar/"}->{hello}, "The RSS Must Flow", "Parsing 2.0 - element in a different namespace contained in a channel", ); } { my $rss_parser = XML::RSS->new(version => "1.0"); $rss_parser->parse(<<'EOF'); Test 1.0 Feed http://example.com/ To lead by example 2007-01-19T14:21:18+0200 Placebo is here Test Image http://example.com/example.gif http://example.com/ This is an item http://example.com/2007/01/19 Yadda & yadda & yadda joeuser@example.com Search Search for an example q http://example.com/search.pl EOF # TEST is ($rss_parser->{channel}->{""}->{foo}, "Placebo is here", "Parsing 1.0 - element in a null namespace contained in a channel", ); } { my $rss_parser = XML::RSS->new(version => "1.0"); $rss_parser->parse(<<'EOF'); freshmeat.net http://freshmeat.net Linux software GTKeyboard 0.85 http://freshmeat.net/news/1999/06/21/930003829.html In the Jungle http://jungle.tld/Enter/ EOF # TEST is_deeply ($rss_parser->{items}->[1]->{taxo}, ["Foo", "Loom", "Hello", "myowA"], "Parsing 1.0 - taxo items", ); } { my $rss_parser = XML::RSS->new(version => "1.0"); $rss_parser->parse(<<'EOF'); freshmeat.net http://freshmeat.net Linux software GTKeyboard 0.85 http://freshmeat.net/news/1999/06/21/930003829.html In the Jungle http://jungle.tld/Enter/ EOF # TEST is_deeply ($rss_parser->{items}->[1]->{taxo}, ["Everybody", "needs", "a", "[[[HUG]]]"], "Parsing 1.0 - taxo bag in with junk elements", ); } { my $rss_parser = XML::RSS->new(version => "1.0"); $rss_parser->parse(<<'EOF'); freshmeat.net http://freshmeat.net Linux software GTKeyboard 0.85 http://freshmeat.net/news/1999/06/21/930003829.html In the Jungle http://jungle.tld/Enter/ EOF # TEST is_deeply ($rss_parser->{channel}->{taxo}, ["Elastic", "Plastic", "stochastic", "dynamic^^K"], "Parsing 1.0 - taxo items in channel", ); } { my $rss_parser = XML::RSS->new(version => "1.0"); $rss_parser->parse(<<'EOF'); freshmeat.net http://freshmeat.net Linux software GTKeyboard 0.85 http://freshmeat.net/news/1999/06/21/930003829.html In the Jungle http://jungle.tld/Enter/ EOF # TEST is_deeply ($rss_parser->{channel}->{taxo}, ["Elastic", "Plastic", "stochastic", "dynamic^^K"], "Parsing 1.0 - taxo items in channel with junk items", ); } { my $rss_parser = XML::RSS->new(version => "1.0"); $rss_parser->parse(<<'EOF'); freshmeat.net http://freshmeat.net Linux software GTKeyboard 0.85 http://freshmeat.net/news/1999/06/21/930003829.html In the Jungle http://jungle.tld/Enter/ Gow EOF # TEST is ($rss_parser->{items}->[1]->{"http://webns.net/mvcb/"}->{hello}, "Gow", "Parsing 1.0 - Elements inside that don't exist in \%rdf_resource_fields", ); } { my $rss_parser = XML::RSS->new(version => "1.0"); $rss_parser->parse(<<'EOF'); freshmeat.net http://freshmeat.net Linux software Gow GTKeyboard 0.85 http://freshmeat.net/news/1999/06/21/930003829.html In the Jungle http://jungle.tld/Enter/ EOF # TEST ok ((!grep { exists($_->{"http://webns.net/mvcb/"}->{generatorAgent}) } @{$rss_parser->{items}}), "Parsing 1.0 - Elements that exist in \%rdf_resource_fields but not inside item", ); } { my $rss_parser = XML::RSS->new(version => "1.0"); $rss_parser->parse(<<'EOF'); freshmeat.net http://freshmeat.net Linux software GTKeyboard 0.85 http://freshmeat.net/news/1999/06/21/930003829.html In the Jungle http://jungle.tld/Enter/ EOF # TEST ok ((!grep { exists($_->{enclosure}) } @{$rss_parser->{items}}), "Parsing 1.0 - Testing \%empty_ok_elements", ); } { my $rss_parser = XML::RSS->new(version => "1.0"); $rss_parser->parse(<<'EOF'); freshmeat.net http://freshmeat.net Linux software GTKeyboard 0.85 http://freshmeat.net/news/1999/06/21/930003829.html In the Jungle http://jungle.tld/Enter/ EOF # TEST is (scalar(@{$rss_parser->{items}}), 1, "Parse 1.0 with item in a different NS - There is 1 item"); # TEST is ($rss_parser->{items}->[0]->{title}, "GTKeyboard 0.85", "Parse 1.0 with item in a different NS - it is not the item in the other NS"); } { my $rss_parser = XML::RSS->new(version => "1.0"); $rss_parser->parse(<<'EOF'); freshmeat.net http://freshmeat.net Linux software In the Jungle http://jungle.tld/Enter/ EOF # TEST is (scalar(@{$rss_parser->{items}}), 0, "Parse 1.0 with item in null namespace"); } { my $rss_parser = XML::RSS->new(version => "1.0"); $rss_parser->parse(<<'EOF'); Test 1.0 Feed http://example.com/ To lead by example 2007-01-19T14:21:18+0200 Test Image http://example.com/example.gif http://example.com/ 5 Sep 2006 This is an item http://example.com/2007/01/19 Yadda & yadda & yadda joeuser@example.com Search Search for an example q http://example.com/search.pl EOF # TEST is ($rss_parser->{image}->{dc}->{date}, "5 Sep 2006", "Parsing 1.0 - Known module in image", ); } { my $rss_parser = XML::RSS->new(version => "1.0"); $rss_parser->parse(<<'EOF'); Test 1.0 Feed http://example.com/ To lead by example 2007-01-19T14:21:18+0200 Test Image http://example.com/example.gif http://example.com/ This is an item http://example.com/2007/01/19 Yadda & yadda & yadda joeuser@example.com Search Search for an example q http://example.com/search.pl 5 May 1977 EOF # TEST is ($rss_parser->{textinput}->{dc}->{date}, "5 May 1977", "Parsing 1.0 - Known module in a textinput", ); } { my $rss_parser = XML::RSS->new(version => "2.0"); my $xml_text = <<'EOF'; Test 2.0 Feed http://example.com/ en-us Copyright 2002 2007-01-19T14:21:43+0200 2007-01-19T14:21:43+0200 http://backend.userland.com/rss editor@example.com webmaster@example.com MyCategory XML::RSS Test 60 Test Image http://example.com/example.gif http://example.com/ 25 Test Image Hi there! This is an item http://example.com/2007/01/19 Yadda yadda yadda - R&D; joeuser@example.com MyCategory http://example.com/2007/01/19/comments.html http://example.com/2007/01/19 Fri 19 Jan 2007 02:21:43 PM IST GMT my brain EOF eval { $rss_parser->parse($xml_text); }; # TEST ok ($@ =~ m{\AMalformed RSS}, "Checking for thrown exception on missing version attribute" ); } { my $rss_parser = XML::RSS->new(version => "1.0"); my $xml_text = <<'EOF'; Test 1.0 Feed http://example.com/ To lead by example 2007-01-19T14:21:18+0200 Test Image http://example.com/example.gif http://example.com/ This is an item http://example.com/2007/01/19 Yadda & yadda & yadda joeuser@example.com Search Search for an example q http://example.com/search.pl 5 May 1977 EOF eval { $rss_parser->parse($xml_text); }; # TEST ok ($@ =~ m{\AMalformed RSS: invalid version}, "Checking for thrown exception on missing version attribute" ); } { my $rss_parser = XML::RSS->new(version => "1.0"); $rss_parser->parse(<<'EOF'); freshmeat.net http://freshmeat.net Linux software GTKeyboard 0.85 http://freshmeat.net/news/1999/06/21/930003829.html EOF # TEST is (scalar(@{$rss_parser->{items}}), 1, "Parse 1.0 with nested "); } { my $rss_parser = XML::RSS->new(version => "2.0"); my $xml_text = <<'EOF'; Test 2.0 Feed http://example.com/ Lambda EOF $rss_parser->parse($xml_text); my $channel = $rss_parser->{channel}; # Sanitize the channel out of uninitialised keys. foreach my $field (qw( category channel cloud copyright docs generator image language lastBuildDate managingEditor pubDate skipDays skipHours textinput ttl webMaster )) { delete $channel->{$field}; } # TEST is_deeply($channel, { title => "Test 2.0 Feed", link => "http://example.com/", description => "Lambda", "http://purl.org/rss/1.0/modules/annotate/" => { reference => "Aloha", }, }, "Testing for non-moduled-namespaced element inside the channel." ); } { my $rss_parser = XML::RSS->new(version => "2.0"); my $xml_text = <<'EOF'; Test 2.0 Feed http://example.com/ Lambda This is an item http://example.com/2007/01/19 Yadda yadda yadda joeuser@example.com EOF $rss_parser->parse($xml_text); my $item = $rss_parser->{items}->[0]; # Sanitize the channel out of uninitialised keys. foreach my $field (qw( item )) { delete $item->{$field}; } # TEST is_deeply($item, { title => "This is an item", link => "http://example.com/2007/01/19", description => "Yadda yadda yadda", author => "joeuser\@example.com", "http://purl.org/rss/1.0/modules/annotate/" => { reference => "Aloha", }, }, "Testing for non-moduled-namespaced element inside an item." ); } { my $rss_parser = XML::RSS->new(version => "1.0"); $rss_parser->parse(<<'EOF'); Test 1.0 Feed http://example.com/ To lead by example 2007-01-19T14:21:18+0200 Test Image http://example.com/example.gif http://example.com/ 5 Sep 2006 This is an item http://example.com/2007/01/19 Yadda & yadda & yadda joeuser@example.com Search Search for an example q http://example.com/search.pl EOF # TEST is ($rss_parser->{items}->[0]->{admin}->{generatorAgent}, "XmlRssGenKon", "Parsing 1.0 - known module rdf_resource_field", ); } { my $rss = create_item_rss( { version => "2.0", item_params => [ media => { title => "media title", text => "media text", content => { url => "http://somrurl.org/img/foo.jpg", type => "image/jpeg", height => "100", width => "100", }, }, ], } ); $rss->add_module(prefix=>'media', uri=>'http://search.yahoo.com/mrss/'); # TEST contains($rss, qq{\n}, "namespaces with attributes are rendered correctly. (bug #25336)" ); }