Epic cleanup and code shuffle in tests to avoid warnings
[catagits/Catalyst-Plugin-Authentication.git] / t / lib / AuthRealmTestApp / Controller / Root.pm
diff --git a/t/lib/AuthRealmTestApp/Controller/Root.pm b/t/lib/AuthRealmTestApp/Controller/Root.pm
new file mode 100644 (file)
index 0000000..347f3d6
--- /dev/null
@@ -0,0 +1,74 @@
+package AuthRealmTestApp::Controller::Root;
+use warnings;
+use strict;
+use base qw/Catalyst::Controller/;
+
+__PACKAGE__->config(namespace => '');
+
+use Test::More;
+use Test::Exception;
+
+sub moose : Local {
+       my ( $self, $c ) = @_;
+
+       ok(!$c->user, "no user");
+
+    while ( my ($user, $info) = each %$AuthRealmTestApp::members ) {
+
+        ok(
+            $c->authenticate(
+                { username => $user, password => $info->{password} },
+                'members'
+            ),
+            "user $user authentication"
+        );
+
+        # check existing realms
+        ok( $c->user_in_realm('members'), "user in members realm");
+        ok(!$c->user_in_realm('admins'),  "user not in admins realm");
+
+        # check an invalid realm
+        ok(!$c->user_in_realm('foobar'), "user not in foobar realm");
+
+        # check if we've got the right user
+        is( $c->user, $info, "user object is in proper place");
+
+        $c->logout;
+
+           # sanity check
+        ok(!$c->user, "no more user after logout");
+
+    }
+
+    while ( my ($user, $info) = each %$AuthRealmTestApp::admins ) {
+
+        ok(
+            $c->authenticate(
+                { username => $user, password => $info->{password} },
+                'admins'
+            ),
+            "user $user authentication"
+        );
+
+        # check existing realms
+        ok(!$c->user_in_realm('members'), "user not in members realm");
+        ok( $c->user_in_realm('admins'),  "user in admins realm");
+
+        # check an invalid realm
+        ok(!$c->user_in_realm('foobar'), "user not in foobar realm");
+
+        # check if we've got the right user
+        is( $c->user, $info, "user object is in proper place");
+
+        $c->logout;
+
+           # sanity check
+        ok(!$c->user, "no more user after logout");
+
+    }
+
+       $c->res->body( "ok" );
+}
+
+1;
+