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:
parent
406b8219c3
commit
f39a13912e
14 changed files with 293 additions and 151 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
119
t/Asset/Wobject/SyndicatedContent/encodings.t
Normal file
119
t/Asset/Wobject/SyndicatedContent/encodings.t
Normal 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;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue