From bd59ac600641a0906f5861da6b2e5d44645d5a11 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Tue, 3 Mar 2009 00:36:12 +0000 Subject: [PATCH] Test adding children, along with automatically adding folders. --- lib/WebGUI/Asset/Wobject/StoryArchive.pm | 7 +++++-- t/Asset/Wobject/StoryArchive.t | 12 +++++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/WebGUI/Asset/Wobject/StoryArchive.pm b/lib/WebGUI/Asset/Wobject/StoryArchive.pm index 8844e6005..49258aa9c 100644 --- a/lib/WebGUI/Asset/Wobject/StoryArchive.pm +++ b/lib/WebGUI/Asset/Wobject/StoryArchive.pm @@ -34,8 +34,11 @@ sub addChild { my $self = shift; my ($properties) = @_; ##Allow subclassing - return undef unless $properties->{className} =~ /^WebGUI::Asset::Story::/; - return $self->SUPER::addChild(@_); + return undef unless $properties->{className} =~ /^WebGUI::Asset::Story/; + my $todayFolder = $self->getFolder; + return undef unless $todayFolder; + my $story = $todayFolder->addChild(@_); + return $story; } #------------------------------------------------------------------- diff --git a/t/Asset/Wobject/StoryArchive.t b/t/Asset/Wobject/StoryArchive.t index d972fff32..f741b3046 100644 --- a/t/Asset/Wobject/StoryArchive.t +++ b/t/Asset/Wobject/StoryArchive.t @@ -58,7 +58,7 @@ $canPostMaker->prepare({ }); my $tests = 1; -plan tests => 13 +plan tests => 19 + $tests + $canPostMaker->plan ; @@ -129,6 +129,8 @@ undef $sameFolder; $sameFolder = $archive->getFolder($endOfDay); is($sameFolder->getId, $todayFolder->getId, 'call within same day(end) returns the same folder'); undef $sameFolder; +$todayFolder->purge; +is($archive->getChildCount, 0, 'leaving with an empty archive'); ################################################################ # @@ -139,6 +141,14 @@ undef $sameFolder; my $child = $archive->addChild({className => 'WebGUI::Asset::Wobject::StoryTopic'}); is($child, undef, 'addChild: Will only add Stories'); +$child = $archive->addChild({className => 'WebGUI::Asset::Story', title => 'First Story'}); +isa_ok($child, 'WebGUI::Asset::Story', 'addChild added and returned a Story'); +is($archive->getChildCount, 1, 'addChild: added it to the archive'); +my $folder = $archive->getFirstChild(); +isa_ok($folder, 'WebGUI::Asset::Wobject::Folder', 'Folder was added to Archive'); +is($folder->getChildCount, 1, 'The folder has 1 child...'); +is($folder->getFirstChild->getTitle, 'First Story', '... and it is the correct child'); + } #----------------------------------------------------------------------------