BusyBird
view release on metacpan or search on metacpan
t/Main_PSGI_View.t view on Meta::CPAN
{label => "external https", args => [src => "https://example.co.jp/favicon.ico"],
exp => '<img src="https://example.co.jp/favicon.ico" />'},
{label => "internal absolute", args => [src => "/static/hoge.png"],
exp => '<img src="/static/hoge.png" />'},
{label => "with width, height and class",
args => [src => '/foobar.jpg', width => "400", height => "300", class => "foo bar"],
exp => '<img src="/foobar.jpg" width="400" height="300" class="foo bar" />'},
{label => "no src", args => [], exp => ''},
{label => "script", args => [src => '<script>alert("hoge");</script>'],
exp => ''},
{label => "data:",
args => [src => 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAAAXNSR0IArs4c6QAAAAxJREFUCNdjuKCgAAAC1AERHXzACQAAAABJRU5ErkJggg=='],
exp => ''},
{label => "javascript:", args => [src => 'javascript: alert("hoge");'],
exp => ''},
) {
is($funcs->{image}->(@{$case->{args}}), $case->{exp}, "$case->{label} OK");
}
note("--- -- path");
foreach my $case (
{arg => "relative/foo.png", exp => "relative/foo.png"},
{arg => "/absolute/foo.png", exp => "/apptop/absolute/foo.png"},
{arg => "", exp => ""},
{arg => "/", exp => "/apptop/"},
) {
is($funcs->{path}->($case->{arg}), $case->{exp}, "$case->{arg}: OK");
}
is($funcs->{script_name}->(), "/apptop", "script_name() function OK");
note("--- -- link to image");
foreach my $case (
{label => "valid url", url => 'http://hoge.com/img.png',
exp => '<a href="http://hoge.com/img.png"><img src="http://hoge.com/img.png" /></a>'},
{label => "invalid url", url => 'javascript: return false;',
exp => ''}
) {
is($funcs->{link}($funcs->{image}(src => $case->{url}), href => $case->{url}), $case->{exp}, "$case->{label}: OK");
}
note("--- -- bb_level");
foreach my $case (
{label => "positive level", args => [10], exp => "10"},
{label => "zero", args => [0], exp => "0"},
{label => "negative level", args => [-5], exp => "-5"},
{label => "undef", args => [undef], exp => "0"},
) {
is($funcs->{bb_level}->(@{$case->{args}}), $case->{exp}, "$case->{label} OK");
}
}
{
note("--- template_functions_for_timeline");
my $main = create_main();
my $view = BusyBird::Main::PSGI::View->new(main_obj => $main, script_name => "");
my $funcs = $view->template_functions_for_timeline('test');
$main->set_config(
time_zone => "UTC",
time_format => '%Y-%m-%d %H:%M:%S',
time_locale => 'en_US',
);
note("--- -- bb_timestamp");
foreach my $case (
{label => 'normal', args => ['Tue May 28 20:10:13 +0900 2013'], exp => '2013-05-28 11:10:13'},
{label => 'undef', args => [undef], exp => ''},
{label => 'empty string', args => [''], exp => ''},
) {
is($funcs->{bb_timestamp}->(@{$case->{args}}), $case->{exp}, "$case->{label}: OK");
}
note("--- -- bb_status_permalink");
foreach my $case (
{label => "complete status",
args => [{id => "191", user => {screen_name => "hoge"}, busybird => {status_permalink => "http://hoge.com/"}}],
exp => "http://hoge.com/"},
{label => "missing status_permalink field",
args => [{id => "191", user => {screen_name => "hoge"}}],
exp => "https://twitter.com/hoge/status/191"},
{label => "unable to build", args => [{id => "191"}], exp => ""},
{label => "invalid status_permalink",
args => [{id => "191", busybird => {status_permalink => "javascript: alert('hoge')"}}],
exp => ""},
{label => "non-integral status ID",
args => [{id => 'busybird://110131', user => {screen_name => "foobar"}, text => "HOGE HOGE"}],
exp => ""},
{label => "original ID",
args => [{id => "converted ID", user => {screen_name => '_hoge_'}, busybird => {original => {id => '119302'}}}],
exp => 'https://twitter.com/_hoge_/status/119302'}
) {
is($funcs->{bb_status_permalink}->(@{$case->{args}}), $case->{exp}, "$case->{label}: OK");
}
note("--- -- bb_text");
foreach my $case (
{label => "HTML special char, no URL, no entity",
args => [{text => q{foo bar "A & B"} }],
exp => q{foo bar "A & B"}},
{label => "URL and HTML special char, no entity",
args => [{id => "hoge", text => 'this contains URL http://hogehoge.com/?a=foo+bar&b=%2Fhoge here :->'}],
exp => q{this contains URL <a href="http://hogehoge.com/?a=foo+bar&b=%2Fhoge" target="_blank">http://hogehoge.com/?a=foo+bar&b=%2Fhoge</a> here :->}},
{label => "URL at the top and bottom",
args => [{text => q{http://hoge.com/toc.html#item5 hogehoge http://foobar.co.jp/q=hoge&page=5}}],
exp => q{<a href="http://hoge.com/toc.html#item5" target="_blank">http://hoge.com/toc.html#item5</a> hogehoge <a href="http://foobar.co.jp/q=hoge&page=5" target="_blank">http://foobar.co.jp/q=hoge&page=5</a>}},
{label => "Twitter Entities",
args => [{
text => q{ã¦ã㨠<"&hearts;&&hearts;"> http://t.co/dNlPhACDcS >"< @debug_ito & & & #test},
entities => {
hashtags => [ { text => "test", indices => [106,111] } ],
user_mentions => [ {
"name" => "Toshio Ito",
"id" => 797588971,
"id_str" => "797588971",
"indices" => [ 77, 87 ],
"screen_name" => "debug_ito"
} ],
symbols => [],
( run in 0.511 second using v1.01-cache-2.11-cpan-ceb78f64989 )