Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

03_frontend_00.t fertig gestellt (#44)

  • Loading branch information...
commit 426188222a4c82128b302a9a0f693b99e2e4388b 1 parent 7ac9aa3
Bedivere authored
5  lib/Ffc.pm
@@ -3,10 +3,13 @@ use Mojo::Base 'Mojolicious';
3 3
 use Ffc::Data;
4 4
 
5 5
 sub switch_act { 
  6
+    return unless $_[1] and $_[1]->isa('Mojolicious::Controller');
6 7
     my $s = $_[1]->session;
7  
-    $s->{act} = $_[2];
  8
+    $s->{act} = $_[2] // 'forum';
  9
+    $s->{act} = 'forum' unless $s->{act} =~ m/\A(?:forum|notes|msgs)\z/xms;
8 10
     $s->{category} = undef;
9 11
     delete $s->{msgs_userid}; delete $s->{msgs_username};
  12
+    return 1;
10 13
 }
11 14
 
12 15
 # This method will run once at server start
33  t/03_frontend_00.t
... ...
@@ -1,14 +1,39 @@
1 1
 use Mojo::Base -strict;
2 2
 
3  
-use Test::More tests => 5;
4 3
 use Test::Mojo;
5 4
 use FindBin;
  5
+use lib "$FindBin::Bin/lib";
6 6
 use lib "$FindBin::Bin/../lib";
  7
+use Mock::Controller;
  8
+use Test::General;
  9
+
  10
+use Test::More tests => 12;
7 11
 
8 12
 use_ok('Ffc');
9 13
 my $t = Test::Mojo->new('Ffc');
10 14
 $t->get_ok('/')->status_is(200)->content_like(qr{Bitte melden Sie sich an});
11 15
 
12  
-{
13  
-    note('sub switch_category( $app, $controller, $act, $category, $msgsuserid )');
14  
-}
  16
+note('sub switch_act( $app, $controller, $act, $category, $msgsuserid )');
  17
+my $c = Mock::Controller->new();
  18
+my $session = $c->session();
  19
+$session->{blubb} = 'bla';
  20
+my $standard = {%$session};
  21
+
  22
+$standard->{act} = $session->{act} = '';
  23
+ok(!Ffc::switch_act(), 'invalid call returns false');
  24
+is_deeply($session, $standard, 'unaltered session ok');
  25
+
  26
+$session->{act} = '';
  27
+$standard->{act} = 'forum';
  28
+$standard->{category} = undef;
  29
+ok(Ffc::switch_act(undef, $c), 'call without act returns false');
  30
+is_deeply($session, $standard, 'altered session ok');
  31
+
  32
+$session->{act} = '';
  33
+ok(Ffc::switch_act(undef, $c, 'asdf'), 'call with wrong act returns false');
  34
+is_deeply($session, $standard, 'altered session ok');
  35
+
  36
+ok(Ffc::switch_act(undef, $c, 'notes'), 'call ok');
  37
+$standard->{act} = 'notes';
  38
+is_deeply($session, $standard, 'altered session ok');
  39
+
1  t/lib/Mock/Controller.pm
@@ -4,6 +4,7 @@ use warnings;
4 4
 use utf8;
5 5
 use 5.010;
6 6
 use Mock::Controller::App;
  7
+use Mojo::Base 'Mojolicious::Controller';
7 8
 
8 9
 sub new {
9 10
     bless { url => '', session => {}, stash => {}, app => Mock::Controller::App->new() },

0 notes on commit 4261882

Please sign in to comment.
Something went wrong with that request. Please try again.