X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=t%2Fmaypole.t;h=9e49186fe884a1004903131049d120900a8e4e73;hb=3ed98309a0852fc198f9e4d0e6f70c5510c8282f;hp=8686254f2a8d74e3f96c825ee3a48f9412a60890;hpb=699c932710930328fa6942c375e097fbced03e5a;p=maypole.git diff --git a/t/maypole.t b/t/maypole.t index 8686254..9e49186 100755 --- a/t/maypole.t +++ b/t/maypole.t @@ -1,7 +1,7 @@ #!/usr/bin/perl use strict; use warnings; -use Test::More tests => 74; +use Test::More tests => 84; use Test::MockModule; # module compilation @@ -23,13 +23,17 @@ my $DECLINED = Maypole::Constants::DECLINED(); my $ERROR = Maypole::Constants::ERROR(); # Maypole API -my @API = qw/ config init_done view_object params query objects model_class +my @API = qw/ config init_done view_object params query param objects model_class template_args output path args action template error document_encoding content_type table headers_in headers_out - is_model_applicable setup init handler handler_guts + is_model_applicable setup setup_model init handler handler_guts call_authenticate call_exception additional_data - authenticate exception parse_path get_template_root get_request + authenticate exception parse_path make_path + make_uri get_template_root get_request parse_location send_output + start_request_hook + get_session + get_user /; can_ok(Maypole => @API); @@ -347,6 +351,7 @@ my $mock_table = new Test::MockModule($table_class, no_auto => 1); # parse_path() { $r->path(undef); + $r->parse_path; is($r->path, 'frontpage', '... path() defaults to "frontpage"'); @@ -371,6 +376,9 @@ my $mock_table = new Test::MockModule($table_class, no_auto => 1); is($r->action, 'index', '... action defaults to index'); } +# make_uri() and make_path() - see pathtools.t + + # get_template_root() { is(Maypole->get_template_root(), '.', '... returns "."'); @@ -387,3 +395,38 @@ my $mock_table = new Test::MockModule($table_class, no_auto => 1); eval {Maypole->send_output}; like($@, qr/Do not use Maypole directly/, '... croaks - must be overriden'); } + +# param() +{ + my $p = { foo => 'bar', + quux => [ qw/one two three/ ], + buz => undef, + num => 3, + zero => 0, + }; + + $r->{params} = $p; + + is_deeply( [keys %$p], [$r->param] ); + + cmp_ok( $r->param('foo'), eq => 'bar' ); + cmp_ok( $r->param('num'), '==' => 3 ); + cmp_ok( $r->param('zero'), '==' => 0 ); + + ok( ! defined $r->param('buz') ); + + # scalar context returns the 1st value, not a ref + cmp_ok( scalar $r->param('quux'), eq => 'one' ); + is_deeply( [$r->param('quux')], [ qw/one two three/ ] ); + + $r->param(foo => 'booze'); + cmp_ok( $r->param('foo'), 'eq', 'booze' ); + + $r->param(foo => undef); + ok( ! defined $r->param('foo') ); + + # cannot introduce new keys + $r->param(new => 'sox'); + ok( ! defined $r->param('new') ); +} +