Permalink
Browse files

03_frontend_00.t fertig gestellt (#44)

  • Loading branch information...
1 parent 7ac9aa3 commit 426188222a4c82128b302a9a0f693b99e2e4388b @bedivere bedivere committed Mar 26, 2013
Showing with 34 additions and 5 deletions.
  1. +4 −1 lib/Ffc.pm
  2. +29 −4 t/03_frontend_00.t
  3. +1 −0 t/lib/Mock/Controller.pm
View
@@ -3,10 +3,13 @@ use Mojo::Base 'Mojolicious';
use Ffc::Data;
sub switch_act {
+ return unless $_[1] and $_[1]->isa('Mojolicious::Controller');
my $s = $_[1]->session;
- $s->{act} = $_[2];
+ $s->{act} = $_[2] // 'forum';
+ $s->{act} = 'forum' unless $s->{act} =~ m/\A(?:forum|notes|msgs)\z/xms;
$s->{category} = undef;
delete $s->{msgs_userid}; delete $s->{msgs_username};
+ return 1;
}
# This method will run once at server start
View
@@ -1,14 +1,39 @@
use Mojo::Base -strict;
-use Test::More tests => 5;
use Test::Mojo;
use FindBin;
+use lib "$FindBin::Bin/lib";
use lib "$FindBin::Bin/../lib";
+use Mock::Controller;
+use Test::General;
+
+use Test::More tests => 12;
use_ok('Ffc');
my $t = Test::Mojo->new('Ffc');
$t->get_ok('/')->status_is(200)->content_like(qr{Bitte melden Sie sich an});
-{
- note('sub switch_category( $app, $controller, $act, $category, $msgsuserid )');
-}
+note('sub switch_act( $app, $controller, $act, $category, $msgsuserid )');
+my $c = Mock::Controller->new();
+my $session = $c->session();
+$session->{blubb} = 'bla';
+my $standard = {%$session};
+
+$standard->{act} = $session->{act} = '';
+ok(!Ffc::switch_act(), 'invalid call returns false');
+is_deeply($session, $standard, 'unaltered session ok');
+
+$session->{act} = '';
+$standard->{act} = 'forum';
+$standard->{category} = undef;
+ok(Ffc::switch_act(undef, $c), 'call without act returns false');
+is_deeply($session, $standard, 'altered session ok');
+
+$session->{act} = '';
+ok(Ffc::switch_act(undef, $c, 'asdf'), 'call with wrong act returns false');
+is_deeply($session, $standard, 'altered session ok');
+
+ok(Ffc::switch_act(undef, $c, 'notes'), 'call ok');
+$standard->{act} = 'notes';
+is_deeply($session, $standard, 'altered session ok');
+
View
@@ -4,6 +4,7 @@ use warnings;
use utf8;
use 5.010;
use Mock::Controller::App;
+use Mojo::Base 'Mojolicious::Controller';
sub new {
bless { url => '', session => {}, stash => {}, app => Mock::Controller::App->new() },

0 comments on commit 4261882

Please sign in to comment.