diff --git a/lib/WebGUI/Asset.pm b/lib/WebGUI/Asset.pm index 559a6fa53..26ab2a173 100644 --- a/lib/WebGUI/Asset.pm +++ b/lib/WebGUI/Asset.pm @@ -498,7 +498,7 @@ sub fixId { my $self = shift; my $id = shift; my $field = shift; - if ($id =~ m/\A \d+ \z/xms || $id =~ m/\A [A-Za-z0-9\-\_]{22} \z/xms) { + if ($id =~ m/\A \d{1,22} \z/xms || $id =~ m/\A [A-Za-z0-9\-\_]{22} \z/xms) { return $id; } return $self->getValue($field); @@ -513,7 +513,9 @@ Fixes a title by eliminating HTML from it. =head3 string -Any text string. Most likely will have been the Asset's name or title. +Any text string. Most likely will have been the Asset's name or title. If +no string is supplied, then it will fetch the default title for the asset, +or the word Untitled. =cut @@ -1288,7 +1290,7 @@ sub getUrl { =head2 getValue ( key ) -Returns the value of anything it can find with an index of key, or else it returns undefined. +Returns the value of anything it can find with an index of key in the asset's properties, or else it returns undefined. =head3 key diff --git a/t/Asset/Asset.t b/t/Asset/Asset.t index 919532d5a..ee70d5d66 100644 --- a/t/Asset/Asset.t +++ b/t/Asset/Asset.t @@ -20,11 +20,62 @@ use WebGUI::Asset::Wobject::Folder; use WebGUI::AssetVersioning; use WebGUI::VersionTag; -use Test::More tests => 48; # increment this value for each test you create +use Test::More; use Test::MockObject; my $session = WebGUI::Test->session; +my @fixIdTests = ( + { + id => '0', + pass => 1, + comment => 'digit zero', + }, + { + id => '1', + pass => 1, + comment => 'digit one', + }, + { + id => '123', + pass => 1, + comment => '3 digit integer', + }, + { + id => '12345678901'x2, + pass => 1, + comment => '22 digit integer', + }, + { + id => '12345678901'x4, + pass => 0, + comment => '44 digit integer', + }, + { + id => '', + pass => 0, + comment => 'null string is rejected', + }, + { + id => 'a', + pass => 0, + comment => 'single lower case character rejected', + }, + { + # '1234567890123456789012' + id => 'abc123ZYX098deadbeef()', + pass => 0, + comment => 'illegal characters in length 22 string rejected', + }, + { + id => $session->id->generate, + pass => 1, + comment => 'valid id accepted', + }, +); + +plan tests => 50 + scalar(@fixIdTests); + # Test the default constructor my $defaultAsset = WebGUI::Asset->getDefault($session); is(ref $defaultAsset, 'WebGUI::Asset::Wobject::Layout','default constructor'); @@ -118,9 +169,12 @@ $deadAsset = WebGUI::Asset->newByDynamicClass($session, 'RoysNonExistantAssetId' is ($deadAsset, undef,'newByDynamicClass constructor with invalid assetId returns undef'); # -- no assetId -$deadAsset = 1; -$deadAsset = WebGUI::Asset->newByDynamicClass($session); -is ($deadAsset, undef, 'newByDynamicClass constructor with no assetId returns undef'); +{ + my $confession = ''; + local $SIG{__DIE__} = sub { $confession = $_[0]; }; + eval { WebGUI::Asset->newByDynamicClass($session); }; + like($confession, qr/newByDynamicClass requires assetId/, 'newByDynamicClass constructor with no assetId confesses and dies'); +} # Root Asset my $rootAsset = WebGUI::Asset->getRoot($session); @@ -234,10 +288,37 @@ is($importNode->fixUrl('fixUrlFolderURL100'), 'fixurlfolderurl101', '100->101'); is($fixUrlAsset5->fixUrl(), 'home/fix-url-folder-url-autogenerated', 'fixUrl will autogenerate a url if not provided one'); -$session->setting->set('urlExtension', 'html'); +TODO: { + local $TODO = "Test the automatic adding of extensions to URLs"; + $session->setting->set('urlExtension', 'html'); + ok(0, "Setup test for adding URL extensions"); + + $session->setting->set('urlExtension', $origUrlExtension); +} + +################################################################ +# +# fixId +# +################################################################ + +my $ownerUserId = $importNode->getValue('ownerUserId'); + +foreach my $test (@fixIdTests) { + my $fixedId = $importNode->fixId($test->{id}, 'ownerUserId'); + my $expectedId = $test->{pass} ? $test->{id} : $ownerUserId; + is($fixedId, $expectedId, $test->{comment}); +} + +################################################################ +# +# fixTitle +# +################################################################ + +is($importNode->fixTitle(), 'Import Node', 'fixTitle: returns the title of the asset on "empty" titles'); END: { - $session->config->set('extrasURL', $origExtras); $session->config->set('uploadsURL', $origUploads); $session->setting->set('urlExtension', $origUrlExtension);