diff --git a/t/Asset/Asset.t b/t/Asset/Asset.t
index ee70d5d66..6b83aa8e5 100644
--- a/t/Asset/Asset.t
+++ b/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 => 'A bold title',
+ fixed => 'A bold title',
+ comment => "Markup is stripped out",
+ },
+ {
+ title => 'Javascript: ',
+ 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);