Add extra tests for denied www methods, checking asset state, add comments to test, and cleanup code.
This commit is contained in:
parent
1e00e6a93f
commit
08f453475e
2 changed files with 24 additions and 1 deletions
|
|
@ -51,6 +51,10 @@ sub www_edit {
|
||||||
return "www_edit";
|
return "www_edit";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub www_alsoView {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
package main;
|
package main;
|
||||||
|
|
||||||
my $tag = WebGUI::VersionTag->getWorking( $session );
|
my $tag = WebGUI::VersionTag->getWorking( $session );
|
||||||
|
|
@ -59,7 +63,7 @@ WebGUI::Test->addToCleanup( $tag );
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
# Tests
|
# Tests
|
||||||
|
|
||||||
plan tests => 10; # Increment this number for each test you create
|
plan tests => 13; # Increment this number for each test you create
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
# Test dispatch
|
# Test dispatch
|
||||||
|
|
@ -69,6 +73,7 @@ my $td = WebGUI::Asset->getImportNode( $session )->addChild( {
|
||||||
url => 'testDispatch',
|
url => 'testDispatch',
|
||||||
className => 'WebGUI::Asset::TestDispatch',
|
className => 'WebGUI::Asset::TestDispatch',
|
||||||
} );
|
} );
|
||||||
|
|
||||||
is( $td->dispatch, "www_view", "dispatch with no fragment shows www_view" );
|
is( $td->dispatch, "www_view", "dispatch with no fragment shows www_view" );
|
||||||
is( $td->dispatch( '/foo' ), 'bar', 'dispatch detects fragment and returns' );
|
is( $td->dispatch( '/foo' ), 'bar', 'dispatch detects fragment and returns' );
|
||||||
ok( !$td->dispatch( '/unhandled' ), 'dispatch with unknown fragment returns false' );
|
ok( !$td->dispatch( '/unhandled' ), 'dispatch with unknown fragment returns false' );
|
||||||
|
|
@ -91,9 +96,22 @@ $session->request->setup_body( {
|
||||||
} );
|
} );
|
||||||
is( $td->dispatch, "www_view", "requests for non-existant methods return www_view method" );
|
is( $td->dispatch, "www_view", "requests for non-existant methods return www_view method" );
|
||||||
|
|
||||||
|
# Test unhandled options
|
||||||
|
$session->request->setup_body( {
|
||||||
|
func => 'alsoView',
|
||||||
|
} );
|
||||||
|
is( $td->dispatch, "www_view", "if a query method return undef, view is still returned" );
|
||||||
|
|
||||||
$session->request->setup_body( { } );
|
$session->request->setup_body( { } );
|
||||||
$output = $td->dispatch( '/not-foo' );
|
$output = $td->dispatch( '/not-foo' );
|
||||||
is( $output, undef, "dispatch returned undef, meaning that it declined to handle the request for the wrong URL" );
|
is( $output, undef, "dispatch returned undef, meaning that it declined to handle the request for the wrong URL" );
|
||||||
isnt( $output, "www_view", "?func= dispatch cancelled because of unhandled fragment" );
|
isnt( $output, "www_view", "?func= dispatch cancelled because of unhandled fragment" );
|
||||||
|
|
||||||
|
$td->cut();
|
||||||
|
$output = $td->dispatch();
|
||||||
|
is $output, undef, 'dispatch returns undef when trying to access an asset that is not published, and admin is not on';
|
||||||
|
$session->var->switchAdminOn;
|
||||||
|
$output = $td->dispatch();
|
||||||
|
is $output, 'www_view', 'when admin is on, the asset can be accessed';
|
||||||
|
|
||||||
#vim:ft=perl
|
#vim:ft=perl
|
||||||
|
|
|
||||||
|
|
@ -92,18 +92,22 @@ cmp_deeply(
|
||||||
cmp_deeply(
|
cmp_deeply(
|
||||||
WebGUI::Content::Asset::getUrlPermutations( "one" ),
|
WebGUI::Content::Asset::getUrlPermutations( "one" ),
|
||||||
[ 'one' ],
|
[ 'one' ],
|
||||||
|
"simple one element URL",
|
||||||
);
|
);
|
||||||
cmp_deeply(
|
cmp_deeply(
|
||||||
WebGUI::Content::Asset::getUrlPermutations( "/one" ),
|
WebGUI::Content::Asset::getUrlPermutations( "/one" ),
|
||||||
[ '/one', ],
|
[ '/one', ],
|
||||||
|
"simple one element URL with leading slash",
|
||||||
);
|
);
|
||||||
cmp_deeply(
|
cmp_deeply(
|
||||||
WebGUI::Content::Asset::getUrlPermutations( "one/two/three" ),
|
WebGUI::Content::Asset::getUrlPermutations( "one/two/three" ),
|
||||||
[ 'one/two/three', 'one/two', 'one', ],
|
[ 'one/two/three', 'one/two', 'one', ],
|
||||||
|
"three element URL",
|
||||||
);
|
);
|
||||||
cmp_deeply(
|
cmp_deeply(
|
||||||
WebGUI::Content::Asset::getUrlPermutations( "/one/two/three" ),
|
WebGUI::Content::Asset::getUrlPermutations( "/one/two/three" ),
|
||||||
[ '/one/two/three', '/one/two', '/one', ],
|
[ '/one/two/three', '/one/two', '/one', ],
|
||||||
|
"three element URL with leading slash",
|
||||||
);
|
);
|
||||||
cmp_deeply(
|
cmp_deeply(
|
||||||
WebGUI::Content::Asset::getUrlPermutations( "/one/two/three.rss" ),
|
WebGUI::Content::Asset::getUrlPermutations( "/one/two/three.rss" ),
|
||||||
|
|
@ -133,6 +137,7 @@ my $clobberingTime
|
||||||
className => 'WebGUI::Asset::TestDispatch',
|
className => 'WebGUI::Asset::TestDispatch',
|
||||||
url => $td->get('url') . '/foo',
|
url => $td->get('url') . '/foo',
|
||||||
} );
|
} );
|
||||||
|
WebGUI::Test->addToCleanup($clobberingTime);
|
||||||
|
|
||||||
is(
|
is(
|
||||||
WebGUI::Content::Asset::dispatch( $session, "testdispatch/foo" ),
|
WebGUI::Content::Asset::dispatch( $session, "testdispatch/foo" ),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue