1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
|
#!/usr/bin/perl
# Test the add_item(mode => "insert")
use strict;
use warnings;
use Test::More tests => 3;
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 create_rss
{
my $rss = XML::RSS->new(version => "2.0");
$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;
}
{
my $rss = create_rss();
$rss->add_item(
title => "gcc 10.0.10",
link => "http://gcc-compiler.tld/",
);
# TEST
contains($rss,
qq{<item>\n<title>GTKeyboard 0.85</title>\n} .
qq{<link>http://freshmeat.net/news/1999/06/21/930003829.html</link>\n} .
qq{</item>\n} .
qq{<item>\n<title>gcc 10.0.10</title>\n} .
qq{<link>http://gcc-compiler.tld/</link>\n} .
qq{</item>\n},
"Checking for second item after first item when add_item without mode."
);
}
{
my $rss = create_rss();
$rss->add_item(
mode => "append",
title => "gcc 10.0.10",
link => "http://gcc-compiler.tld/",
);
# TEST
contains($rss,
qq{<item>\n<title>GTKeyboard 0.85</title>\n} .
qq{<link>http://freshmeat.net/news/1999/06/21/930003829.html</link>\n} .
qq{</item>\n} .
qq{<item>\n<title>gcc 10.0.10</title>\n} .
qq{<link>http://gcc-compiler.tld/</link>\n} .
qq{</item>\n},
"Checking for second item after first item when add_item with mode == append."
);
}
{
my $rss = create_rss();
$rss->add_item(
mode => "insert",
title => "gcc 10.0.10",
link => "http://gcc-compiler.tld/",
);
# TEST
contains($rss,
qq{<item>\n<title>gcc 10.0.10</title>\n} .
qq{<link>http://gcc-compiler.tld/</link>\n} .
qq{</item>\n} .
qq{<item>\n<title>GTKeyboard 0.85</title>\n} .
qq{<link>http://freshmeat.net/news/1999/06/21/930003829.html</link>\n} .
qq{</item>\n},
"Checking for second item before first item when add_item with mode == insert."
);
}
|