Fix title, menuTitle and url around modifiers. Tests for title, menuTitle.
menuTitle is set to be lazy because it depends on title as a default.
This commit is contained in:
parent
49bd7f5032
commit
6733595dfc
2 changed files with 66 additions and 17 deletions
|
|
@ -35,13 +35,15 @@ property title => (
|
|||
around title => sub {
|
||||
my $orig = shift;
|
||||
my $self = shift;
|
||||
if (@_ > 1) {
|
||||
my $title = $_[0];
|
||||
$title = 'Untitled' if $title eq '';
|
||||
$title = WebGUI::HTML::filter($title, 'all');
|
||||
if (@_ > 0) {
|
||||
my $title = shift;
|
||||
$title = WebGUI::HTML::filter($title, 'all');
|
||||
$title = $self->meta->get_attribute('title')->default if $title eq '';
|
||||
unshift @_, $title;
|
||||
}
|
||||
$self->$orig(@_);
|
||||
};
|
||||
|
||||
property menuTitle => (
|
||||
tab => "properties",
|
||||
label => ['411','Asset'],
|
||||
|
|
@ -49,17 +51,25 @@ property menuTitle => (
|
|||
uiLevel => 1,
|
||||
fieldType => 'text',
|
||||
defaultValue => 'Untitled',
|
||||
builder => '_default_menuTitle',
|
||||
lazy => 1,
|
||||
);
|
||||
sub _default_menuTitle {
|
||||
my $self = shift;
|
||||
return $self->title;
|
||||
}
|
||||
around menuTitle => sub {
|
||||
my $orig = shift;
|
||||
my $self = shift;
|
||||
if (@_ > 1) {
|
||||
my $title = $_[0];
|
||||
$title = $self->title if $title eq '';
|
||||
if (@_ > 0) {
|
||||
my $title = shift;
|
||||
$title = WebGUI::HTML::filter($title, 'all');
|
||||
$title = $self->title if $title eq '';
|
||||
unshift @_, $title;
|
||||
}
|
||||
$self->$orig(@_);
|
||||
};
|
||||
|
||||
property url => (
|
||||
tab => "properties",
|
||||
label => ['104','Asset'],
|
||||
|
|
@ -71,7 +81,7 @@ property url => (
|
|||
around url => sub {
|
||||
my $orig = shift;
|
||||
my $self = shift;
|
||||
if (@_ > 1) {
|
||||
if (@_ > 0) {
|
||||
my $url = $_[0];
|
||||
$url = $self->fixUrl($url);
|
||||
}
|
||||
|
|
|
|||
57
t/Asset.t
57
t/Asset.t
|
|
@ -20,18 +20,57 @@ use Test::More;
|
|||
use Test::Deep;
|
||||
use Test::Exception;
|
||||
|
||||
plan tests => 5;
|
||||
plan tests => 16;
|
||||
|
||||
my $session = WebGUI::Test->session;
|
||||
|
||||
my $asset;
|
||||
{
|
||||
|
||||
$asset = WebGUI::Asset->new({session => $session, });
|
||||
my $asset = WebGUI::Asset->new({session => $session, });
|
||||
|
||||
isa_ok $asset, 'WebGUI::Asset';
|
||||
isa_ok $asset->session, 'WebGUI::Session';
|
||||
is $asset->session->getId, $session->getId, 'asset was assigned the correct session';
|
||||
isa_ok $asset, 'WebGUI::Asset';
|
||||
isa_ok $asset->session, 'WebGUI::Session';
|
||||
is $asset->session->getId, $session->getId, 'asset was assigned the correct session';
|
||||
|
||||
can_ok $asset, 'title', 'menuTitle';
|
||||
is $asset->title, 'Untitled', 'title: default is untitled';
|
||||
is $asset->title, 'Untitled', 'menuTitle: default is untitled';
|
||||
can_ok $asset, 'title', 'menuTitle';
|
||||
is $asset->title, 'Untitled', 'title: default is untitled';
|
||||
|
||||
$asset->title('asset title');
|
||||
is $asset->title, 'asset title', '... set, get';
|
||||
$asset->title('');
|
||||
is $asset->title, 'Untitled', '... get default title when empty title set';
|
||||
$asset->title('<h1>Header</h1>text');
|
||||
is $asset->title, 'Headertext', '... HTML is filtered out';
|
||||
$asset->title('<h1></h1>');
|
||||
is $asset->title, 'Untitled', '... if HTML filters out all, returns default';
|
||||
|
||||
is $asset->menuTitle, 'Untitled', 'menuTitle: default is untitled';
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
my $asset = WebGUI::Asset->new({
|
||||
session => $session,
|
||||
title => 'asset title',
|
||||
});
|
||||
|
||||
is $asset->menuTitle, 'asset title', 'menuTitle: default is title';
|
||||
|
||||
$asset->menuTitle('asset menuTitle');
|
||||
is $asset->menuTitle, 'asset menuTitle', '... set and get';
|
||||
|
||||
$asset->menuTitle('');
|
||||
is $asset->menuTitle, 'asset title', '... set to default when trying to clear the title';
|
||||
|
||||
$asset->menuTitle('<h1>Header</h1>text');
|
||||
is $asset->menuTitle, 'Headertext', '... HTML is filtered out';
|
||||
$asset->menuTitle('<h1></h1>');
|
||||
is $asset->menuTitle, 'asset title', '... if HTML filters out all, returns default';
|
||||
|
||||
my $asset = WebGUI::Asset->new({
|
||||
session => $session,
|
||||
title => 'asset title',
|
||||
menuTitle => 'menuTitle asset',
|
||||
});
|
||||
is $asset->menuTitle, 'menuTitle asset', '... set via constructor';
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue