diff --git a/lib/WebGUI/Asset.pm b/lib/WebGUI/Asset.pm index 316d1884d..1be61226f 100644 --- a/lib/WebGUI/Asset.pm +++ b/lib/WebGUI/Asset.pm @@ -236,6 +236,12 @@ property assetSize => ( ); has session => ( is => 'ro', + required => 1, + ); +has assetId => ( + is => 'ro', + lazy => 1, + default => sub { shift->session->id->generate() }, ); around BUILDARGS => sub { @@ -1054,7 +1060,7 @@ Returns the assetId of an Asset. sub getId { my $self = shift; - return $self->get("assetId"); + return $self->assetId; } #------------------------------------------------------------------- diff --git a/t/Asset.t b/t/Asset.t index 007b04dfe..0ca6e0a35 100644 --- a/t/Asset.t +++ b/t/Asset.t @@ -20,7 +20,7 @@ use Test::More; use Test::Deep; use Test::Exception; -plan tests => 17; +plan tests => 20; my $session = WebGUI::Test->session; @@ -47,6 +47,10 @@ my $session = WebGUI::Test->session; 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'; } { @@ -69,7 +73,7 @@ my $session = WebGUI::Test->session; $asset->menuTitle('

'); is $asset->menuTitle, 'asset title', '... if HTML filters out all, returns default'; - my $asset = WebGUI::Asset->new({ + $asset = WebGUI::Asset->new({ session => $session, title => 'asset title', menuTitle => 'menuTitle asset',