From 2ce2155321c2bfad052ae456c7a8a402394683bb Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Sat, 28 Feb 2009 00:56:38 +0000 Subject: [PATCH] test canPostStories method --- t/Asset/Wobject/StoryArchive.t | 72 ++++++++++++++++++++++++++++++---- 1 file changed, 65 insertions(+), 7 deletions(-) diff --git a/t/Asset/Wobject/StoryArchive.t b/t/Asset/Wobject/StoryArchive.t index 2fbc5f41f..5e20c9b10 100644 --- a/t/Asset/Wobject/StoryArchive.t +++ b/t/Asset/Wobject/StoryArchive.t @@ -21,18 +21,45 @@ use Test::Deep; use Data::Dumper; use WebGUI::Test; # Must use this before any other WebGUI modules +use WebGUI::Test::Maker::Permission; use WebGUI::Session; use WebGUI::Text; -#---------------------------------------------------------------------------- -# Init +################################################################ +# +# setup session, users and groups for this test +# +################################################################ + my $session = WebGUI::Test->session; -#---------------------------------------------------------------------------- -# Tests +my $staff = WebGUI::Group->new($session, 'new'); +$staff->name('Reporting Staff'); -my $tests = 0; -plan tests => 1 + $tests; +my $reporter = WebGUI::User->new($session, 'new'); +$reporter->username('reporter'); +my $editor = WebGUI::User->new($session, 'new'); +$editor->username('editor'); +my $reader = WebGUI::User->new($session, 'new'); +$reader->username('reader'); +$staff->addUsers([$reporter->userId]); + +my $archive = 'placeholder for Test::Maker::Permission'; + +my $canPostMaker = WebGUI::Test::Maker::Permission->new(); +$canPostMaker->prepare({ + object => $archive, + session => $session, + method => 'canPostStories', + pass => [3, $editor, $reporter ], + fail => [1, $reader ], +}); + +my $tests = 1; +plan tests => 2 + + $tests + + $canPostMaker->plan + ; #---------------------------------------------------------------------------- # put your tests here @@ -44,11 +71,42 @@ my $storage; SKIP: { - skip "Unable to load module $class", $tests unless $loaded; +skip "Unable to load module $class", $tests unless $loaded; + +$archive = WebGUI::Asset->getDefault($session)->addChild({className => $class}); + +isa_ok($archive, 'WebGUI::Asset::Wobject::StoryArchive', 'created StoryArchive'); + +################################################################ +# +# canPostStories +# +################################################################ + +$archive->update({ + ownerUserId => $editor->userId, + groupToPost => $staff->getId, +}); + +is($archive->get('groupToPost'), $staff->getId, 'set Staff group to post to Story Archive'); + +$canPostMaker->{_tests}->[0]->{object} = $archive; + +$canPostMaker->run(); } #---------------------------------------------------------------------------- # Cleanup END { + if (defined $archive and ref $archive eq $class) { + $archive->purge; + } + WebGUI::VersionTag->getWorking($session)->rollback; + foreach my $user ($editor, $reporter, $reader) { + $user->delete if defined $user; + } + foreach my $group ($staff) { + $group->delete if defined $group; + } }