tests for fixTitle
This commit is contained in:
parent
060dd85963
commit
14f5ebdebc
1 changed files with 106 additions and 42 deletions
148
t/Asset/Asset.t
148
t/Asset/Asset.t
|
|
@ -74,52 +74,55 @@ my @fixIdTests = (
|
|||
},
|
||||
);
|
||||
|
||||
plan tests => 50 + scalar(@fixIdTests);
|
||||
my @fixTitleTests = (
|
||||
{
|
||||
title => undef,
|
||||
fixed => 0,
|
||||
comment => "undef returns the Asset's title",
|
||||
},
|
||||
{
|
||||
title => '',
|
||||
fixed => 0,
|
||||
comment => "null string returns the Asset's title",
|
||||
},
|
||||
{
|
||||
title => 'untitled',
|
||||
fixed => 0,
|
||||
comment => "'untitled' returns the Asset's title",
|
||||
},
|
||||
{
|
||||
title => 'UnTiTlEd',
|
||||
fixed => 0,
|
||||
comment => "'untitled' in any case returns the Asset's title",
|
||||
},
|
||||
{
|
||||
title => 'Username: ^@;',
|
||||
fixed => 'Username: ^@;',
|
||||
comment => "Macros are negated",
|
||||
},
|
||||
{
|
||||
title => '<b>A bold title</b>',
|
||||
fixed => 'A bold title',
|
||||
comment => "Markup is stripped out",
|
||||
},
|
||||
{
|
||||
title => 'Javascript: <script>Evil code goes in here</script>',
|
||||
fixed => 'Javascript: ',
|
||||
comment => "javascript removed",
|
||||
},
|
||||
{
|
||||
title => 'This is a good Title',
|
||||
fixed => 'This is a good Title',
|
||||
comment => "Good titles are passed",
|
||||
},
|
||||
);
|
||||
|
||||
plan tests => 50 + scalar(@fixIdTests) + scalar(@fixTitleTests);
|
||||
|
||||
# Test the default constructor
|
||||
my $defaultAsset = WebGUI::Asset->getDefault($session);
|
||||
is(ref $defaultAsset, 'WebGUI::Asset::Wobject::Layout','default constructor');
|
||||
|
||||
my $versionTag = WebGUI::VersionTag->getWorking($session);
|
||||
$versionTag->set({name=>"Asset tests"});
|
||||
|
||||
my $properties = {
|
||||
# '1234567890123456789012'
|
||||
id => 'fixUrlAsset00000000012',
|
||||
title => 'fixUrl Asset Test',
|
||||
className => 'WebGUI::Asset::Wobject::Folder',
|
||||
url => 'fixUrlFolderURL2',
|
||||
};
|
||||
|
||||
my $fixUrlAsset = $defaultAsset->addChild($properties, $properties->{id});
|
||||
|
||||
# '1234567890123456789012'
|
||||
$properties->{id} = 'fixUrlAsset00000000013';
|
||||
$properties->{url} = 'fixUrlFolderURL9';
|
||||
|
||||
my $fixUrlAsset2 = $defaultAsset->addChild($properties, $properties->{id});
|
||||
|
||||
# '1234567890123456789012'
|
||||
$properties->{id} = 'fixUrlAsset00000000014';
|
||||
$properties->{url} = 'fixUrlFolderURL00';
|
||||
|
||||
my $fixUrlAsset3 = $defaultAsset->addChild($properties, $properties->{id});
|
||||
|
||||
# '1234567890123456789012'
|
||||
$properties->{id} = 'fixUrlAsset00000000015';
|
||||
$properties->{url} = 'fixUrlFolderURL100';
|
||||
|
||||
my $fixUrlAsset4 = $defaultAsset->addChild($properties, $properties->{id});
|
||||
|
||||
delete $properties->{url};
|
||||
# '1234567890123456789012'
|
||||
$properties->{id} = 'fixUrlAsset00000000016';
|
||||
$properties->{menuTitle} = 'fix url folder url autogenerated';
|
||||
|
||||
my $fixUrlAsset5 = $defaultAsset->addChild($properties, $properties->{id});
|
||||
|
||||
$versionTag->commit;
|
||||
|
||||
# Test the new constructor
|
||||
my $assetId = "PBnav00000000000000001"; # one of the default nav assets
|
||||
|
||||
|
|
@ -244,6 +247,57 @@ $session->{_request} = $origRequest;
|
|||
#
|
||||
################################################################
|
||||
|
||||
my $versionTag = WebGUI::VersionTag->getWorking($session);
|
||||
$versionTag->set({name=>"Asset tests"});
|
||||
|
||||
my $properties = {
|
||||
# '1234567890123456789012'
|
||||
id => 'fixUrlAsset00000000012',
|
||||
title => 'fixUrl Asset Test',
|
||||
className => 'WebGUI::Asset::Wobject::Folder',
|
||||
url => 'fixUrlFolderURL2',
|
||||
};
|
||||
|
||||
my $fixUrlAsset = $defaultAsset->addChild($properties, $properties->{id});
|
||||
|
||||
# '1234567890123456789012'
|
||||
$properties->{id} = 'fixUrlAsset00000000013';
|
||||
$properties->{url} = 'fixUrlFolderURL9';
|
||||
|
||||
my $fixUrlAsset2 = $defaultAsset->addChild($properties, $properties->{id});
|
||||
|
||||
# '1234567890123456789012'
|
||||
$properties->{id} = 'fixUrlAsset00000000014';
|
||||
$properties->{url} = 'fixUrlFolderURL00';
|
||||
|
||||
my $fixUrlAsset3 = $defaultAsset->addChild($properties, $properties->{id});
|
||||
|
||||
# '1234567890123456789012'
|
||||
$properties->{id} = 'fixUrlAsset00000000015';
|
||||
$properties->{url} = 'fixUrlFolderURL100';
|
||||
|
||||
my $fixUrlAsset4 = $defaultAsset->addChild($properties, $properties->{id});
|
||||
|
||||
delete $properties->{url};
|
||||
# '1234567890123456789012'
|
||||
$properties->{id} = 'fixUrlAsset00000000016';
|
||||
$properties->{menuTitle} = 'fix url folder url autogenerated';
|
||||
|
||||
my $fixUrlAsset5 = $defaultAsset->addChild($properties, $properties->{id});
|
||||
|
||||
my $properties2 = {
|
||||
# '1234567890123456789012'
|
||||
id => 'fixTitleAsset000000010',
|
||||
title => '',
|
||||
className => 'WebGUI::Asset::Snippet',
|
||||
url => 'fixTitleAsset1',
|
||||
};
|
||||
|
||||
my $fixTitleAsset = $defaultAsset->addChild($properties2, $properties2->{id});
|
||||
|
||||
$versionTag->commit;
|
||||
|
||||
|
||||
my $origUrlExtension = $session->setting->get('urlExtension');
|
||||
$session->setting->set('urlExtension', undef);
|
||||
|
||||
|
|
@ -316,7 +370,17 @@ foreach my $test (@fixIdTests) {
|
|||
#
|
||||
################################################################
|
||||
|
||||
is($importNode->fixTitle(), 'Import Node', 'fixTitle: returns the title of the asset on "empty" titles');
|
||||
my $importNodeTitle = $importNode->getTitle();
|
||||
|
||||
foreach my $test (@fixTitleTests) {
|
||||
my $fixedTitle = $importNode->fixTitle($test->{title}, 'ownerUserId');
|
||||
my $expectedTitle = $test->{fixed} || $importNodeTitle;
|
||||
is($fixedTitle, $expectedTitle, $test->{comment});
|
||||
}
|
||||
|
||||
$fixTitleAsset->update({'title' => 0});
|
||||
|
||||
is($fixTitleAsset->fixTitle(''), 'Untitled', q{fixTitle: title is false, fixTitle returns 'Untitled'});
|
||||
|
||||
END: {
|
||||
$session->config->set('extrasURL', $origExtras);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue