diff --git a/t/Asset/Asset.t b/t/Asset/Asset.t index 1359dd50a..4adb6ec6e 100644 --- a/t/Asset/Asset.t +++ b/t/Asset/Asset.t @@ -15,11 +15,61 @@ use lib "$FindBin::Bin/../lib"; use WebGUI::Test; use WebGUI::Session; use WebGUI::Asset; -use Test::More tests => 1; # increment this value for each test you create +use WebGUI::Asset::Wobject::Navigation; + +use Test::More tests => 11; # increment this value for each test you create my $session = WebGUI::Test->session; # Test the default constructor my $defaultAsset = WebGUI::Asset->getDefault($session); -is(ref $defaultAsset, 'WebGUI::Asset::Wobject::Layout'); +is(ref $defaultAsset, 'WebGUI::Asset::Wobject::Layout','default constructor'); +# Test the new constructor +my $assetId = "PBnav00000000000000001"; # one of the default nav assets + +# - explicit class +my $asset = WebGUI::Asset->new($session, $assetId, 'WebGUI::Asset::Wobject::Navigation'); +is (ref $asset, 'WebGUI::Asset::Wobject::Navigation','new constructor explicit - ref check'); +is ($asset->getId, $assetId, 'new constructor explicit - returns correct asset'); + +# - implicit class +$asset = undef; +$asset = WebGUI::Asset::Wobject::Navigation->new($session, $assetId); +is (ref $asset, 'WebGUI::Asset::Wobject::Navigation', 'new constructor implicit - ref check'); +is ($asset->getId, $assetId, 'new constructor implicit - returns correct asset'); + +# - die gracefully +my $deadAsset = 1; + +# -- no asset id +$deadAsset = WebGUI::Asset->new($session, '', 'WebGUI::Asset::Wobject::Navigation'); +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'); + +# Test the newByDynamicClass Constructor +$asset = undef; + +$asset = WebGUI::Asset->newByDynamicClass($session, $assetId); +is (ref $asset, 'WebGUI::Asset::Wobject::Navigation', 'newByDynamicClass constructor - ref check'); +is ($asset->getId, $assetId, 'newByDynamicClass constructor - returns correct asset'); + +# - die gracefully +$deadAsset = 1; + +# -- invalid asset id +$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'); + +# TODO +# Test the newByPropertiesHashRef Constructor +#