From 000b2fcce31bb647a70e964fb89976ea75424806 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Tue, 8 Aug 2006 17:43:44 +0000 Subject: [PATCH] Reverting previous work. Asset->new must return an Asset, even if no className is passed and the invocant's class is Asset. This is due to the root. In the db, the root Asset has the className WebGUI::Asset, and the getRoot method matches this. Changed the failing test in Asset.t to look for a WebGUI::Asset to be returned. Added two tests to Asset.t to validate the object returned by Asset->getRoot method. Reverted previous work and updated the POD for Asset->new. --- docs/changelog/7.x.x.txt | 3 --- lib/WebGUI/Asset.pm | 6 +++--- t/Asset/Asset.t | 12 ++++++++---- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 95eeda6d4..154cb950b 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -10,9 +10,6 @@ - fix: Redirects get displayed inside page layouts as '0' - fix: Mysterious "0" Appearing When Admin Is Off - fix: Deletion of Products - - Fix Asset.pm so that if no className is passed primeval Assets are not - returned. - 7.0.4 - Added a forum.lastPost.user.hasRead variable to the Message Board template. diff --git a/lib/WebGUI/Asset.pm b/lib/WebGUI/Asset.pm index 57e329f52..5fd0be7c8 100644 --- a/lib/WebGUI/Asset.pm +++ b/lib/WebGUI/Asset.pm @@ -1361,7 +1361,7 @@ sub manageAssetsSearch { =head2 new ( session, assetId [, className, revisionDate ] ) -Constructor. This does not create an asset. Returns a new object if it can, otherwise returns undef. +Constructor. This does not create an asset. =head3 session @@ -1377,7 +1377,8 @@ By default we'll use whatever class it is called by like WebGUI::Asset::File->ne =head3 revisionDate -An epoch date that represents a specific version of an asset. By default the most recent version will be used. +An epoch date that represents a specific version of an asset. By default the most recent version will be used. If +no revision date is available it will return undef. =cut @@ -1406,7 +1407,6 @@ sub new { } $class = $className; } - return undef if $class eq 'WebGUI::Asset'; my $cache = WebGUI::Cache->new($session, ["asset",$assetId,$revisionDate]); my $properties = $cache->get; if (exists $properties->{assetId}) { diff --git a/t/Asset/Asset.t b/t/Asset/Asset.t index 4adb6ec6e..973f78bd7 100644 --- a/t/Asset/Asset.t +++ b/t/Asset/Asset.t @@ -17,7 +17,7 @@ use WebGUI::Session; use WebGUI::Asset; use WebGUI::Asset::Wobject::Navigation; -use Test::More tests => 11; # increment this value for each test you create +use Test::More tests => 13; # increment this value for each test you create my $session = WebGUI::Test->session; @@ -47,9 +47,8 @@ $deadAsset = WebGUI::Asset->new($session, '', 'WebGUI::Asset::Wobject::Navigatio is ($deadAsset, undef,'new constructor with no assetId returns undef'); # -- no class -$deadAsset = 1; -$deadAsset = WebGUI::Asset->new($session, $assetId); -is ($deadAsset, undef,'new constructor with no class returns undef'); +my $primevalAsset = WebGUI::Asset->new($session, $assetId); +isa_ok ($primevalAsset, 'WebGUI::Asset'); # Test the newByDynamicClass Constructor $asset = undef; @@ -70,6 +69,11 @@ $deadAsset = 1; $deadAsset = WebGUI::Asset->newByDynamicClass($session); is ($deadAsset, undef, 'newByDynamicClass constructor with no assetId returns undef'); +# Root Asset +my $rootAsset = WebGUI::Asset->getRoot($session); +isa_ok($rootAsset, 'WebGUI::Asset'); +is($rootAsset->getId, 'PBasset000000000000001', 'Root Asset ID check'); + # TODO # Test the newByPropertiesHashRef Constructor #