Refactor SC tests, separating encodings out into their own test file. TEST_ENCODINGS=1 to run this new test. 8/13 tests fail.

This commit is contained in:
Colin Kuskie 2010-08-24 15:24:22 -07:00
parent 406b8219c3
commit f39a13912e
14 changed files with 293 additions and 151 deletions

View file

@ -163,16 +163,18 @@ sub generateFeed {
}
my $cache = WebGUI::Cache->new($self->session, $url, "RSS");
my $value = $cache->get;
#warn "got this: $value\n";
unless ($value) {
$value = $cache->setByHTTP($url, $self->get("cacheTimeout"));
$newlyCached = 1;
}
#warn "got this: $value\n";
# if the content can be downgraded, it is either valid latin1 or didn't have
# an HTTP Content-Encoding header. In the second case, XML::FeedPP will take
# care of any encoding specified in the XML prolog
utf8::downgrade($value, 1);
utf8::downgrade($value, 1) ? 1 : 0;
eval {
my $singleFeed = XML::FeedPP->new($value, utf8_flag => 1, -type => 'string', @opt);
my $singleFeed = XML::FeedPP->new($value, utf8_flag => 1, -type => 'string', xml_deref => 1, @opt);
$feed->merge_channel($singleFeed);
$feed->merge_item($singleFeed);
};
@ -181,7 +183,6 @@ sub generateFeed {
}
}
# build a new feed that matches the term the user is interested in
if ($self->get('hasTerms') ne '') {
my @terms = split /,\s*/, $self->get('hasTerms'); # get the list of terms

View file

@ -191,21 +191,6 @@ Rich Text editor in the first sentence of the description.",
#
####################################################################
sub withCachedFeed {
my ($url, $path, $block) = @_;
$syndicated_content->update({ rssUrl => $url });
open my $file, '<', WebGUI::Test->getTestCollateralPath($path)
or die "Unable to get RSS file: $path";
my $content = do { local $/; <$file> };
close $file;
my $cache = WebGUI::Cache->new($session, $url, 'RSS');
$cache->set($content, 60);
$block->();
$cache->delete;
}
sub titles_are {
my ($expected, $message) = @_;
my $feed = $syndicated_content->generateFeed;
@ -213,18 +198,23 @@ sub titles_are {
cmp_deeply \@got, $expected, $message;
}
$syndicated_content->update({ hasTerms => 'WebGUI' });
$syndicated_content->update({ hasTerms => 'WebGUI', });
my $testFeedUrl = 'http://www.example.com/feed.rss';
$syndicated_content->update({ rssUrl => $testFeedUrl, });
my $cache = WebGUI::Cache->new($session, $testFeedUrl, 'RSS');
$cache->set(slurp_rss('tbb.rss'), 60);
my $feed = $syndicated_content->generateFeed;
titles_are(
[
'Google Picasa Plugin for WebGUI Gallery',
'WebGUI Roadmap',
'WebGUI 8 Performance',
],
'generateFeed: filters items based on the terms being in title, or description'
);
withCachedFeed 'http://www.plainblack.com/tbb.rss', 'tbb.rss', sub {
titles_are(
[
'Google Picasa Plugin for WebGUI Gallery',
'WebGUI Roadmap',
'WebGUI 8 Performance',
],
'generateFeed: filters items based on the terms being in title, or description'
);
};
####################################################################
#
@ -237,13 +227,11 @@ $syndicated_content->update({
hasTerms => '',
maxHeadlines => 50,
});
$cache->set(slurp_rss('duplicate-link.rss'), 60);
withCachedFeed 'http://www.oncp.gob.ve/oncp.xml', 'oncp.xml', sub {
my $oddFeed1 = $syndicated_content->generateFeed();
my @oddItems = $oddFeed1->get_item();
is (@oddItems, 13, 'feed has items even without pubDates or links');
};
my $oddFeed1 = $syndicated_content->generateFeed();
my @oddItems = $oddFeed1->get_item();
is (@oddItems, 2, 'feed has items even without pubDates or links');
####################################################################
#
@ -251,28 +239,36 @@ withCachedFeed 'http://www.oncp.gob.ve/oncp.xml', 'oncp.xml', sub {
#
####################################################################
$cache->set(slurp_rss('tbb_odd.rss'), 60);
my @ascending = (
'I have arrived in Lisboa!',
'WebGUI 8 Performance',
'WebGUI Roadmap',
'Google Picasa Plugin for WebGUI Gallery',
);
my @descending = reverse @ascending;
my @feed = (
'WebGUI Roadmap',
'Google Picasa Plugin for WebGUI Gallery',
'I have arrived in Lisboa!',
'WebGUI 8 Performance',
);
withCachedFeed 'http://www.plainblack.com/tbb.rss', 'tbb_odd.rss', sub {
my @ascending = (
'I have arrived in Lisboa!',
'WebGUI 8 Performance',
'WebGUI Roadmap',
'Google Picasa Plugin for WebGUI Gallery',
);
my @descending = reverse @ascending;
my @feed = (
'WebGUI Roadmap',
'Google Picasa Plugin for WebGUI Gallery',
'I have arrived in Lisboa!',
'WebGUI 8 Performance',
);
$syndicated_content->update({ sortItems => 'pubDate_asc' });
titles_are \@ascending, 'ascending sort';
$syndicated_content->update({ sortItems => 'pubDate_asc' });
titles_are \@ascending, 'ascending sort';
$syndicated_content->update({ sortItems => 'pubDate_des' });
titles_are \@descending, 'descending sort';
$syndicated_content->update({ sortItems => 'pubDate_des' });
titles_are \@descending, 'descending sort';
$syndicated_content->update({ sortItems => 'feed' });
titles_are \@feed, 'feed order';
$syndicated_content->update({ sortItems => 'feed' });
titles_are \@feed, 'feed order';
};
sub slurp_rss {
my $file = shift;
my $filepath = WebGUI::Test->getTestCollateralPath('rss/' . $file);
open my $fh, '<', $filepath
or die "Unable to get RSS file $file: $!";
my $content = do { local $/; <$fh> };
close $fh;
return $content;
}

View file

@ -0,0 +1,119 @@
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2009 Plain Black Corporation.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#-------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#-------------------------------------------------------------------
use FindBin;
use strict;
use File::Spec;
use lib "$FindBin::Bin/../../../lib";
# The goal of this test is to test the creation of
# and expose any bugs of SyndicatedContent Wobjects.
use WebGUI::Test;
use Test::More; # increment this value for each test you create
use WebGUI::Session;
plan skip_all => 'set TEST_ENCODINGS to enable this test' unless $ENV{TEST_ENCODINGS};
plan tests => 13; # increment this value for each test you create
use Test::Deep;
use WebGUI::Asset::Wobject::SyndicatedContent;
use XML::FeedPP;
use WebGUI::Cache;
my $session = WebGUI::Test->session;
my %var;
##############################
## SETUP ##
##############################
# Do our work in the import node
my $node = WebGUI::Asset->getImportNode($session);
# Create a version tag to work in
my $versionTag = WebGUI::VersionTag->getWorking($session);
$versionTag->set({name=>"SyndicatedContent Test"});
addToCleanup($versionTag);
my $syndicated_content = $node->addChild({className=>'WebGUI::Asset::Wobject::SyndicatedContent'});
####################################################################
#
# Encoding tests
#
####################################################################
my $UTF8_BOM = "\xEF\xBB\xBF";
my $testFeedUrl = 'http://www.example.com/feed.rss';
$syndicated_content->update({
hasTerms => '',
rssUrl => $testFeedUrl,
});
my $cache = WebGUI::Cache->new($session, $testFeedUrl, 'RSS');
my $utf8_es = slurp_rss('utf8-es.rss');
my $utf8_ru = slurp_rss('utf8-ru.rss');
my $entity_es = slurp_rss('entity-es.rss');
my $entity_ru = slurp_rss('entity-ru.rss');
my $utf8_no_prolog = Encode::decode_utf8(slurp_rss('utf8-no-prolog-encoding.rss'));
my $iso_8859_1 = slurp_rss('iso-8859-1.rss');
my $iso_8859_5 = slurp_rss('iso-8859-5.rss');
my $es_title = "PM captur\x{00F3} a tres delincuentes que robaron agencia bancaria en San Mart\x{00ED}n";
my $ru_title = "\x{412}\x{438}\x{43a}\x{438}\x{43f}\x{435}\x{434}\x{438}\x{44f} - \x{421}\x{432}\x{435}\x{436}\x{438}\x{435} \x{43f}\x{440}\x{430}\x{432}\x{43a}\x{438} [ru]";
$cache->set($utf8_es, 60);
is $syndicated_content->generateFeed->title, $es_title, 'Latin-1 compatible, UTF-8 encoded';
$cache->set($utf8_ru, 60);
is $syndicated_content->generateFeed->title, $ru_title, 'Russian, UTF-8 encoded';
$cache->set($entity_es, 60);
is $syndicated_content->generateFeed->title, $es_title, 'Latin-1 compatible, Entity encoded, utf8 flag off';
$cache->set($entity_ru, 60);
is $syndicated_content->generateFeed->title, $ru_title, 'Russian, Entity encoded, utf8 flag off';
$cache->set($UTF8_BOM . $utf8_es, 60);
is $syndicated_content->generateFeed->title, $es_title, 'Latin-1 compatible, UTF-8 encoded, With BOM';
$cache->set(Encode::decode_utf8($utf8_es), 60);
is $syndicated_content->generateFeed->title, $es_title, 'Latin-1 compatible, Decoded';
$cache->set(Encode::decode_utf8($utf8_ru), 60);
is $syndicated_content->generateFeed->title, $ru_title, 'Russian, Decoded';
$cache->set(Encode::decode_utf8($entity_es), 60);
is $syndicated_content->generateFeed->title, $es_title, 'Latin-1, Entity encoded, utf8 flag on';
$cache->set(Encode::decode_utf8($entity_ru), 60);
is $syndicated_content->generateFeed->title, $ru_title, 'Russian, Entity encoded, utf8 flag on';
$cache->set($UTF8_BOM . Encode::decode_utf8($utf8_es), 60);
is $syndicated_content->generateFeed->title, $es_title, 'Latin-1 compatible, Decoded, With BOM';
$cache->set($utf8_no_prolog, 60);
is $syndicated_content->generateFeed->title, $es_title, 'No encoding in prolog, Decoded';
$cache->set($iso_8859_1, 60);
is $syndicated_content->generateFeed->title, $es_title, 'ISO-8859-1 encoded';
$cache->set($iso_8859_5, 60);
is $syndicated_content->generateFeed->title, $ru_title, 'ISO-8859-5 encoded';
$cache->delete;
sub slurp_rss {
my $file = shift;
my $filepath = WebGUI::Test->getTestCollateralPath('rss/' . $file);
open my $fh, '<', $filepath
or die "Unable to get RSS file $file: $!";
my $content = do { local $/; <$fh> };
close $fh;
return $content;
}

View file

@ -1,95 +0,0 @@
<?xml version="1.0" encoding="iso-8859-1" ?>
<rss version="2.0"><channel>
<title><![CDATA[Oficina Nacional de Crédito Público]]></title>
<link>http://www.oncp.gob.ve</link>
<description>Información Financiera</description>
<language>es-ve</language>
<copyright>Oficina Nacional de Crédito Público - 2009</copyright>
<image>
<title>Oficina Nacional de Crédito Público</title>
<url>http://www.oncp.gob.ve/data/themes/digital//banner/oncp.png</url>
<link>http://www.oncp.gob.ve</link>
</image>
<item>
<title><![CDATA[Deuda Interna I Sem 09 / MM US$ 20.441]]></title>
<link>http://www.oncp.gob.ve</link>
<description><![CDATA[MM US$ 20.441]]></description>
<guid isPermaLink="true">http://www.oncp.gob.ve</guid>
</item>
<item>
<title><![CDATA[Deuda Externa I Sem 09 / MM US$ 29.894]]></title>
<link>http://www.oncp.gob.ve</link>
<description><![CDATA[MM US$ 29.894]]></description>
</item>
<item>
<title><![CDATA[Tasa Pasiva / 14,52%]]></title>
<link>http://www.oncp.gob.ve</link>
<description><![CDATA[14,52%]]></description>
</item>
<item>
<title><![CDATA[Tasa Activa / 19,56%]]></title>
<link>http://www.oncp.gob.ve</link>
<description><![CDATA[19,56%]]></description>
</item>
<item>
<title><![CDATA[Variación PIB II Trimestre / -2,4%]]></title>
<link>http://www.oncp.gob.ve</link>
<description><![CDATA[-2,4%]]></description>
</item>
<item>
<title><![CDATA[PIB II Trimestre 2009 / M BsF 13.979.77]]></title>
<link>http://www.oncp.gob.ve</link>
<description><![CDATA[M BsF 13.979.77]]></description>
</item>
<item>
<title><![CDATA[Unidad Tributaria / BsF. 55,00]]></title>
<link>http://www.oncp.gob.ve</link>
<description><![CDATA[BsF. 55,00]]></description>
</item>
<item>
<title><![CDATA[Cesta Venezolana / US$ 65,32]]></title>
<link>http://www.oncp.gob.ve</link>
<description><![CDATA[US$ 65,32]]></description>
</item>
<item>
<title><![CDATA[Cesta OPEP / US$ 67,92]]></title>
<link>http://www.oncp.gob.ve</link>
<description><![CDATA[US$ 67,92]]></description>
</item>
<item>
<title><![CDATA[Variación Acumuladaa / 15,6%]]></title>
<link>http://www.oncp.gob.ve</link>
<description><![CDATA[15,6%]]></description>
</item>
<item>
<title><![CDATA[IPC Variación Agosto 2009 / 2,2%]]></title>
<link>http://www.oncp.gob.ve</link>
<description><![CDATA[2,2%]]></description>
</item>
<item>
<title><![CDATA[Reservas Internacionales con BCV + FEM / MM US$ 33.213 (32.384 + 829)]]></title>
<link>http://www.oncp.gob.ve</link>
<description><![CDATA[MM US$ 33.213 (32.384 + 829)]]></description>
</item>
<item>
<title><![CDATA[Variación Acumulada / 15,6%]]></title>
<link>http://www.oncp.gob.ve</link>
<description><![CDATA[15,6%]]></description>
</item>
</channel>
</rss>

View file

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8" ?>
<rss version="2.0"><channel>
<title>Duplicate Link Feed Title</title>
<link>http://www.example.com/</link>
<description>Duplicate Link Feed Description</description>
<item>
<title>Duplicate Link Feed Item 1</title>
<link>http://www.example.com/</link>
<description>Duplicate Link Feed Item 1</description>
<guid isPermaLink="true">http://www.example.com/</guid>
</item>
<item>
<title>Duplicate Link Feed Item 2</title>
<link>http://www.example.com/</link>
<description>Duplicate Link Feed Item 2</description>
<guid isPermaLink="true">http://www.example.com/</guid>
</item>
</channel>
</rss>

View file

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>PM captur&#xF3; a tres delincuentes que robaron agencia bancaria en San Mart&#xED;n</title>
<link>http://www.vtv.gob.ve/rss-noticias-nacionales</link>
<description>RSS Noticias Nacionales</description>
<language>es</language>
<item>
<title>PM captur&#xF3; a tres delincuentes que robaron agencia bancaria en San Mart&#xED;n</title>
<link>http://www.vtv.gob.ve/noticias-nacionales/25087</link>
<description>&lt;p&gt;Efectivos de la Polic&#xED;a Metropolitana (PM) de Caracas capturaron, este lunes en horas de la ma&#xF1;ana, a tres delincuentes implicados en el robo perpetrado en el Banco Industrial de Venezuela (BIV) ubicado dentro de la oficina del Instituto Postal Telegr&#xE1;fico de Venezuela, Ipostel, en la avenida Jos&#xE9; &#xC1;ngel Lamas, San Mart&#xED;n.&lt;/p&gt;</description>
<pubDate>Mon, 19 Oct 2009 15:42:17 -0400</pubDate>
</item>
</channel>
</rss>

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<rss version="2.0">
<channel>
<title>PM capturó a tres delincuentes que robaron agencia bancaria en San Martín</title>
<link>http://www.vtv.gob.ve/rss-noticias-nacionales</link>
<description>RSS Noticias Nacionales</description>
<language>es</language>
<item>
<title>PM capturó a tres delincuentes que robaron agencia bancaria en San Martín</title>
<link>http://www.vtv.gob.ve/noticias-nacionales/25087</link>
<description>&lt;p&gt;Efectivos de la Policía Metropolitana (PM) de Caracas capturaron, este lunes en horas de la mañana, a tres delincuentes implicados en el robo perpetrado en el Banco Industrial de Venezuela (BIV) ubicado dentro de la oficina del Instituto Postal Telegráfico de Venezuela, Ipostel, en la avenida José Ángel Lamas, San Martín.&lt;/p&gt;</description>
<pubDate>Mon, 19 Oct 2009 15:42:17 -0400</pubDate>
</item>
</channel>
</rss>

View file

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="iso-8859-5"?>
<rss version="2.0">
<channel>
<title>Википедия - Свежие правки [ru]</title>
<link>http://ru.wikipedia.org/wiki/%D0%A1%D0%BB%D1%83%D0%B6%D0%B5%D0%B1%D0%BD%D0%B0%D1%8F:RecentChanges</link>
<description>Отслеживать последние изменения в вики в этом потоке.</description>
<language>ru</language>
<item>
<title>Йиржи из Подебрад</title>
<link>http://ru.wikipedia.org/w/index.php?title=%D0%99%D0%B8%D1%80%D0%B6%D0%B8_%D0%B8%D0%B7_%D0%9F%D0%BE%D0%B4%D0%B5%D0%B1%D1%80%D0%B0%D0%B4&amp;diff=19271780&amp;oldid=prev</link>
<description>&lt;div&gt;Происходил из знатной и влиятельной чешской семьи, примкнувшей к гуситскому лагерю. Отец Йиржи, Виктор из [[Подебрады|Подебрад]], был одним из руководителей [[табориты|таборитов]];? радикального крыла гуситов, однако через некоторое время присоединился к умеренным утраквистам. Сам Йиржи из Подебрад, будучи четырнадцатилетним мальчиком, участвовал в [[битва под Липанами|битве под Липанами]] в [[1434]], в которой умеренные гуситы, объединившиеся с австрийцами, нанесли поражение радикальным. В общем, при [[Сигизмунд (император )|Сигизмунде Люксембургском]] семья Йиржи из Подебрад принадлежала к умеренной партии, но после избрания королем Чехии с подачи католической партии Альбрехта V Австрийского (немецкого императора [[Альбрехт II (император)|Альбрехта II]]), отец и сын примкнули к оппозиции, желавшей избрания [[Казимир III|Казимира Польского]].&lt;/div&gt;</description>
<pubDate>Tue, 20 Oct 2009 00:00:44 GMT</pubDate>
</channel>
</rss>

View file

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>PM capturó a tres delincuentes que robaron agencia bancaria en San Martín</title>
<link>http://www.vtv.gob.ve/rss-noticias-nacionales</link>
<description>RSS Noticias Nacionales</description>
<language>es</language>
<item>
<title>PM capturó a tres delincuentes que robaron agencia bancaria en San Martín</title>
<link>http://www.vtv.gob.ve/noticias-nacionales/25087</link>
<description>&lt;p&gt;Efectivos de la Policía Metropolitana (PM) de Caracas capturaron, este lunes en horas de la mañana, a tres delincuentes implicados en el robo perpetrado en el Banco Industrial de Venezuela (BIV) ubicado dentro de la oficina del Instituto Postal Telegráfico de Venezuela, Ipostel, en la avenida José Ángel Lamas, San Martín.&lt;/p&gt;</description>
<pubDate>Mon, 19 Oct 2009 15:42:17 -0400</pubDate>
</item>
</channel>
</rss>

View file

@ -0,0 +1,15 @@
<?xml version="1.0"?>
<rss version="2.0">
<channel>
<title>PM capturó a tres delincuentes que robaron agencia bancaria en San Martín</title>
<link>http://www.vtv.gob.ve/rss-noticias-nacionales</link>
<description>RSS Noticias Nacionales</description>
<language>es</language>
<item>
<title>PM capturó a tres delincuentes que robaron agencia bancaria en San Martín</title>
<link>http://www.vtv.gob.ve/noticias-nacionales/25087</link>
<description>&lt;p&gt;Efectivos de la Policía Metropolitana (PM) de Caracas capturaron, este lunes en horas de la mañana, a tres delincuentes implicados en el robo perpetrado en el Banco Industrial de Venezuela (BIV) ubicado dentro de la oficina del Instituto Postal Telegráfico de Venezuela, Ipostel, en la avenida José Ángel Lamas, San Martín.&lt;/p&gt;</description>
<pubDate>Mon, 19 Oct 2009 15:42:17 -0400</pubDate>
</item>
</channel>
</rss>

View file

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Википедия - Свежие правки [ru]</title>
<link>http://ru.wikipedia.org/wiki/%D0%A1%D0%BB%D1%83%D0%B6%D0%B5%D0%B1%D0%BD%D0%B0%D1%8F:RecentChanges</link>
<description>Отслеживать последние изменения в вики в этом потоке.</description>
<language>ru</language>
<item>
<title>Йиржи из Подебрад</title>
<link>http://ru.wikipedia.org/w/index.php?title=%D0%99%D0%B8%D1%80%D0%B6%D0%B8_%D0%B8%D0%B7_%D0%9F%D0%BE%D0%B4%D0%B5%D0%B1%D1%80%D0%B0%D0%B4&amp;diff=19271780&amp;oldid=prev</link>
<description>&lt;div&gt;Происходил из знатной и влиятельной чешской семьи, примкнувшей к гуситскому лагерю. Отец Йиржи, Виктор из [[Подебрады|Подебрад]], был одним из руководителей [[табориты|таборитов]];— радикального крыла гуситов, однако через некоторое время присоединился к умеренным утраквистам. Сам Йиржи из Подебрад, будучи четырнадцатилетним мальчиком, участвовал в [[битва под Липанами|битве под Липанами]] в [[1434]], в которой умеренные гуситы, объединившиеся с австрийцами, нанесли поражение радикальным. В общем, при [[Сигизмунд (император )|Сигизмунде Люксембургском]] семья Йиржи из Подебрад принадлежала к умеренной партии, но после избрания королем Чехии с подачи католической партии Альбрехта V Австрийского (немецкого императора [[Альбрехт II (император)|Альбрехта II]]), отец и сын примкнули к оппозиции, желавшей избрания [[Казимир III|Казимира Польского]].&lt;/div&gt;</description>
<pubDate>Tue, 20 Oct 2009 00:00:44 GMT</pubDate>
</channel>
</rss>