From 016e16aab1f3bf9b3bc18c64015abd8a48451547 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Fri, 26 Jan 2007 05:02:04 +0000 Subject: [PATCH] fix a bad test in the Clipboard and add the AssetPackage test --- t/Asset/AssetClipboard.t | 4 +- t/Asset/AssetPackage.t | 103 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 t/Asset/AssetPackage.t diff --git a/t/Asset/AssetClipboard.t b/t/Asset/AssetClipboard.t index 4f98a2fb8..b372e6cdb 100644 --- a/t/Asset/AssetClipboard.t +++ b/t/Asset/AssetClipboard.t @@ -42,10 +42,12 @@ my $snippetAssetId = $snippet->getId; $versionTag->commit; +sleep 2; + my $duplicatedSnippet = $snippet->duplicate; is($duplicatedSnippet->get('title'), 'snippet', 'duplicated snippet has correct title'); -is($duplicatedSnippet->getId, $snippetAssetId, 'duplicated snippet has correct id'); +isnt($duplicatedSnippet->getId, $snippetAssetId, 'duplicated snippet does not have same assetId as original'); is($snippet->getId, $snippetAssetId, 'original snippet has correct id'); is($snippet->getParent->getId, $root->getId, 'original snippet is a child of root'); diff --git a/t/Asset/AssetPackage.t b/t/Asset/AssetPackage.t new file mode 100644 index 000000000..ca6f53a2f --- /dev/null +++ b/t/Asset/AssetPackage.t @@ -0,0 +1,103 @@ +#------------------------------------------------------------------- +# 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"; + +##The goal of this test is to check the creation and purging of +##versions. + +use WebGUI::Test; +use WebGUI::Session; +use WebGUI::Utility; +use WebGUI::Asset; +use WebGUI::VersionTag; + +use Test::More; # increment this value for each test you create +use Test::MockObject; +plan tests => 6; + +my $session = WebGUI::Test->session; +$session->user({userId => 3}); +my $root = WebGUI::Asset->getRoot($session); +my $versionTag = WebGUI::VersionTag->getWorking($session); +$versionTag->set({name=>"Asset Package test"}); + +my $folder = $root->addChild({ + url => 'testFolder', + title => 'folder', + menuTitle => 'folderMenuTitle', + className => 'WebGUI::Asset::Wobject::Folder', + isPackage => 1, +}); + +my $targetFolder = $root->addChild({ + url => 'targetFolder', + title => 'Target Folder', + menuTitle => 'Target folderMenuTitle', + className => 'WebGUI::Asset::Wobject::Folder', +}); + +my $snippet = $folder->addChild({ + url => 'testSnippet', + title => 'snippet', + menuTitle => 'snippetMenuTitle', + className => 'WebGUI::Asset::Snippet', + snippet => 'A snippet of text', +}); + +my $packageAssetId = $folder->getId; +hack_session_request($session, $packageAssetId); + +my $targetFolderChildren; +$targetFolderChildren = $targetFolder->getLineage(["children"], {returnObjects => 1,}); +is(scalar @{ $targetFolderChildren }, 0, 'target folder has no children'); + +$versionTag->commit; + +my $deployReturn = $targetFolder->www_deployPackage(); +is($deployReturn, "", 'www_deployPackage returns empty string'); + +$targetFolderChildren = $targetFolder->getLineage(["children"], {returnObjects => 1,}); +is(scalar @{ $targetFolderChildren }, 1, 'target folder now has 1 child'); + +my $deployedFolder = $targetFolderChildren->[0]; + +is($deployedFolder->get('title'), 'folder', 'deployed folder has correct title'); + +my $deployedFolderChildren; +$deployedFolderChildren = $deployedFolder->getLineage(["children"], {returnObjects => 1,}); +is(scalar @{ $deployedFolderChildren }, 1, 'deployed package folder still has 1 child'); +isa_ok($deployedFolderChildren->[0] , 'WebGUI::Asset::Snippet', 'deployed child is a Snippet'); + +my $newVersionTag = WebGUI::VersionTag->getWorking($session); +$newVersionTag->commit; + +##This allows us to place an arbitrary assetId inside the form processor. +##This is required for deploying a package. +sub hack_session_request { + my ($session, $id) = @_; + my $request = Test::MockObject->new(); + $request->mock('body', + sub { + return $id + }, + ); + $session->{_request} = $request; +} + +END { + foreach my $tag($versionTag, $newVersionTag) { + if (defined $tag and ref $tag eq 'WebGUI::VersionTag') { + $tag->rollback; + } + } +}