From 00b41fb2a08627ee18cbcfef95430f6702c84b23 Mon Sep 17 00:00:00 2001 From: Doug Bell Date: Wed, 28 Jul 2010 15:04:00 -0500 Subject: [PATCH] add tests for declined behavior --- t/Content/Asset.t | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/t/Content/Asset.t b/t/Content/Asset.t index 080806ffb..934aa9dcd 100644 --- a/t/Content/Asset.t +++ b/t/Content/Asset.t @@ -26,6 +26,7 @@ use WebGUI::Session; my $session = WebGUI::Test->session; $INC{'WebGUI::Asset::TestDispatch'} = __FILE__; +$INC{'WebGUI::Asset::TestDecline'} = __FILE__; package WebGUI::Asset::TestDispatch; @@ -42,11 +43,25 @@ sub dispatch { return $self->SUPER::dispatch( $fragment ); } +sub www_edit { + my ( $self ) = @_; + return "www_edit " . $self->get('title'); +} + sub www_view { my ( $self ) = @_; return "www_view " . $self->get('title'); } +package WebGUI::Asset::TestDecline; + +our @ISA = ( 'WebGUI::Asset' ); + +# Override dispatch to decline everything +sub dispatch { return; } + +sub www_edit { return "you'll never see me!" } + package main; my $td @@ -61,7 +76,7 @@ WebGUI::Test->addToCleanup( WebGUI::VersionTag->getWorking( $session ) ); #---------------------------------------------------------------------------- # Tests -plan tests => 8; # Increment this number for each test you create +plan tests => 11; # Increment this number for each test you create #---------------------------------------------------------------------------- # test getUrlPermutation( url ) method @@ -118,4 +133,29 @@ is( "dispatch to the asset with the longest URL", ); +$clobberingTime->purge; + +# Add an asset that declines everything instead +my $declined + = WebGUI::Asset->getImportNode( $session )->addChild( { + title => "three", + className => 'WebGUI::Asset::TestDecline', + url => $td->get('url') . '/foo', + } ); + +is( + WebGUI::Content::Asset::dispatch( $session, "testdispatch/foo" ), + "bar", + "Dispatch passes to TestDispatch asset after declined", +); + +# Test ?func= dispatch with declined asset +$session->request->setup_body({ + func => "edit", +}); + +my $output = WebGUI::Content::Asset::dispatch( $session, "testdispatch/foo" ); +isnt( $output, "you'll never see me!", "func=edit was declined" ); +isnt( $output, "www_edit one", "func=edit was not for us" ); + #vim:ft=perl