X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F01app.t;h=1e87e76cee98a6369abafbcffd46dfd2dd02b2cf;hb=0fa271b6f70c61399fb198360c92731510564fb4;hp=ac0b4f2e6b388fe10c37013139424691f8569d9e;hpb=6979999624e6502df3590a0047c20e9158237742;p=scpubgit%2Fstemmaweb.git diff --git a/t/01app.t b/t/01app.t index ac0b4f2..1e87e76 100644 --- a/t/01app.t +++ b/t/01app.t @@ -1,73 +1,11 @@ #!/usr/bin/env perl use strict; use warnings; -use File::Temp; use Test::More; -use Text::Tradition::Directory; use Catalyst::Test 'stemmaweb'; -use vars qw( $orig_db, $was_link ); -my $textids; -my $dbfile = 'db/traditions.db'; -( $orig_db, $was_link, $textids ) = _make_testing_database(); - ok( request('/')->is_success, 'Got root HTML' ); -ok( request('/directory')->is_success, 'Got the text directory' ); -ok( request('/text/' . $textids->{'public'} . '/info')->is_success, - 'Got information listing for public text' ); -is( request('/text/' . $textids->{'public'} . '/info')->code, 403, - 'Denied information listing for public text' ); - +ok( request('/about')->is_success, 'Got about page HTML' ); done_testing(); - - -sub _make_testing_database { - my $fh = File::Temp->new(); - my $file = $fh->filename; - $fh->unlink_on_destroy( 0 ); - $fh->close; - my $dsn = 'dbi:SQLite:dbname=' . $file; - my $dir = Text::Tradition::Directory->new( 'dsn' => $dsn, - 'extra_args' => { 'create' => 1 } ); - my $scope = $dir->new_scope; - - my $textids = {}; - # Create a (public) tradition - my $pubtrad = Text::Tradition->new( input => 'Self', file => 't/data/john.xml' ); - $textids->{'public'} = $dir->store( $pubtrad ); - - # Create a user - my $userobj = $dir->add_user( { username => 'swtest', password => 'swtestpass' } ); - # Create a tradition for the user - my $privtrad = Text::Tradition->new( input => 'Tabular', sep_char => ',' - file => 't/data/florilegium.csv', user => $userobj ); - $privtrad->add_stemma( dotfile => 't/data/florilegium.dot' ); - $textids->{'private'} = $dir->store( $privtrad ); - - ## Now replace the existing traditions database with the test one - my( $orig, $was_link ); - if( -l $dbfile ) { - $was_link = 1; - $orig = readlink( $dbfile ); - unlink( $dbfile ) or die "Could not replace database file $dbfile"; - } else { - my $suffix = '.backup.' . time(); - $orig = $dbfile.$suffix; - rename( $dbfile, $orig ) or die "Could not move database file $dbfile"; - } - link( $file, $dbfile ); - return( $orig, $was_link, $textids ); -} - -END { - # Restore the original database - unlink( readlink( $dbfile ) ); - unlink( $dbfile ); - if( $was_link ) { - link( $orig_db, $dbfile ); - } else { - rename( $orig_db, $dbfile ); - } -}