Changeset 12
- Timestamp:
- 05/18/05 12:58:14 (3 years ago)
- Files:
-
- trunk/Build.PL (modified) (2 diffs)
- trunk/lib/Scrpbk.pm (modified) (3 diffs)
- trunk/root/base/robots.txt (modified) (1 diff)
- trunk/t/00_start_server.t (added)
- trunk/t/01app.t (modified) (1 diff)
- trunk/t/c/display.t (modified) (1 diff)
- trunk/t/c/holder.t (modified) (2 diffs)
- trunk/t/c/page.t (modified) (1 diff)
- trunk/t/c/person.t (modified) (1 diff)
- trunk/t/c/scrap.t (modified) (4 diffs)
- trunk/t/c/searchengine.t (modified) (1 diff)
- trunk/t/helpers.pl (modified) (4 diffs)
- trunk/t/login_logout.t (modified) (1 diff)
- trunk/t/zz_stop_server.t (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/Build.PL
r8 r12 1 1 use strict; 2 2 use Catalyst::Build; 3 4 my @test_files = sort( glob('t/*.t'), glob('t/*/*.t') ); 3 5 4 6 my $build = Catalyst::Build->new( … … 7 9 module_name => 'Scrpbk', 8 10 9 requires => {10 'Catalyst' => '5.10',11 'Cwd' => 0,12 'Data::Dumper' => 0,13 'DateTime::Format::Pg' => 0,14 'DateTime' => 0,15 'Email::Valid' => 0,16 'File::Spec' => 0,17 'FindBin' => 0,18 'HTML::Entities' => 0,19 'Getopt::Long' => 0,20 'Mail::Mailer' => 0,21 'Pod::Usage' => 0,22 'Template' => 0,23 'Test::More' => 0,24 'Test::WWW::Mechanize' => 0,25 'URI' => 0,26 'YAML' => 0,11 requires => { 12 'Catalyst' => '5.10', 13 'Cwd' => 0, 14 'Data::Dumper' => 0, 15 'DateTime::Format::Pg' => 0, 16 'DateTime' => 0, 17 'Email::Valid' => 0, 18 'File::Spec' => 0, 19 'FindBin' => 0, 20 'HTML::Entities' => 0, 21 'Getopt::Long' => 0, 22 'Mail::Mailer' => 0, 23 'Pod::Usage' => 0, 24 'Template' => 0, 25 'Test::More' => 0, 26 'Test::WWW::Mechanize' => 0, 27 'URI' => 0, 28 'YAML' => 0, 27 29 }, 28 30 29 31 create_makefile_pl => 'passthrough', 30 32 script_files => [ glob('script/*') ], 31 test_files => [ glob('t/*.t'), glob('t/*/*.t') ]33 test_files => \@test_files 32 34 ); 33 35 trunk/lib/Scrpbk.pm
r11 r12 18 18 Scrpbk->setup; 19 19 20 { # Check that the correct db version is being used. 21 my $dbh = Scrpbk::M::DBI::db_Main(); 22 my ($db_version) = $dbh->selectrow_array("select scrpbk_db_version(1)"); 20 warn "Here in " . `pwd`; 21 22 { # Check that the correct db version is being used. 23 my $dbh = Scrpbk::M::DBI::db_Main(); 24 my ($db_version) = $dbh->selectrow_array("select scrpbk_db_version(1)"); 23 25 $db_version ||= 0; 24 26 die "Wrong database version: have '$db_version', need '$VERSION'" 25 unless $db_version == $VERSION;27 unless $db_version == $VERSION; 26 28 } 27 29 28 30 # If we are testing turn on debugging. 29 sub debug { $yaml_config->{setting} eq 'testing' ? 1 : 0 } ;31 sub debug { $yaml_config->{setting} eq 'testing' ? 1 : 0 } 30 32 31 33 sub begin : Private { … … 44 46 # Get user 'homepage' onto stash as 'target'. 45 47 my $target = Scrpbk::M::Person->retrieve( tag => 'homepage' ); 46 47 if ( $target ) { 48 $c->stash->{target} = $target; 49 ( $c->stash->{page} ) = $target->pages( url => 'home' ); 50 } else { 51 warn "Could not load user 'homepage'"; 48 49 if ($target) { 50 $c->stash->{target} = $target; 51 ( $c->stash->{page} ) = $target->pages( url => 'home' ); 52 } 53 else { 54 warn "Could not load user 'homepage'"; 52 55 } 53 56 } … … 58 61 # If there is a redirect going change the template. 59 62 if ( $c->res->redirect ) { 60 $c->res->output("You are being redirected."); 61 } else { 62 $c->forward('Scrpbk::V::TT'); 63 $c->res->output("You are being redirected."); 64 } 65 else { 66 $c->forward('Scrpbk::V::TT'); 63 67 } 64 68 65 69 return 1; 66 70 } 67 68 71 69 72 sub load_session_from_cookie : Private { trunk/root/base/robots.txt
r2 r12 1 1 User-Agent: * 2 Disallow: /scrap 3 Disallow: /holder 4 Disallow: /person 2 Disallow: trunk/t/01app.t
r2 r12 1 use Test::More tests => 2;2 use _ok( Catalyst::Test, 'Scrpbk' );1 use strict; 2 use warnings; 3 3 4 ok( request('/')->is_success );4 use Test::More tests => 1; 5 5 6 require 't/helpers.pl'; 7 8 use LWP::UserAgent; 9 my $ua = LWP::UserAgent->new; 10 11 # Give the server a chance to start. 12 sleep 5; 13 14 ok( $ua->get( server_base_url() . '/' )->is_success ); 15 trunk/t/c/display.t
r11 r12 1 use strict; 2 use warnings; 1 3 2 use Test::More tests => 3; 3 use_ok( Catalyst::Test, 'Scrpbk' ); 4 use Test::More tests => 1; 4 5 use_ok('Scrpbk::C::Display'); 5 6 6 ok( request('display')->is_success );7 trunk/t/c/holder.t
r5 r12 2 2 use warnings; 3 3 4 use Test::More tests => 54;4 use Test::More tests => 48; 5 5 6 6 require 't/helpers.pl'; 7 ok start_server();8 7 9 8 use_ok('Scrpbk::C::Holder'); … … 117 116 ok !$mech->cookie_jar->as_string, "check that cookie is gone"; 118 117 119 ok stop_server();120 121 118 ################################################################################ 122 119 trunk/t/c/page.t
r11 r12 1 use strict; 2 use warnings; 1 3 2 use Test::More tests => 3; 3 use_ok( Catalyst::Test, 'Scrpbk' ); 4 use Test::More tests => 1; 4 5 use_ok('Scrpbk::C::Page'); 5 6 6 ok( request('page')->is_success );7 trunk/t/c/person.t
r2 r12 1 use strict; 2 use warnings; 1 3 2 use Test::More tests => 3; 3 use_ok( Catalyst::Test, 'Scrpbk' ); 4 use Test::More tests => 1; 4 5 use_ok('Scrpbk::C::Person'); 5 6 ok( request('person')->is_success );7 trunk/t/c/scrap.t
r8 r12 4 4 require 't/helpers.pl'; 5 5 6 use Test::More 'no_plan'; 7 8 ok start_server(); 6 use Test::More tests => 22; 9 7 10 8 use_ok('Scrpbk::C::Holder'); … … 38 36 form_name => 'add_scrap', 39 37 fields => { 40 content => "$_: **Test Scrap $_** - This is a scrap: [http://examle.com/]" 38 content => 39 "$_: **Test Scrap $_** - This is a scrap: [http://examle.com/]" 41 40 } 42 41 ), … … 50 49 for ( 1 .. 3 ) { 51 50 my $content = "**Test Scrap $_**"; 52 my @results = Scrpbk::M::Scrap->search_like 53 (person => $test_user,54 content => $_ . '%'55 );56 $scraps{$_} = $results[0];57 ok $scraps{$_}, "load the scrap '$content'";51 my @results = Scrpbk::M::Scrap->search_like( 52 person => $test_user, 53 content => $_ . '%' 54 ); 55 $scraps{$_} = $results[0]; 56 ok $scraps{$_}, "load the scrap '$content'"; 58 57 } 59 58 } … … 79 78 ok !$mech->cookie_jar->as_string, "check that cookie is gone"; 80 79 81 ok stop_server(), "kill server";82 83 80 ################################################################################ 84 81 trunk/t/c/searchengine.t
r2 r12 1 1 2 use Test::More tests => 3;3 use_ok( Catalyst::Test, 'Scrpbk' ); 2 use Test::More tests => 1; 3 4 4 use_ok('Scrpbk::C::SearchEngine'); 5 5 6 ok( request('searchengine')->is_success );6 #ok( request('searchengine')->is_success ); 7 7 trunk/t/helpers.pl
r5 r12 16 16 ################################################################################ 17 17 18 my $PORT = 3000; 19 my $SERVER = "http://localhost" . ( $PORT ? ":$PORT" : '' ); 20 my $SERVER_PID = ''; 21 22 sub start_server { 23 $SERVER_PID = fork; 24 unless ($SERVER_PID) { 25 BEGIN { $ENV{CATALYST_ENGINE} = 'HTTP' } 26 use Scrpbk; 27 Scrpbk->run(3000); 28 exit; 29 } 30 return $SERVER_PID; 31 } 32 33 sub stop_server { 34 return kill 9, $SERVER_PID; 35 } 18 my $PORT = 3000; 19 my $SERVER = "http://localhost" . ( $PORT ? ":$PORT" : '' ); 36 20 37 21 sub server_base_url { … … 41 25 ################################################################################ 42 26 27 my $TEST_USER; 28 43 29 sub test_user { 44 return Scrpbk::M::Person->retrieve( tag => 'test' );30 return $TEST_USER ||= Scrpbk::M::Person->retrieve( tag => 'test' ); 45 31 } 46 32 … … 49 35 sub login_as_test { 50 36 my $mech = get_mech(); 51 $mech->get _ok( server_base_url(), "request the home page" );37 $mech->get( server_base_url() . '/' ) || return 0; 52 38 53 my $test_user = test_user() ;39 my $test_user = test_user() || return 0; 54 40 55 ok$mech->submit_form(41 $mech->submit_form( 56 42 form_name => 'login', 57 43 fields => { … … 59 45 password => $test_user->password 60 46 } 61 ) ,62 "log in";47 ) 48 || return 0; 63 49 64 50 # Check we are logged in. 65 $mech->content_contains( "Your area", "check for 'Your area'" ); 66 ok( $mech->cookie_jar->as_string, "check that cookie is set" ) 67 || diag Dumper $mech->cookie_jar; 51 $mech->cookie_jar->as_string || return 0; 52 return 1; 68 53 } 69 54 70 55 sub logout { 71 56 my $mech = get_mech(); 72 $mech->content_lacks( 'Login', 'content lacks login' ); 73 ok $mech->follow_link( text => 'Log out' ), "logout"; 74 $mech->content_contains( 'Login', 'content contains login' ); 57 $mech->follow_link( text => 'Log out' ), "logout"; 58 75 59 } 76 60 trunk/t/login_logout.t
r2 r12 4 4 require 't/helpers.pl'; 5 5 6 use Test::More 'no_plan';6 use Test::More tests => 2; 7 7 8 ok start_server();9 8 ok login_as_test(), "login"; 10 ok logout(); 11 ok stop_server(); 9 ok logout(), "logout";
