[Cpan-forum-commit] rev 158 - in trunk: bin lib/CPAN t t/lib/CPAN/Forum

svn at pti.co.il svn at pti.co.il
Sun Aug 20 23:28:03 IDT 2006


Author: gabor
Date: 2006-08-20 23:28:03 +0300 (Sun, 20 Aug 2006)
New Revision: 158

Modified:
   trunk/bin/setup.pl
   trunk/lib/CPAN/Forum.pm
   trunk/t/001-users.t
   trunk/t/lib/CPAN/Forum/Test.pm
Log:
make sure a basic test in 001 passes


Modified: trunk/bin/setup.pl
===================================================================
--- trunk/bin/setup.pl	2006-08-20 05:52:58 UTC (rev 157)
+++ trunk/bin/setup.pl	2006-08-20 20:28:03 UTC (rev 158)
@@ -4,11 +4,13 @@
 use warnings;
 use lib "lib";
 use CPAN::Forum::INC;
-use FindBin qw($Bin);
 use Cwd qw(cwd);
 
+my $config_file = shift;
+my $dir      = shift or die "$0 CONFIG DB_DIR\n";
+
 my %opt;
-open my $opt, "$Bin/../CONFIG" or die "You need to create a CONFIG file. See README.\n";
+open my $opt, $config_file or die "You need to create a CONFIG file. See README.\n";
 while (<$opt>) {
 	chomp ;
 	my ($k, $v) = split /=/;
@@ -29,7 +31,6 @@
 
 }
 
-my $dir = "$Bin/../db";
 my $dbfile = "$dir/forum.db";
 unlink $dbfile if -e $dbfile;
 mkdir $dir if not -e $dir;

Modified: trunk/lib/CPAN/Forum.pm
===================================================================
--- trunk/lib/CPAN/Forum.pm	2006-08-20 05:52:58 UTC (rev 157)
+++ trunk/lib/CPAN/Forum.pm	2006-08-20 20:28:03 UTC (rev 158)
@@ -559,11 +559,13 @@
 
 	# Redirect to login, if necessary
 	if (not  $self->session->param('loggedin') ) {
+	    $self->log->debug("Redirecting to login");
 		$self->session->param(request => $ENV{PATH_INFO});
 		$self->header_type("redirect");
 		$self->header_props(-url => "http://$ENV{HTTP_HOST}/login/");
 		return;
 	}
+	$self->log->debug("cgiapp_prerun ends");
 }
 
 
@@ -576,6 +578,7 @@
 
 sub autoload {
 	my $self = shift;
+	$self->log->debug("autoload called: @ARGV");
 	$self->internal_error();
 }
 
@@ -590,12 +593,14 @@
 	my $self = shift;
 	my $q = $self->query;
 	
+	$self->log->debug("home");
 	my $t = $self->load_tmpl("home.tmpl",
 		loop_context_vars => 1,
 	);
 	
 	my $page = $q->param('page') || 1;
 	$self->_search_results($t, {where => {}, page => $page});
+	$self->log->debug("home to output");
 	$t->output;
 }
 
@@ -722,9 +727,11 @@
 
 sub load_tmpl {
 	my $self = shift;
+	$self->log->debug("load_tmpl: @_");
 	my $t = $self->SUPER::load_tmpl(@_
 #		      die_on_bad_params => -e ($self->param("ROOT") . "/die_on_bad_param") ? 1 : 0
 	);
+	$self->log->debug("template loaded");
 	$t->param("loggedin" => $self->session->param("loggedin") || "");
 	$t->param("username" => $self->session->param("username") || "anonymous");
 	$t->param("test_site_warning" => -e $self->param("ROOT") . "/config_test_site");

Modified: trunk/t/001-users.t
===================================================================
--- trunk/t/001-users.t	2006-08-20 05:52:58 UTC (rev 157)
+++ trunk/t/001-users.t	2006-08-20 20:28:03 UTC (rev 158)
@@ -3,38 +3,36 @@
 use strict;
 use warnings;
 
-use Test::More "no_plan";
+use Test::More;
+my $tests;
+plan tests => $tests;
 
 use lib qw(t/lib);
 use CPAN::Forum::Test;
 
-setup_database();
-ok(-e "blib/db/forum.db");
-
-use CPAN::Forum::DBI;
-CPAN::Forum::DBI->myinit("$ROOT/db/forum.db");
-
-use CGI::Application::Test;
+{
+    CPAN::Forum::Test::setup_database();
+    ok(-e "blib/db/forum.db");
+    BEGIN { $tests += 1; }
+}
 use CPAN::Forum;
-my $cat = CGI::Application::Test->new({
-            class   => "CPAN::Forum", 
-            cookie  => "cpanforum", 
-            app     => {
-                TMPL_PATH => "$ROOT/templates",
-                PARAMS => {
-                    ROOT => $ROOT,
-                },
-            }});
 
+my $w   = CPAN::Forum::Test::get_mech();
+my $url = CPAN::Forum::Test::get_url();
+
 {
-    my $r = $cat->cgiapp(path_info => '/');
-    like($r, qr{CPAN Forum});
+    $w->get_ok($url);
+    $w->content_like(qr{CPAN Forum});
+    BEGIN { $tests += 2; }
 }
 
+
 {
-    my $r = $cat->cgiapp(path_info => '/new_post');
-    like($r, qr{Location: http://test-host/login});
+    #$w->follow_link_ok({ text => 'new post' });
+    #like($r, qr{Location: http://test-host/login});
 
+    BEGIN { $tests += 0; }
+
 #TODO: {
 #   local $TODO = "do real redirection here";
 #   unlike($r, qr{<HTML>}i);

Modified: trunk/t/lib/CPAN/Forum/Test.pm
===================================================================
--- trunk/t/lib/CPAN/Forum/Test.pm	2006-08-20 05:52:58 UTC (rev 157)
+++ trunk/t/lib/CPAN/Forum/Test.pm	2006-08-20 20:28:03 UTC (rev 158)
@@ -6,9 +6,9 @@
 use vars qw(@ISA @EXPORT);
 @ISA    = qw(Exporter);
 
- at EXPORT = qw(@users $ROOT setup_database);
+ at EXPORT = qw(@users);
 
-our $ROOT = "blib";  
+my $ROOT = "blib";  
 
 our @users = (
 	{
@@ -23,13 +23,34 @@
 	mkdir "schema";
 	copy "../schema/schema.sql", "schema";
 
-	system "$^X bin/setup.pl";
-	system "$^X bin/populate.pl ../t/02packages.details.txt";
+	system "$^X ../bin/setup.pl CONFIG db";
+	system "$^X ../bin/populate.pl ../t/02packages.details.txt";
 
 	chdir "..";
 }
 
+sub get_mech {
+    use Test::WWW::Mechanize::CGI;
+    my $w = Test::WWW::Mechanize::CGI->new;
+    $w->cgi(sub {
+        require CPAN::Forum;
+        require CPAN::Forum::DBI;
+        CPAN::Forum::DBI->myinit("$ROOT/db/forum.db");
+        my $webapp = CPAN::Forum->new(
+                TMPL_PATH => "templates",
+                PARAMS => {
+                    ROOT => $ROOT,
+                },
+            );
+        $webapp->run();
+        }); 
+    return $w;
+};
 
+sub get_url {
+    return "http://cpanforum.local";
+}
 
+
 1;
 



More information about the Cpan-forum-commit mailing list