]> git.decadent.org.uk Git - maypole.git/blobdiff - t/maypole.t
fixing bugs introduced in 2.11
[maypole.git] / t / maypole.t
index f376697bddd0acc032b12a8f4bcdf69d1e20ec6f..9e49186fe884a1004903131049d120900a8e4e73 100755 (executable)
@@ -1,7 +1,7 @@
 #!/usr/bin/perl
 use strict;
 use warnings;
-use Test::More tests => 73;
+use Test::More tests => 84;
 use Test::MockModule;
 
 # module compilation
@@ -23,17 +23,23 @@ 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_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);
 
+ok( ! UNIVERSAL::can(Maypole => 'is_applicable'), 'no is_applicable() method' );
+
 ok(Maypole->config->isa('Maypole::Config'), 'config is a Maypole::Config object');
 ok(! Maypole->init_done, '... which is false by default');
 is(Maypole->view_object, undef, '... which is undefined');
@@ -183,7 +189,9 @@ my ($r, $req); # request objects
     my $mock_table  = new Test::MockModule($table_class, no_auto => 1);
     
     $mock_driver->mock(
-        is_applicable   => sub {push @{$called{applicable}},\@_; $applicable},
+        #is_applicable   => sub {push @{$called{applicable}},\@_; $applicable},
+        is_model_applicable   => 
+            sub {push @{$called{applicable}},\@_; $applicable},
         get_request     => sub {($r, $req) = @_},
         additional_data => sub {$called{additional_data}++},
     );
@@ -202,7 +210,7 @@ my ($r, $req); # request objects
     );
     
     # allow request
-    $applicable = $OK;
+    $applicable = 1;
     
     $r->{path} = '/table/action';    
     $r->parse_path;
@@ -218,7 +226,7 @@ my ($r, $req); # request objects
     # decline request
     %called = ();
     
-    $applicable = $DECLINED;
+    $applicable = 0;
     
     $r->{path} = '/table/action';
     $r->parse_path;
@@ -255,7 +263,7 @@ my ($r, $req); # request objects
     # ... TODO view processing error handling
 }
 
-# is_applicable()
+# is_model_applicable()
 {
     $r->config->display_tables([qw(one two)]);
     $r->config->ok_tables(undef);
@@ -264,19 +272,19 @@ my ($r, $req); # request objects
     $r->action('unittest');
     my $is_public;
     $mock_model->mock('is_public', sub {0});
-    my $status = $r->is_applicable;
-    is($status, $DECLINED,
-    '... return DECLINED unless model_class->is_public(action)');
+    my $true_false = $r->is_model_applicable;
+    is($true_false, 0,
+    '... returns 0 unless model_class->is_public(action)');
     $mock_model->mock('is_public', sub {$is_public = \@_; 1});
-    $status = $r->is_applicable;
-    is($status, $OK, '... returns OK if table is in ok_tables');
+    $true_false = $r->is_model_applicable;
+    is($true_false, 1, '... returns 1 if table is in ok_tables');
     is_deeply($is_public, [$r->model_class, 'unittest'],
             '... calls model_class->is_public with request action');
     is_deeply($r->config->ok_tables, {one => 1, two => 1},
             '... config->ok_tables defaults to config->display_tables');
     delete $r->config->ok_tables->{one};
-    $status = $r->is_applicable;
-    is($status, $DECLINED, '... return DECLINED unless $r->table is in ok_tables');
+    $true_false = $r->is_model_applicable;
+    is($true_false, 0, '... returns 0 unless $r->table is in ok_tables');
 }
 
 my $mock_driver = new Test::MockModule($driver_class, no_auto => 1);
@@ -343,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"');
     
@@ -367,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 "."');
@@ -383,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') );
+}
+