webgui/t/Asset/Asset.t
Colin Kuskie 000b2fcce3 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.
2006-08-08 17:43:44 +00:00

79 lines
2.9 KiB
Perl

#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2006 Plain Black Corporation.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#-------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#-------------------------------------------------------------------
use FindBin;
use strict;
use lib "$FindBin::Bin/../lib";
use WebGUI::Test;
use WebGUI::Session;
use WebGUI::Asset;
use WebGUI::Asset::Wobject::Navigation;
use Test::More tests => 13; # 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','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
my $primevalAsset = WebGUI::Asset->new($session, $assetId);
isa_ok ($primevalAsset, 'WebGUI::Asset');
# 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');
# 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
#