142 lines
4.3 KiB
Perl
142 lines
4.3 KiB
Perl
#-------------------------------------------------------------------
|
|
# 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 warnings;
|
|
no warnings qw(uninitialized);
|
|
use lib "$FindBin::Bin/lib";
|
|
|
|
use WebGUI::Test;
|
|
|
|
use Test::More;
|
|
use Test::Deep;
|
|
use Test::Exception;
|
|
|
|
plan tests => 29;
|
|
|
|
my $session = WebGUI::Test->session;
|
|
|
|
{
|
|
|
|
note "new, session and title";
|
|
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';
|
|
|
|
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->get('title'), $asset->title, '... get(title) works';
|
|
|
|
is $asset->menuTitle, 'Untitled', 'menuTitle: default is untitled';
|
|
|
|
can_ok $asset, qw/assetId getId/;
|
|
ok $session->id->valid( $asset->assetId), 'assetId generated by default is valid';
|
|
is $asset->assetId, $asset->getId, '... getId is an alias for assetId';
|
|
}
|
|
|
|
{
|
|
|
|
note "menuTitle";
|
|
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';
|
|
|
|
$asset = WebGUI::Asset->new({
|
|
session => $session,
|
|
title => 'asset title',
|
|
menuTitle => 'menuTitle asset',
|
|
});
|
|
is $asset->menuTitle, 'menuTitle asset', '... set via constructor';
|
|
}
|
|
|
|
{
|
|
note "Class dispatch";
|
|
my $asset = WebGUI::Asset->new({
|
|
session => $session,
|
|
title => 'testing snippet',
|
|
className => 'WebGUI::Asset::Snippet',
|
|
});
|
|
|
|
isa_ok $asset, 'WebGUI::Asset';
|
|
|
|
use WebGUI::Asset::Snippet;
|
|
$asset = WebGUI::Asset::Snippet->new({
|
|
session => $session,
|
|
title => 'testing snippet',
|
|
});
|
|
|
|
isa_ok $asset, 'WebGUI::Asset::Snippet';
|
|
}
|
|
|
|
{
|
|
note "Property inspection";
|
|
my $asset = WebGUI::Asset->new({
|
|
session => $session,
|
|
});
|
|
|
|
cmp_deeply(
|
|
[$asset->meta->get_all_properties],
|
|
array_each(
|
|
methods(
|
|
tableName => 'assetData',
|
|
)
|
|
),
|
|
'all properties have the right tableName'
|
|
);
|
|
|
|
}
|
|
|
|
{
|
|
note "getClassById";
|
|
my $class;
|
|
$class = WebGUI::Asset->getClassById($session, 'PBasset000000000000001');
|
|
is $class, 'WebGUI::Asset', 'getClassById: retrieve a class';
|
|
$class = WebGUI::Asset->getClassById($session, 'PBasset000000000000001');
|
|
is $class, 'WebGUI::Asset', '... cache check';
|
|
$class = WebGUI::Asset->getClassById($session, 'PBasset000000000000002');
|
|
is $class, 'WebGUI::Asset::Wobject::Folder', '... retrieve another class';
|
|
$class = WebGUI::Asset->getClassById($session, 'noIdHereBoss');
|
|
is $class, undef, '... returns undef if the class cannot be found';
|
|
}
|
|
|
|
{
|
|
note "new, fetching from db";
|
|
my $asset;
|
|
$asset = WebGUI::Asset->new($session, 'PBasset000000000000001');
|
|
isa_ok $asset, 'WebGUI::Asset';
|
|
is $asset->title, 'Root', 'got the right asset';
|
|
}
|